Documentation
¶
Index ¶
- func ListProviders() []string
- func RegisterProvider(provider PaymentProvider)
- type AP2Constraints
- type AP2MandateClaims
- type AP2Subject
- type AP2VerificationInput
- type AgentAssertionClaims
- type Handlers
- func (h *Handlers) CreateIntent(ctx context.Context, orderID string, providerName string) (*PaymentTransaction, error)
- func (h *Handlers) CreateIntentStep(sCtx mdk.StepContext) mdk.StepResult
- func (h *Handlers) Refund(ctx context.Context, transactionID string, amount float64) (string, error)
- func (h *Handlers) RefundStep(sCtx mdk.StepContext) mdk.StepResult
- func (h *Handlers) VerifyAP2(ctx context.Context, input AP2VerificationInput) (*PaymentTransaction, error)
- func (h *Handlers) VerifyAP2Step(sCtx mdk.StepContext) mdk.StepResult
- func (h *Handlers) VerifyPayment(ctx context.Context, orderID string, providerName string, ...) (*PaymentTransaction, error)
- func (h *Handlers) VerifyPaymentStep(sCtx mdk.StepContext) mdk.StepResult
- type JWK
- type MockProvider
- func (m *MockProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
- func (m *MockProvider) ID() string
- func (m *MockProvider) Refund(ctx context.Context, transactionID string, amount float64) (string, error)
- func (m *MockProvider) VerifyPayment(ctx context.Context, payload map[string]any) (bool, error)
- type Module
- func (m *Module) CreatePaymentIntent(ctx context.Context, orderID string, provider string) (*PaymentIntent, error)
- func (m *Module) FieldResolvers() map[string]any
- func (m *Module) GetPaymentTransaction(ctx context.Context, id string) (*PaymentTransaction, error)
- func (m *Module) GetTransactionStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) ListActivePaymentProviders(ctx context.Context) ([]*PaymentProviderInfo, error)
- func (m *Module) ListOrderTransactions(ctx context.Context, orderID string) ([]*PaymentTransaction, error)
- func (m *Module) ListProvidersStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ListTransactionsStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) Models() []any
- func (m *Module) Mutations() map[string]any
- func (m *Module) Queries() map[string]any
- func (m *Module) Routes() []mdk.Route
- func (m *Module) Shutdown(ctx context.Context) error
- func (m *Module) VerifyPayment(ctx context.Context, orderID string, provider string, payload map[string]any) (*PaymentVerificationResult, error)
- func (m *Module) VerifyPaymentAp2(ctx context.Context, input AP2VerificationInput) (*PaymentVerificationResult, error)
- type PaymentIntent
- type PaymentProvider
- type PaymentProviderInfo
- type PaymentTransaction
- type PaymentVerificationResult
- type RazorpayProvider
- func (r *RazorpayProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
- func (r *RazorpayProvider) ID() string
- func (r *RazorpayProvider) Refund(ctx context.Context, transactionID string, amount float64) (string, error)
- func (r *RazorpayProvider) VerifyPayment(ctx context.Context, payload map[string]any) (bool, error)
- func (r *RazorpayProvider) WriteToHash(h interface{ ... }, data string) (int, error)
- type StripeProvider
- func (s *StripeProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
- func (s *StripeProvider) ID() string
- func (s *StripeProvider) Refund(ctx context.Context, transactionID string, amount float64) (string, error)
- func (s *StripeProvider) VerifyPayment(ctx context.Context, payload map[string]any) (bool, error)
- type TransactionStatus
- type WebhookHandlers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListProviders ¶
func ListProviders() []string
ListProviders returns a list of registered payment provider identifiers.
func RegisterProvider ¶
func RegisterProvider(provider PaymentProvider)
RegisterProvider registers a payment provider.
Types ¶
type AP2Constraints ¶
type AP2MandateClaims ¶
type AP2MandateClaims struct {
Issuer string `json:"iss"`
Subject string `json:"sub"`
IssuedAt int64 `json:"iat"`
Expiration int64 `json:"exp"`
CredentialSubject AP2Subject `json:"credentialSubject"`
VC *struct {
CredentialSubject AP2Subject `json:"credentialSubject"`
} `json:"vc,omitempty"`
}
func VerifyAP2Mandate ¶
func VerifyAP2Mandate(ctx context.Context, input AP2VerificationInput, amount float64, currency string, merchantHost string, userPublicKeyPEM string) (*AP2MandateClaims, error)
VerifyAP2Mandate cryptographically validates the user's mandate and the agent's assertion.
func (*AP2MandateClaims) GetSubject ¶
func (c *AP2MandateClaims) GetSubject() AP2Subject
func (*AP2MandateClaims) VerifyConstraints ¶
func (c *AP2MandateClaims) VerifyConstraints(amount float64, currency string, merchantHost string) error
type AP2Subject ¶
type AP2Subject struct {
AgentKey JWK `json:"agentKey"`
Constraints AP2Constraints `json:"constraints"`
}
type AP2VerificationInput ¶
type AP2VerificationInput struct {
MandateJWT string `json:"mandate_jwt"` // User-signed mandate VC (JWT)
AgentAssertion string `json:"agent_assertion"` // Agent-signed JWT asserting the transaction
OrderID string `json:"order_id"`
Provider string `json:"provider"` // "stripe", "razorpay", "mock"
Payload map[string]any `json:"payload"` // Additional gateway payload (Stripe payment method token, etc.)
}
type AgentAssertionClaims ¶
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
func (*Handlers) CreateIntent ¶
func (h *Handlers) CreateIntent(ctx context.Context, orderID string, providerName string) (*PaymentTransaction, error)
CreateIntent registers a payment intent/order with the provider and GORM.
func (*Handlers) CreateIntentStep ¶
func (h *Handlers) CreateIntentStep(sCtx mdk.StepContext) mdk.StepResult
CreateIntentStep wraps CreateIntent to mdk.StepHandler.
func (*Handlers) Refund ¶
func (h *Handlers) Refund(ctx context.Context, transactionID string, amount float64) (string, error)
Refund processes refunds (used as Sage rollback compensations).
func (*Handlers) RefundStep ¶
func (h *Handlers) RefundStep(sCtx mdk.StepContext) mdk.StepResult
RefundStep wraps Refund to mdk.StepHandler.
func (*Handlers) VerifyAP2 ¶
func (h *Handlers) VerifyAP2(ctx context.Context, input AP2VerificationInput) (*PaymentTransaction, error)
VerifyAP2 verifies an AP2 agent payment mandate and processes the charge via the selected gateway provider.
func (*Handlers) VerifyAP2Step ¶
func (h *Handlers) VerifyAP2Step(sCtx mdk.StepContext) mdk.StepResult
VerifyAP2Step wraps VerifyAP2 to mdk.StepHandler.
func (*Handlers) VerifyPayment ¶
func (h *Handlers) VerifyPayment(ctx context.Context, orderID string, providerName string, payload map[string]any) (*PaymentTransaction, error)
VerifyPayment confirms checkout signature/token values, updating order and transaction states.
func (*Handlers) VerifyPaymentStep ¶
func (h *Handlers) VerifyPaymentStep(sCtx mdk.StepContext) mdk.StepResult
VerifyPaymentStep wraps VerifyPayment to mdk.StepHandler.
type MockProvider ¶
type MockProvider struct{}
func NewMockProvider ¶
func NewMockProvider() *MockProvider
func (*MockProvider) CreateIntent ¶
func (m *MockProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
func (*MockProvider) ID ¶
func (m *MockProvider) ID() string
func (*MockProvider) VerifyPayment ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func (*Module) CreatePaymentIntent ¶
func (*Module) FieldResolvers ¶
func (*Module) GetPaymentTransaction ¶
func (*Module) GetTransactionStep ¶
func (m *Module) GetTransactionStep(sCtx mdk.StepContext) mdk.StepResult
func (*Module) ListActivePaymentProviders ¶
func (m *Module) ListActivePaymentProviders(ctx context.Context) ([]*PaymentProviderInfo, error)
func (*Module) ListOrderTransactions ¶
func (*Module) ListProvidersStep ¶
func (m *Module) ListProvidersStep(sCtx mdk.StepContext) mdk.StepResult
func (*Module) ListTransactionsStep ¶
func (m *Module) ListTransactionsStep(sCtx mdk.StepContext) mdk.StepResult
func (*Module) VerifyPayment ¶
func (*Module) VerifyPaymentAp2 ¶
func (m *Module) VerifyPaymentAp2(ctx context.Context, input AP2VerificationInput) (*PaymentVerificationResult, error)
type PaymentIntent ¶
type PaymentIntent struct {
ProviderTransactionID string `json:"provider_transaction_id"`
ClientSecret string `json:"client_secret,omitempty"` // For front-end SDKs
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Status string `json:"status"`
Metadata map[string]string `json:"metadata,omitempty"`
}
PaymentIntent holds the response payload from the payment gateway setup phase.
type PaymentProvider ¶
type PaymentProvider interface {
ID() string
// CreateIntent registers a payment with the provider.
CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
// VerifyPayment confirms signatures or tokens from a checkout payload.
VerifyPayment(ctx context.Context, payload map[string]any) (bool, error)
// Refund processes a refund for a successful payment.
Refund(ctx context.Context, transactionID string, amount float64) (string, error)
}
PaymentProvider defines the operations that each payment integration must implement.
func GetProvider ¶
func GetProvider(id string) (PaymentProvider, bool)
GetProvider retrieves a payment provider by its identifier.
type PaymentProviderInfo ¶
type PaymentTransaction ¶
type PaymentTransaction struct {
ID string `gorm:"primaryKey" json:"id"`
OrderID string `gorm:"index" json:"order_id"`
Provider string `json:"provider"` // "stripe", "razorpay", "mock"
ProviderTransactionID string `gorm:"index" json:"provider_transaction_id"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Status TransactionStatus `gorm:"not null" json:"status"`
ClientSecret string `json:"client_secret,omitempty"` // Stripe client_secret or Razorpay order_id
Metadata string `json:"metadata,omitempty"` // JSON metadata string
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
PaymentTransaction tracks payment gateway state changes linked to orders.
type RazorpayProvider ¶
type RazorpayProvider struct {
BaseURL string // Custom BaseURL for testing
HTTPClient *http.Client // Custom HTTP client for testing
// contains filtered or unexported fields
}
func NewRazorpayProvider ¶
func NewRazorpayProvider(keyID, keySecret string) *RazorpayProvider
func (*RazorpayProvider) CreateIntent ¶
func (r *RazorpayProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
func (*RazorpayProvider) ID ¶
func (r *RazorpayProvider) ID() string
func (*RazorpayProvider) VerifyPayment ¶
func (*RazorpayProvider) WriteToHash ¶
type StripeProvider ¶
type StripeProvider struct {
// contains filtered or unexported fields
}
func NewStripeProvider ¶
func NewStripeProvider(secretKey string) *StripeProvider
func (*StripeProvider) CreateIntent ¶
func (s *StripeProvider) CreateIntent(ctx context.Context, orderID string, amount float64, currency string) (*PaymentIntent, error)
func (*StripeProvider) ID ¶
func (s *StripeProvider) ID() string
func (*StripeProvider) VerifyPayment ¶
type TransactionStatus ¶
type TransactionStatus string
const ( StatusPending TransactionStatus = "PENDING" StatusSucceeded TransactionStatus = "SUCCEEDED" StatusFailed TransactionStatus = "FAILED" StatusRefunded TransactionStatus = "REFUNDED" )
type WebhookHandlers ¶
type WebhookHandlers struct {
// contains filtered or unexported fields
}
func NewWebhookHandlers ¶
func NewWebhookHandlers(db *gorm.DB, rt mdk.Runtime) *WebhookHandlers
func (*WebhookHandlers) HandleRazorpay ¶
func (wh *WebhookHandlers) HandleRazorpay(w http.ResponseWriter, r *http.Request)
func (*WebhookHandlers) HandleStripe ¶
func (wh *WebhookHandlers) HandleStripe(w http.ResponseWriter, r *http.Request)