stripe

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 9 Imported by: 0

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

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 New

func New(cfg Config, opts ...Option) *Adapter

New constructs a Stripe adapter. Returns nil when not configured.

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

func (a *Adapter) Configured() bool

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) Provider

func (a *Adapter) Provider() payment.Provider

Provider returns the gateway identifier.

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.

type Option

type Option func(*Config)

Option mutates Config.

func WithHTTPTimeout

func WithHTTPTimeout(d time.Duration) Option

WithHTTPTimeout sets the outbound HTTP timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL