Documentation
¶
Overview ¶
Package gopay provides a unified interface for payment processing across multiple providers including Stripe, PayPal, and Razorpay.
Each provider lives in its own sub-module so that importing one provider does not pull in the dependencies of another. For example, using PayPal will not require the Stripe SDK.
Core Package ¶
This package defines the shared interfaces (Provider, CustomerProvider, PaymentMethodProvider, WebhookProvider), request/response types, sentinel errors, and the Client that wraps any provider with validation and convenience methods.
client, err := gopay.NewClient(provider) p, err := client.CreatePayment(ctx, gopay.NewPaymentRequest(gopay.USD(1999)))
Providers ¶
Install only the providers you need:
go get github.com/KARTIKrocks/gopay/stripe go get github.com/KARTIKrocks/gopay/paypal go get github.com/KARTIKrocks/gopay/razorpay
Each provider package exports a Config, a Provider (which implements Provider and optionally CustomerProvider / PaymentMethodProvider / WebhookProvider), and a NewProvider constructor.
Testing ¶
Use MockProvider for unit tests without hitting any external API:
mock := gopay.NewMockProvider() mock.WithAutoSucceed(true) client, err := gopay.NewClient(mock)
Webhooks ¶
Use WebhookProvider.VerifyWebhook to verify and parse incoming webhook events. Each provider package also exports a ParseWebhook function that parses the payload without signature verification — this is useful for debugging or when verification is handled elsewhere (e.g. by a gateway), but should not be used in production without separate verification.
Error Handling ¶
All provider-specific errors are mapped to sentinel errors defined in this package (e.g. ErrCardDeclined, ErrInsufficientFunds, ErrNotFound). Use errors.Is for matching:
if errors.Is(err, gopay.ErrCardDeclined) {
// handle declined card
}
Index ¶
- Variables
- type Address
- type Amount
- type BillingDetails
- type CaptureMethod
- type CardDetails
- type Client
- func (c *Client) AttachPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
- func (c *Client) CancelPayment(ctx context.Context, paymentID string) (*Payment, error)
- func (c *Client) CapturePayment(ctx context.Context, paymentID string, amount *Amount) (*Payment, error)
- func (c *Client) CreateCustomer(ctx context.Context, req *CustomerRequest) (*Customer, error)
- func (c *Client) CreatePayment(ctx context.Context, req *PaymentRequest) (*Payment, error)
- func (c *Client) DeleteCustomer(ctx context.Context, customerID string) error
- func (c *Client) DetachPaymentMethod(ctx context.Context, paymentMethodID string) error
- func (c *Client) FullRefund(ctx context.Context, paymentID string) (*Refund, error)
- func (c *Client) GetCustomer(ctx context.Context, customerID string) (*Customer, error)
- func (c *Client) GetPayment(ctx context.Context, paymentID string) (*Payment, error)
- func (c *Client) GetRefund(ctx context.Context, refundID string) (*Refund, error)
- func (c *Client) ListPaymentMethods(ctx context.Context, customerID string) ([]*PaymentMethod, error)
- func (c *Client) Provider() Provider
- func (c *Client) ProviderName() string
- func (c *Client) Refund(ctx context.Context, req *RefundRequest) (*Refund, error)
- func (c *Client) UpdateCustomer(ctx context.Context, customerID string, req *CustomerRequest) (*Customer, error)
- func (c *Client) VerifyWebhook(ctx context.Context, payload []byte, headers map[string]string) (*WebhookEvent, error)
- type Customer
- type CustomerProvider
- type CustomerRequest
- func (r *CustomerRequest) Validate() error
- func (r *CustomerRequest) WithDescription(desc string) *CustomerRequest
- func (r *CustomerRequest) WithMetadata(key, value string) *CustomerRequest
- func (r *CustomerRequest) WithName(name string) *CustomerRequest
- func (r *CustomerRequest) WithPhone(phone string) *CustomerRequest
- type MockProvider
- func (p *MockProvider) AttachPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
- func (p *MockProvider) CancelPayment(ctx context.Context, paymentID string) (*Payment, error)
- func (p *MockProvider) CapturePayment(ctx context.Context, paymentID string, amount *Amount) (*Payment, error)
- func (p *MockProvider) CreateCustomer(ctx context.Context, req *CustomerRequest) (*Customer, error)
- func (p *MockProvider) CreatePayment(ctx context.Context, req *PaymentRequest) (*Payment, error)
- func (p *MockProvider) Customers() map[string]*Customer
- func (p *MockProvider) DeleteCustomer(ctx context.Context, customerID string) error
- func (p *MockProvider) DetachPaymentMethod(ctx context.Context, paymentMethodID string) error
- func (p *MockProvider) GetCustomer(ctx context.Context, customerID string) (*Customer, error)
- func (p *MockProvider) GetPayment(ctx context.Context, paymentID string) (*Payment, error)
- func (p *MockProvider) GetRefund(ctx context.Context, refundID string) (*Refund, error)
- func (p *MockProvider) ListPaymentMethods(ctx context.Context, customerID string) ([]*PaymentMethod, error)
- func (p *MockProvider) Name() string
- func (p *MockProvider) Payments() map[string]*Payment
- func (p *MockProvider) Refund(ctx context.Context, req *RefundRequest) (*Refund, error)
- func (p *MockProvider) Refunds() map[string]*Refund
- func (p *MockProvider) Reset()
- func (p *MockProvider) SetCustomer(customer *Customer)
- func (p *MockProvider) SetPayment(payment *Payment)
- func (p *MockProvider) SetRefund(refund *Refund)
- func (p *MockProvider) UpdateCustomer(ctx context.Context, customerID string, req *CustomerRequest) (*Customer, error)
- func (p *MockProvider) VerifyWebhook(_ context.Context, payload []byte, _ map[string]string) (*WebhookEvent, error)
- func (p *MockProvider) WithAutoCapture(auto bool) *MockProvider
- func (p *MockProvider) WithAutoSucceed(auto bool) *MockProvider
- func (p *MockProvider) WithCaptureError(err error) *MockProvider
- func (p *MockProvider) WithCreateError(err error) *MockProvider
- func (p *MockProvider) WithRefundError(err error) *MockProvider
- func (p *MockProvider) WithWebhookError(err error) *MockProvider
- type Payment
- type PaymentMethod
- type PaymentMethodProvider
- type PaymentMethodType
- type PaymentRequest
- func (r *PaymentRequest) Validate() error
- func (r *PaymentRequest) WithCaptureMethod(method CaptureMethod) *PaymentRequest
- func (r *PaymentRequest) WithCustomer(customerID string) *PaymentRequest
- func (r *PaymentRequest) WithDescription(desc string) *PaymentRequest
- func (r *PaymentRequest) WithIdempotencyKey(key string) *PaymentRequest
- func (r *PaymentRequest) WithMetadata(key, value string) *PaymentRequest
- func (r *PaymentRequest) WithPaymentMethod(paymentMethodID string) *PaymentRequest
- func (r *PaymentRequest) WithReturnURL(url string) *PaymentRequest
- type PaymentStatus
- type Provider
- type Refund
- type RefundReason
- type RefundRequest
- func (r *RefundRequest) Validate() error
- func (r *RefundRequest) WithAmount(amount *Amount) *RefundRequest
- func (r *RefundRequest) WithIdempotencyKey(key string) *RefundRequest
- func (r *RefundRequest) WithMetadata(key, value string) *RefundRequest
- func (r *RefundRequest) WithReason(reason RefundReason) *RefundRequest
- type RefundStatus
- type WebhookEvent
- type WebhookProvider
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidConfig = errors.New("gopay: invalid configuration") ErrInvalidAmount = errors.New("gopay: invalid amount") ErrInvalidCurrency = errors.New("gopay: invalid currency") ErrInvalidCard = errors.New("gopay: invalid card") ErrCardDeclined = errors.New("gopay: card declined") ErrInsufficientFunds = errors.New("gopay: insufficient funds") ErrExpiredCard = errors.New("gopay: expired card") ErrPaymentFailed = errors.New("gopay: payment failed") ErrRefundFailed = errors.New("gopay: refund failed") ErrNotFound = errors.New("gopay: not found") ErrAlreadyRefunded = errors.New("gopay: already refunded") ErrAlreadyCaptured = errors.New("gopay: already captured") ErrAuthenticationRequired = errors.New("gopay: authentication required") ErrProviderError = errors.New("gopay: provider error") ErrUnsupported = errors.New("gopay: operation not supported") )
Sentinel errors for payment operations.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct {
Line1 string
Line2 string
City string
State string
PostalCode string
Country string
}
Address represents a physical address.
type Amount ¶
type Amount struct {
// Value is the amount in the smallest currency unit (e.g., cents).
Value int64
// Currency is the three-letter ISO currency code.
Currency string
}
Amount represents a monetary amount.
type BillingDetails ¶
type BillingDetails struct {
// Name is the billing name.
Name string
// Email is the billing email.
Email string
// Phone is the billing phone.
Phone string
// Address is the billing address.
Address *Address
}
BillingDetails contains billing information.
type CaptureMethod ¶
type CaptureMethod string
CaptureMethod determines when funds are captured.
const ( // CaptureAutomatic captures funds immediately. CaptureAutomatic CaptureMethod = "automatic" // CaptureManual requires a separate capture call. CaptureManual CaptureMethod = "manual" )
func (CaptureMethod) String ¶
func (c CaptureMethod) String() string
String returns the string representation.
type CardDetails ¶
type CardDetails struct {
// Brand is the card brand (visa, mastercard, etc.).
Brand string
// Last4 is the last 4 digits.
Last4 string
// ExpMonth is the expiration month.
ExpMonth int
// ExpYear is the expiration year.
ExpYear int
// Funding is the funding type (credit, debit, prepaid).
Funding string
// Country is the card's country.
Country string
}
CardDetails contains card information.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main payment client.
func (*Client) AttachPaymentMethod ¶
AttachPaymentMethod attaches a payment method to a customer (if supported).
func (*Client) CancelPayment ¶
CancelPayment cancels an authorized payment.
func (*Client) CapturePayment ¶
func (c *Client) CapturePayment(ctx context.Context, paymentID string, amount *Amount) (*Payment, error)
CapturePayment captures an authorized payment.
func (*Client) CreateCustomer ¶
CreateCustomer creates a customer (if supported).
func (*Client) CreatePayment ¶
CreatePayment creates a new payment.
func (*Client) DeleteCustomer ¶
DeleteCustomer deletes a customer (if supported).
func (*Client) DetachPaymentMethod ¶
DetachPaymentMethod detaches a payment method from a customer (if supported).
func (*Client) FullRefund ¶
FullRefund creates a full refund for a payment.
func (*Client) GetCustomer ¶
GetCustomer retrieves a customer (if supported).
func (*Client) GetPayment ¶
GetPayment retrieves a payment.
func (*Client) ListPaymentMethods ¶
func (c *Client) ListPaymentMethods(ctx context.Context, customerID string) ([]*PaymentMethod, error)
ListPaymentMethods lists payment methods for a customer (if supported).
func (*Client) ProviderName ¶
ProviderName returns the provider name.
func (*Client) UpdateCustomer ¶
func (c *Client) UpdateCustomer(ctx context.Context, customerID string, req *CustomerRequest) (*Customer, error)
UpdateCustomer updates a customer (if supported).
func (*Client) VerifyWebhook ¶
func (c *Client) VerifyWebhook(ctx context.Context, payload []byte, headers map[string]string) (*WebhookEvent, error)
VerifyWebhook verifies and parses a webhook event (if supported).
type Customer ¶
type Customer struct {
// ID is the customer ID.
ID string
// Email is the customer's email.
Email string
// Name is the customer's name.
Name string
// Phone is the customer's phone.
Phone string
// Description is the description.
Description string
// DefaultPaymentMethodID is the default payment method.
DefaultPaymentMethodID string
// Metadata holds additional data.
Metadata map[string]string
// CreatedAt is the creation timestamp.
CreatedAt time.Time
// Provider is the provider name.
Provider string
// Raw contains the raw provider response.
Raw map[string]any
}
Customer represents a customer.
type CustomerProvider ¶
type CustomerProvider interface {
Provider
// CreateCustomer creates a new customer.
CreateCustomer(ctx context.Context, req *CustomerRequest) (*Customer, error)
// GetCustomer retrieves a customer by ID.
GetCustomer(ctx context.Context, customerID string) (*Customer, error)
// UpdateCustomer updates a customer.
UpdateCustomer(ctx context.Context, customerID string, req *CustomerRequest) (*Customer, error)
// DeleteCustomer deletes a customer.
DeleteCustomer(ctx context.Context, customerID string) error
}
CustomerProvider extends Provider with customer management.
type CustomerRequest ¶
type CustomerRequest struct {
// Email is the customer's email.
Email string
// Name is the customer's name.
Name string
// Phone is the customer's phone.
Phone string
// Description is an optional description.
Description string
// Metadata holds additional data.
Metadata map[string]string
}
CustomerRequest represents a customer creation/update request.
func NewCustomerRequest ¶
func NewCustomerRequest(email string) *CustomerRequest
NewCustomerRequest creates a new customer request.
func (*CustomerRequest) Validate ¶
func (r *CustomerRequest) Validate() error
Validate validates the customer request.
func (*CustomerRequest) WithDescription ¶
func (r *CustomerRequest) WithDescription(desc string) *CustomerRequest
WithDescription sets the description.
func (*CustomerRequest) WithMetadata ¶
func (r *CustomerRequest) WithMetadata(key, value string) *CustomerRequest
WithMetadata adds metadata.
func (*CustomerRequest) WithName ¶
func (r *CustomerRequest) WithName(name string) *CustomerRequest
WithName sets the name.
func (*CustomerRequest) WithPhone ¶
func (r *CustomerRequest) WithPhone(phone string) *CustomerRequest
WithPhone sets the phone.
type MockProvider ¶
type MockProvider struct {
// contains filtered or unexported fields
}
MockProvider is a mock payment provider for testing.
func NewMockProvider ¶
func NewMockProvider() *MockProvider
NewMockProvider creates a new mock provider.
func (*MockProvider) AttachPaymentMethod ¶
func (p *MockProvider) AttachPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
AttachPaymentMethod attaches a payment method to a customer.
func (*MockProvider) CancelPayment ¶
CancelPayment cancels a mock payment.
func (*MockProvider) CapturePayment ¶
func (p *MockProvider) CapturePayment(ctx context.Context, paymentID string, amount *Amount) (*Payment, error)
CapturePayment captures a mock payment.
func (*MockProvider) CreateCustomer ¶
func (p *MockProvider) CreateCustomer(ctx context.Context, req *CustomerRequest) (*Customer, error)
CreateCustomer creates a mock customer.
func (*MockProvider) CreatePayment ¶
func (p *MockProvider) CreatePayment(ctx context.Context, req *PaymentRequest) (*Payment, error)
CreatePayment creates a mock payment.
func (*MockProvider) Customers ¶
func (p *MockProvider) Customers() map[string]*Customer
Customers returns all customers.
func (*MockProvider) DeleteCustomer ¶
func (p *MockProvider) DeleteCustomer(ctx context.Context, customerID string) error
DeleteCustomer deletes a mock customer.
func (*MockProvider) DetachPaymentMethod ¶
func (p *MockProvider) DetachPaymentMethod(ctx context.Context, paymentMethodID string) error
DetachPaymentMethod detaches a payment method.
func (*MockProvider) GetCustomer ¶
GetCustomer retrieves a mock customer.
func (*MockProvider) GetPayment ¶
GetPayment retrieves a mock payment.
func (*MockProvider) ListPaymentMethods ¶
func (p *MockProvider) ListPaymentMethods(ctx context.Context, customerID string) ([]*PaymentMethod, error)
ListPaymentMethods lists payment methods for a customer.
func (*MockProvider) Payments ¶
func (p *MockProvider) Payments() map[string]*Payment
Payments returns all payments.
func (*MockProvider) Refund ¶
func (p *MockProvider) Refund(ctx context.Context, req *RefundRequest) (*Refund, error)
Refund creates a mock refund.
func (*MockProvider) Refunds ¶
func (p *MockProvider) Refunds() map[string]*Refund
Refunds returns all refunds.
func (*MockProvider) SetCustomer ¶
func (p *MockProvider) SetCustomer(customer *Customer)
SetCustomer manually sets a customer.
func (*MockProvider) SetPayment ¶
func (p *MockProvider) SetPayment(payment *Payment)
SetPayment manually sets a payment.
func (*MockProvider) SetRefund ¶
func (p *MockProvider) SetRefund(refund *Refund)
SetRefund manually sets a refund.
func (*MockProvider) UpdateCustomer ¶
func (p *MockProvider) UpdateCustomer(ctx context.Context, customerID string, req *CustomerRequest) (*Customer, error)
UpdateCustomer updates a mock customer.
func (*MockProvider) VerifyWebhook ¶
func (p *MockProvider) VerifyWebhook(_ context.Context, payload []byte, _ map[string]string) (*WebhookEvent, error)
VerifyWebhook verifies and parses a mock webhook event. It simply parses the payload as JSON and returns it as a WebhookEvent. Use WithWebhookError to simulate verification failures.
func (*MockProvider) WithAutoCapture ¶
func (p *MockProvider) WithAutoCapture(auto bool) *MockProvider
WithAutoCapture sets whether payments are auto-captured.
func (*MockProvider) WithAutoSucceed ¶
func (p *MockProvider) WithAutoSucceed(auto bool) *MockProvider
WithAutoSucceed sets whether payments auto-succeed.
func (*MockProvider) WithCaptureError ¶
func (p *MockProvider) WithCaptureError(err error) *MockProvider
WithCaptureError sets the error to return on CapturePayment.
func (*MockProvider) WithCreateError ¶
func (p *MockProvider) WithCreateError(err error) *MockProvider
WithCreateError sets the error to return on CreatePayment.
func (*MockProvider) WithRefundError ¶
func (p *MockProvider) WithRefundError(err error) *MockProvider
WithRefundError sets the error to return on Refund.
func (*MockProvider) WithWebhookError ¶
func (p *MockProvider) WithWebhookError(err error) *MockProvider
WithWebhookError sets the error to return on VerifyWebhook.
type Payment ¶
type Payment struct {
// ID is the payment ID.
ID string
// Amount is the payment amount.
Amount *Amount
// Status is the payment status.
Status PaymentStatus
// Description is the payment description.
Description string
// CustomerID is the associated customer ID.
CustomerID string
// PaymentMethodID is the payment method used.
PaymentMethodID string
// CaptureMethod is the capture method.
CaptureMethod CaptureMethod
// AmountCaptured is the amount captured.
AmountCaptured int64
// AmountRefunded is the amount refunded.
AmountRefunded int64
// FailureCode is the failure code if failed.
FailureCode string
// FailureMessage is the failure message if failed.
FailureMessage string
// ClientSecret is the client secret (for frontend).
ClientSecret string
// RedirectURL is the URL for 3DS redirect.
RedirectURL string
// Metadata holds additional data.
Metadata map[string]string
// CreatedAt is the creation timestamp.
CreatedAt time.Time
// Provider is the provider name.
Provider string
// Raw contains the raw provider response.
Raw map[string]any
}
Payment represents a payment.
func (*Payment) IsCaptured ¶
IsCaptured returns true if the payment was captured.
func (*Payment) IsSuccessful ¶
IsSuccessful returns true if the payment was successful.
func (*Payment) RequiresAction ¶
RequiresAction returns true if the payment requires additional action.
type PaymentMethod ¶
type PaymentMethod struct {
// ID is the payment method ID.
ID string
// Type is the payment method type.
Type PaymentMethodType
// CustomerID is the associated customer ID.
CustomerID string
// Card contains card details (if type is card).
Card *CardDetails
// BillingDetails contains billing information.
BillingDetails *BillingDetails
// CreatedAt is the creation timestamp.
CreatedAt time.Time
// Provider is the provider name.
Provider string
// Raw contains the raw provider response.
Raw map[string]any
}
PaymentMethod represents a payment method.
type PaymentMethodProvider ¶
type PaymentMethodProvider interface {
Provider
// AttachPaymentMethod attaches a payment method to a customer.
AttachPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
// DetachPaymentMethod detaches a payment method from a customer.
DetachPaymentMethod(ctx context.Context, paymentMethodID string) error
// ListPaymentMethods lists payment methods for a customer.
ListPaymentMethods(ctx context.Context, customerID string) ([]*PaymentMethod, error)
}
PaymentMethodProvider extends Provider with payment method management.
type PaymentMethodType ¶
type PaymentMethodType string
PaymentMethodType represents the type of payment method.
const ( PaymentMethodCard PaymentMethodType = "card" PaymentMethodBankAccount PaymentMethodType = "bank_account" PaymentMethodWallet PaymentMethodType = "wallet" PaymentMethodUPI PaymentMethodType = "upi" PaymentMethodNetBanking PaymentMethodType = "netbanking" )
func (PaymentMethodType) String ¶
func (t PaymentMethodType) String() string
String returns the string representation.
type PaymentRequest ¶
type PaymentRequest struct {
// Amount is the payment amount.
Amount *Amount
// Description is an optional description.
Description string
// CustomerID is the customer ID (optional).
CustomerID string
// PaymentMethodID is the payment method ID (optional).
PaymentMethodID string
// ReturnURL is the URL to redirect after payment (for 3DS).
ReturnURL string
// CaptureMethod determines when to capture funds.
CaptureMethod CaptureMethod
// Metadata holds additional data.
Metadata map[string]string
// IdempotencyKey for idempotent requests.
IdempotencyKey string
}
PaymentRequest represents a payment creation request.
func NewPaymentRequest ¶
func NewPaymentRequest(amount *Amount) *PaymentRequest
NewPaymentRequest creates a new payment request.
func (*PaymentRequest) Validate ¶
func (r *PaymentRequest) Validate() error
Validate validates the payment request.
func (*PaymentRequest) WithCaptureMethod ¶
func (r *PaymentRequest) WithCaptureMethod(method CaptureMethod) *PaymentRequest
WithCaptureMethod sets the capture method.
func (*PaymentRequest) WithCustomer ¶
func (r *PaymentRequest) WithCustomer(customerID string) *PaymentRequest
WithCustomer sets the customer ID.
func (*PaymentRequest) WithDescription ¶
func (r *PaymentRequest) WithDescription(desc string) *PaymentRequest
WithDescription sets the description.
func (*PaymentRequest) WithIdempotencyKey ¶
func (r *PaymentRequest) WithIdempotencyKey(key string) *PaymentRequest
WithIdempotencyKey sets the idempotency key.
func (*PaymentRequest) WithMetadata ¶
func (r *PaymentRequest) WithMetadata(key, value string) *PaymentRequest
WithMetadata adds metadata.
func (*PaymentRequest) WithPaymentMethod ¶
func (r *PaymentRequest) WithPaymentMethod(paymentMethodID string) *PaymentRequest
WithPaymentMethod sets the payment method ID.
func (*PaymentRequest) WithReturnURL ¶
func (r *PaymentRequest) WithReturnURL(url string) *PaymentRequest
WithReturnURL sets the return URL.
type PaymentStatus ¶
type PaymentStatus string
PaymentStatus represents the status of a payment.
const ( PaymentStatusPending PaymentStatus = "pending" PaymentStatusRequiresAction PaymentStatus = "requires_action" PaymentStatusProcessing PaymentStatus = "processing" PaymentStatusSucceeded PaymentStatus = "succeeded" PaymentStatusFailed PaymentStatus = "failed" PaymentStatusCanceled PaymentStatus = "canceled" PaymentStatusRequiresCapture PaymentStatus = "requires_capture" )
func (PaymentStatus) String ¶
func (s PaymentStatus) String() string
String returns the string representation.
type Provider ¶
type Provider interface {
// Name returns the provider name.
Name() string
// CreatePayment creates a new payment.
CreatePayment(ctx context.Context, req *PaymentRequest) (*Payment, error)
// GetPayment retrieves a payment by ID.
GetPayment(ctx context.Context, paymentID string) (*Payment, error)
// CapturePayment captures an authorized payment.
CapturePayment(ctx context.Context, paymentID string, amount *Amount) (*Payment, error)
// CancelPayment cancels an authorized payment.
CancelPayment(ctx context.Context, paymentID string) (*Payment, error)
// Refund creates a refund for a payment.
Refund(ctx context.Context, req *RefundRequest) (*Refund, error)
// GetRefund retrieves a refund by ID.
GetRefund(ctx context.Context, refundID string) (*Refund, error)
}
Provider represents a payment provider.
type Refund ¶
type Refund struct {
// ID is the refund ID.
ID string
// PaymentID is the refunded payment ID.
PaymentID string
// Amount is the refund amount.
Amount *Amount
// Status is the refund status.
Status RefundStatus
// Reason is the refund reason.
Reason RefundReason
// FailureReason is the failure reason if failed.
FailureReason string
// Metadata holds additional data.
Metadata map[string]string
// CreatedAt is the creation timestamp.
CreatedAt time.Time
// Provider is the provider name.
Provider string
// Raw contains the raw provider response.
Raw map[string]any
}
Refund represents a refund.
func (*Refund) IsSuccessful ¶
IsSuccessful returns true if the refund was successful.
type RefundReason ¶
type RefundReason string
RefundReason represents the reason for a refund.
const ( RefundReasonDuplicate RefundReason = "duplicate" RefundReasonFraudulent RefundReason = "fraudulent" RefundReasonRequestedByCustomer RefundReason = "requested_by_customer" RefundReasonOther RefundReason = "other" )
func (RefundReason) String ¶
func (r RefundReason) String() string
String returns the string representation.
type RefundRequest ¶
type RefundRequest struct {
// PaymentID is the payment to refund.
PaymentID string
// Amount is the refund amount (nil for full refund).
Amount *Amount
// Reason is the refund reason.
Reason RefundReason
// Metadata holds additional data.
Metadata map[string]string
// IdempotencyKey for idempotent requests.
IdempotencyKey string
}
RefundRequest represents a refund request.
func NewRefundRequest ¶
func NewRefundRequest(paymentID string) *RefundRequest
NewRefundRequest creates a new refund request.
func (*RefundRequest) Validate ¶
func (r *RefundRequest) Validate() error
Validate validates the refund request.
func (*RefundRequest) WithAmount ¶
func (r *RefundRequest) WithAmount(amount *Amount) *RefundRequest
WithAmount sets the refund amount.
func (*RefundRequest) WithIdempotencyKey ¶
func (r *RefundRequest) WithIdempotencyKey(key string) *RefundRequest
WithIdempotencyKey sets the idempotency key.
func (*RefundRequest) WithMetadata ¶
func (r *RefundRequest) WithMetadata(key, value string) *RefundRequest
WithMetadata adds metadata.
func (*RefundRequest) WithReason ¶
func (r *RefundRequest) WithReason(reason RefundReason) *RefundRequest
WithReason sets the refund reason.
type RefundStatus ¶
type RefundStatus string
RefundStatus represents the status of a refund.
const ( RefundStatusPending RefundStatus = "pending" RefundStatusSucceeded RefundStatus = "succeeded" RefundStatusFailed RefundStatus = "failed" RefundStatusCanceled RefundStatus = "canceled" )
func (RefundStatus) String ¶
func (s RefundStatus) String() string
String returns the string representation.
type WebhookEvent ¶
type WebhookEvent struct {
// ID is the event ID.
ID string
// Type is the event type.
Type string
// Provider is the provider name.
Provider string
// Raw contains the raw event payload.
Raw []byte
}
WebhookEvent represents a parsed webhook event.
type WebhookProvider ¶
type WebhookProvider interface {
// VerifyWebhook verifies and parses a webhook event.
// The headers map should contain the relevant signature headers from the HTTP request.
VerifyWebhook(ctx context.Context, payload []byte, headers map[string]string) (*WebhookEvent, error)
}
WebhookProvider extends Provider with webhook verification.