Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRetryableError ¶
IsRetryableError determines if error code is retryable
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode represents specific error codes
const ( // ErrorCodeInvalidRequest indicates invalid request ErrorCodeInvalidRequest ErrorCode = "INVALID_REQUEST" // ErrorCodeAuthenticationFailed indicates authentication failure ErrorCodeAuthenticationFailed ErrorCode = "AUTHENTICATION_FAILED" // ErrorCodeInsufficientFunds indicates insufficient funds ErrorCodeInsufficientFunds ErrorCode = "INSUFFICIENT_FUNDS" // ErrorCodePaymentDeclined indicates payment declined ErrorCodePaymentDeclined ErrorCode = "PAYMENT_DECLINED" // ErrorCodeNetworkError indicates network error ErrorCodeNetworkError ErrorCode = "NETWORK_ERROR" // ErrorCodeTimeout indicates timeout ErrorCodeTimeout ErrorCode = "TIMEOUT" // ErrorCodeProviderError indicates provider error ErrorCodeProviderError ErrorCode = "PROVIDER_ERROR" // ErrorCodeValidationError indicates validation error ErrorCodeValidationError ErrorCode = "VALIDATION_ERROR" // ErrorCodePaymentExpired indicates payment expired ErrorCodePaymentExpired ErrorCode = "PAYMENT_EXPIRED" )
type PaymentError ¶
type PaymentError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Provider string `json:"provider,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
Retryable bool `json:"retryable"`
Cause error `json:"-"`
}
PaymentError represents a payment-related error
func NewPaymentError ¶
func NewPaymentError(code ErrorCode, message string, provider string, retryable bool) *PaymentError
NewPaymentError creates a new payment error
func NewValidationError ¶
func NewValidationError(field, message string) *PaymentError
NewValidationError creates a validation error
func (*PaymentError) Error ¶
func (e *PaymentError) Error() string
Error implements the error interface
func (*PaymentError) IsRetryable ¶
func (e *PaymentError) IsRetryable() bool
IsRetryable returns whether the error is retryable
func (*PaymentError) Unwrap ¶
func (e *PaymentError) Unwrap() error
Unwrap returns the underlying error
func (*PaymentError) WithCause ¶
func (e *PaymentError) WithCause(cause error) *PaymentError
WithCause adds a cause to the payment error
func (*PaymentError) WithDetail ¶
func (e *PaymentError) WithDetail(key string, value interface{}) *PaymentError
WithDetail adds a detail to the payment error
type PaymentRequest ¶
type PaymentRequest struct {
Amount money.Money `json:"amount"`
PhoneNumber *phone.Phone `json:"phone_number"`
Reference string `json:"reference"`
Description string `json:"description,omitempty"`
Language Language `json:"language,omitempty"`
Passcode string `json:"passcode,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
SuccessURL string `json:"success_url,omitempty"`
FailureURL string `json:"failure_url,omitempty"`
CancelURL string `json:"cancel_url,omitempty"`
CallbackURL string `json:"callback_url,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
PaymentRequest represents a payment request
func (*PaymentRequest) GetLanguage ¶
func (pr *PaymentRequest) GetLanguage() Language
GetLanguage returns language with default fallback
func (*PaymentRequest) IsExpired ¶
func (pr *PaymentRequest) IsExpired() bool
IsExpired returns true if payment request has expired
func (*PaymentRequest) Validate ¶
func (pr *PaymentRequest) Validate() error
Validate validates payment request
type PaymentResponse ¶
type PaymentResponse struct {
TransactionID string `json:"transaction_id"`
Status PaymentStatus `json:"status"`
Amount money.Money `json:"amount"`
Reference string `json:"reference"`
Provider string `json:"provider"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PaymentURL string `json:"payment_url,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
PaymentResponse represents a payment response
func (*PaymentResponse) IsCompleted ¶
func (pr *PaymentResponse) IsCompleted() bool
IsCompleted returns true if payment is completed
func (*PaymentResponse) IsSuccessful ¶
func (pr *PaymentResponse) IsSuccessful() bool
IsSuccessful returns true if payment was successful
type PaymentStatus ¶
type PaymentStatus string
PaymentStatus represents the status of a payment
const ( // PaymentStatusPending indicates payment is pending PaymentStatusPending PaymentStatus = "pending" // PaymentStatusSuccess indicates payment was successful PaymentStatusSuccess PaymentStatus = "success" // PaymentStatusFailed indicates payment failed PaymentStatusFailed PaymentStatus = "failed" // PaymentStatusCancelled indicates payment was cancelled PaymentStatusCancelled PaymentStatus = "cancelled" // PaymentStatusExpired indicates payment expired PaymentStatusExpired PaymentStatus = "expired" )
func (PaymentStatus) IsCompleted ¶
func (ps PaymentStatus) IsCompleted() bool
IsCompleted returns true if payment is in a final state
func (PaymentStatus) IsFailed ¶
func (ps PaymentStatus) IsFailed() bool
IsFailed returns true if payment failed
func (PaymentStatus) IsSuccessful ¶
func (ps PaymentStatus) IsSuccessful() bool
IsSuccessful returns true if payment was successful
func (PaymentStatus) String ¶
func (ps PaymentStatus) String() string
String returns string representation