Documentation
¶
Overview ¶
Package gateways holds the concrete payment gateways (Stripe, Razorpay, PayU, …). Each implements contracts.PaymentGateway. To add a gateway, drop a new file here implementing the interface and register it in the manager.
Index ¶
- type PayUConfig
- type PayUGateway
- func (p *PayUGateway) CreateCharge(ctx context.Context, cp contracts.ChargeParams) (*contracts.Charge, error)
- func (p *PayUGateway) Name() string
- func (p *PayUGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
- func (p *PayUGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
- type RazorpayConfig
- type RazorpayGateway
- func (r *RazorpayGateway) CreateCharge(ctx context.Context, p contracts.ChargeParams) (*contracts.Charge, error)
- func (r *RazorpayGateway) Name() string
- func (r *RazorpayGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
- func (r *RazorpayGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
- type StripeConfig
- type StripeGateway
- func (s *StripeGateway) CreateCharge(ctx context.Context, p contracts.ChargeParams) (*contracts.Charge, error)
- func (s *StripeGateway) Name() string
- func (s *StripeGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
- func (s *StripeGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PayUConfig ¶
PayUConfig configures the PayU (India) gateway. PaymentURL defaults to the production endpoint; use https://test.payu.in/_payment for sandbox.
type PayUGateway ¶
type PayUGateway struct {
// contains filtered or unexported fields
}
PayUGateway implements contracts.PaymentGateway for PayU India. PayU is a hash-signed browser-form flow: CreateCharge returns the signed form fields + action URL (Charge.Raw / RedirectURL) which the frontend auto-submits; PayU posts the result back, verified with VerifyWebhook (reverse hash).
func (*PayUGateway) CreateCharge ¶
func (p *PayUGateway) CreateCharge(ctx context.Context, cp contracts.ChargeParams) (*contracts.Charge, error)
CreateCharge builds the signed PayU request. It does not call PayU — the returned Charge.Raw holds the form fields the browser POSTs to RedirectURL.
func (*PayUGateway) Name ¶
func (p *PayUGateway) Name() string
func (*PayUGateway) VerifyPayment ¶
func (p *PayUGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
VerifyPayment verifies a PayU response supplied as PaymentProof (OrderID=txnid, Signature=posted hash). Prefer VerifyWebhook when you have the full form.
func (*PayUGateway) VerifyWebhook ¶
func (p *PayUGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
VerifyWebhook verifies a PayU callback. The payload is the raw form-encoded body (application/x-www-form-urlencoded); the reverse hash is recomputed and compared to the posted "hash".
type RazorpayConfig ¶
RazorpayConfig configures the Razorpay gateway (India).
type RazorpayGateway ¶
type RazorpayGateway struct {
// contains filtered or unexported fields
}
RazorpayGateway implements contracts.PaymentGateway via Razorpay Orders + client-side Checkout. Flow: CreateCharge → an order id → the frontend opens Razorpay Checkout → on success it returns {order_id, payment_id, signature} which VerifyPayment validates. Webhooks are verified with VerifyWebhook.
func NewRazorpay ¶
func NewRazorpay(cfg RazorpayConfig) *RazorpayGateway
NewRazorpay builds the Razorpay gateway.
func (*RazorpayGateway) CreateCharge ¶
func (r *RazorpayGateway) CreateCharge(ctx context.Context, p contracts.ChargeParams) (*contracts.Charge, error)
CreateCharge creates a Razorpay order (Charge.ID is the order id; no redirect).
func (*RazorpayGateway) Name ¶
func (r *RazorpayGateway) Name() string
func (*RazorpayGateway) VerifyPayment ¶
func (r *RazorpayGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
VerifyPayment validates a Checkout callback: HMAC-SHA256("<order>|<payment>", key_secret) must equal the returned signature (constant-time).
func (*RazorpayGateway) VerifyWebhook ¶
func (r *RazorpayGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
VerifyWebhook validates X-Razorpay-Signature (HMAC-SHA256 of the raw body).
type StripeConfig ¶
type StripeConfig struct {
SecretKey string // sk_...
WebhookSecret string // whsec_...
Tolerance time.Duration // webhook timestamp tolerance (default 5m)
}
StripeConfig configures the Stripe gateway (international hosted checkout).
type StripeGateway ¶
type StripeGateway struct {
// contains filtered or unexported fields
}
StripeGateway implements contracts.PaymentGateway via Stripe hosted Checkout.
func NewStripe ¶
func NewStripe(cfg StripeConfig) *StripeGateway
NewStripe builds the Stripe gateway.
func (*StripeGateway) CreateCharge ¶
func (s *StripeGateway) CreateCharge(ctx context.Context, p contracts.ChargeParams) (*contracts.Charge, error)
CreateCharge creates a hosted Checkout session; redirect to Charge.RedirectURL.
func (*StripeGateway) Name ¶
func (s *StripeGateway) Name() string
func (*StripeGateway) VerifyPayment ¶
func (s *StripeGateway) VerifyPayment(ctx context.Context, proof contracts.PaymentProof) (bool, error)
VerifyPayment retrieves the Checkout session (id in proof.OrderID) and reports whether it is paid.
func (*StripeGateway) VerifyWebhook ¶
func (s *StripeGateway) VerifyWebhook(payload []byte, headers http.Header) (*contracts.WebhookEvent, error)
VerifyWebhook validates the Stripe-Signature header (HMAC-SHA256 of "t.body").