Documentation
¶
Overview ¶
Package stripe implements the payment.PaymentProvider interface for Stripe Checkout (v81).
The adapter wraps github.com/stripe/stripe-go/v81 to create Checkout Sessions and verify webhook signatures. It is stateless after construction and safe for concurrent use.
Index ¶
- type Adapter
- func (a *Adapter) BuildWebhookResponse(ctx context.Context, success bool, msg string) (*payment.WebhookResponse, error)
- func (a *Adapter) Configured() bool
- func (a *Adapter) CreateCheckout(ctx context.Context, req *payment.CheckoutRequest) (*payment.CheckoutResult, error)
- func (a *Adapter) Provider() payment.Provider
- func (a *Adapter) QueryOrder(ctx context.Context, req *payment.OrderQuery) (*payment.OrderQueryResult, error)
- func (a *Adapter) VerifyWebhook(ctx context.Context, req *payment.WebhookVerifyRequest) (*payment.WebhookEvent, error)
- type Config
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements payment.PaymentProvider for Stripe.
func (*Adapter) BuildWebhookResponse ¶
func (a *Adapter) BuildWebhookResponse(ctx context.Context, success bool, msg string) (*payment.WebhookResponse, error)
BuildWebhookResponse returns a 200 OK with empty body for Stripe. Stripe only requires the HTTP status; the body is ignored.
func (*Adapter) Configured ¶
Configured reports whether the adapter has the minimum credentials.
func (*Adapter) CreateCheckout ¶
func (a *Adapter) CreateCheckout(ctx context.Context, req *payment.CheckoutRequest) (*payment.CheckoutResult, error)
CreateCheckout creates a Stripe Checkout Session and returns its URL.
Currency is mapped to Stripe's minor-unit convention (USD 12.34 -> 1234 cents). The TradeNo is stored as client_reference_id and echoed back in webhook events.
func (*Adapter) QueryOrder ¶
func (a *Adapter) QueryOrder(ctx context.Context, req *payment.OrderQuery) (*payment.OrderQueryResult, error)
QueryOrder retrieves a Checkout Session by TradeNo (client_reference_id). Stripe does not index by client_reference_id server-side, so this performs a list-and-filter. For high-volume deployments, prefer storing the SessionID at checkout time and querying by it.
func (*Adapter) VerifyWebhook ¶
func (a *Adapter) VerifyWebhook(ctx context.Context, req *payment.WebhookVerifyRequest) (*payment.WebhookEvent, error)
VerifyWebhook verifies the Stripe-Signature header and parses the event into a normalized WebhookEvent.
req.RawBody must be the exact bytes of the webhook request body. req.Signature is the Stripe-Signature header value.
type Config ¶
type Config struct {
// APIKey is the secret key (sk_live_... or sk_test_...).
APIKey string
// WebhookSecret is the signing secret for the webhook endpoint
// (whsec_...).
WebhookSecret string
// PriceID is the default Stripe Price object id used when the
// CheckoutRequest does not carry a ProductID. May be empty if
// callers always pass ProductID.
PriceID string
// UnitPrice is the fallback USD price per unit when PriceID is empty
// and the adapter must build an inline price. Expressed in USD
// major units (e.g. 8.0 means $8.00).
UnitPrice float64
// HTTPTimeout is the timeout for outbound API calls. Defaults to 30s.
HTTPTimeout time.Duration
}
Config holds the Stripe API credentials.