Documentation
¶
Overview ¶
Package stripe adapts Stripe Checkout, webhooks, portal, and invoicing to the explicit v2 compat/billing contracts.
New constructs a Stripe-backed provider. Webhook verification is required by default; skip-verification paths are development-only and must be enabled with explicit dev context. This adapter is contrib-maintained and outside the stable core API promise.
Index ¶
- func AllowInsecureWebhook(ctx context.Context, ip netip.Addr) context.Context
- func AllowInsecureWebhookFromRequest(ctx context.Context, r *http.Request, resolver identity.Resolver) context.Context
- func HealthChecker(provider compatbilling.PaymentProvider) ports.HealthChecker
- type Config
- type Option
- type Provider
- func (p *Provider) CreateBillingPortalSession(ctx context.Context, in compatbilling.BillingPortalSessionInput) (compatbilling.BillingPortalSession, error)
- func (p *Provider) CreateCheckoutSession(ctx context.Context, req compatbilling.CheckoutSessionRequest) (compatbilling.CheckoutSession, error)
- func (p *Provider) CreateCustomer(ctx context.Context, in compatbilling.CustomerInput) (compatbilling.Customer, error)
- func (p *Provider) CreateInvoice(ctx context.Context, in compatbilling.InvoiceInput) (compatbilling.Invoice, error)
- func (p *Provider) CreateInvoiceItem(ctx context.Context, in compatbilling.InvoiceItemInput) (compatbilling.InvoiceItem, error)
- func (p *Provider) CreateSetupIntent(ctx context.Context, in compatbilling.SetupIntentInput) (compatbilling.SetupIntent, error)
- func (p *Provider) FinalizeInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)
- func (p *Provider) GetSubscriptionPrimaryItemID(ctx context.Context, subscriptionID string) (string, error)
- func (p *Provider) ListPrices(ctx context.Context) ([]compatbilling.Price, error)
- func (p *Provider) ParseWebhook(ctx context.Context, payload []byte, sigHeader string) (compatbilling.WebhookEvent, error)
- func (p *Provider) PayInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)
- func (p *Provider) RetrieveInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)
- func (p *Provider) RetrieveInvoiceItem(ctx context.Context, invoiceItemID string) (compatbilling.InvoiceItem, error)
- func (p *Provider) RetrievePaymentMethod(ctx context.Context, paymentMethodID string) (compatbilling.PaymentMethod, error)
- func (p *Provider) SetCustomerDefaultPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
- func (p *Provider) UpdateCustomer(ctx context.Context, customerID string, in compatbilling.CustomerInput) error
- func (p *Provider) UpdateInvoiceItem(ctx context.Context, invoiceItemID string, in compatbilling.InvoiceItemUpdate) (compatbilling.InvoiceItem, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowInsecureWebhook ¶
AllowInsecureWebhook marks the request as safe for skipping verification in dev mode. It only enables skipping when the source IP is private or loopback.
func AllowInsecureWebhookFromRequest ¶
func AllowInsecureWebhookFromRequest(ctx context.Context, r *http.Request, resolver identity.Resolver) context.Context
AllowInsecureWebhookFromRequest infers source IP from a request and marks the context accordingly.
func HealthChecker ¶
func HealthChecker(provider compatbilling.PaymentProvider) ports.HealthChecker
HealthChecker returns a Stripe payment provider checker or nil when provider is nil.
Types ¶
type Config ¶
type Config struct {
Enabled bool
SecretKey string
WebhookSecret string
WebhookSkipVerify bool
WebhookDevMode bool
FrontendBaseURL string
}
Config describes Stripe credentials and URLs.
func LoadConfig ¶
LoadConfig reads Stripe config from environment.
type Option ¶
type Option func(*Provider)
Option customizes Provider behavior.
func WithDevMode ¶
WithDevMode enables development-only webhook behavior (e.g., skipping verification).
func WithSkipVerify ¶
WithSkipVerify allows skipping webhook signature verification (dev only).
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements compatbilling.PaymentProvider using Stripe Checkout + webhooks.
func (*Provider) CreateBillingPortalSession ¶
func (p *Provider) CreateBillingPortalSession(ctx context.Context, in compatbilling.BillingPortalSessionInput) (compatbilling.BillingPortalSession, error)
CreateBillingPortalSession creates a customer portal session.
func (*Provider) CreateCheckoutSession ¶
func (p *Provider) CreateCheckoutSession(ctx context.Context, req compatbilling.CheckoutSessionRequest) (compatbilling.CheckoutSession, error)
CreateCheckoutSession creates a hosted checkout session for a single line item.
func (*Provider) CreateCustomer ¶
func (p *Provider) CreateCustomer(ctx context.Context, in compatbilling.CustomerInput) (compatbilling.Customer, error)
CreateCustomer creates a Stripe customer.
func (*Provider) CreateInvoice ¶
func (p *Provider) CreateInvoice(ctx context.Context, in compatbilling.InvoiceInput) (compatbilling.Invoice, error)
CreateInvoice creates a draft invoice for the customer.
func (*Provider) CreateInvoiceItem ¶
func (p *Provider) CreateInvoiceItem(ctx context.Context, in compatbilling.InvoiceItemInput) (compatbilling.InvoiceItem, error)
CreateInvoiceItem creates a pending invoice item.
func (*Provider) CreateSetupIntent ¶
func (p *Provider) CreateSetupIntent(ctx context.Context, in compatbilling.SetupIntentInput) (compatbilling.SetupIntent, error)
CreateSetupIntent creates a Stripe setup intent for saving payment methods.
func (*Provider) FinalizeInvoice ¶
func (p *Provider) FinalizeInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)
FinalizeInvoice finalizes a draft invoice.
func (*Provider) GetSubscriptionPrimaryItemID ¶ added in v2.1.0
func (p *Provider) GetSubscriptionPrimaryItemID(ctx context.Context, subscriptionID string) (string, error)
GetSubscriptionPrimaryItemID returns the first subscription item's id for plan-change deep links.
func (*Provider) ListPrices ¶
ListPrices fetches active prices from Stripe.
func (*Provider) ParseWebhook ¶
func (p *Provider) ParseWebhook(ctx context.Context, payload []byte, sigHeader string) (compatbilling.WebhookEvent, error)
ParseWebhook verifies and parses the Stripe webhook payload.
func (*Provider) PayInvoice ¶
PayInvoice attempts to pay an open invoice immediately using the customer's default payment method.
func (*Provider) RetrieveInvoice ¶
func (p *Provider) RetrieveInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)
RetrieveInvoice fetches an invoice by ID.
func (*Provider) RetrieveInvoiceItem ¶
func (p *Provider) RetrieveInvoiceItem(ctx context.Context, invoiceItemID string) (compatbilling.InvoiceItem, error)
RetrieveInvoiceItem fetches an invoice item to see if it's already attached to an invoice.
func (*Provider) RetrievePaymentMethod ¶
func (p *Provider) RetrievePaymentMethod(ctx context.Context, paymentMethodID string) (compatbilling.PaymentMethod, error)
RetrievePaymentMethod fetches a stored payment method details.
func (*Provider) SetCustomerDefaultPaymentMethod ¶
func (p *Provider) SetCustomerDefaultPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
SetCustomerDefaultPaymentMethod updates the customer's default invoice payment method.
func (*Provider) UpdateCustomer ¶
func (p *Provider) UpdateCustomer(ctx context.Context, customerID string, in compatbilling.CustomerInput) error
UpdateCustomer updates an existing Stripe customer.
func (*Provider) UpdateInvoiceItem ¶
func (p *Provider) UpdateInvoiceItem(ctx context.Context, invoiceItemID string, in compatbilling.InvoiceItemUpdate) (compatbilling.InvoiceItem, error)
UpdateInvoiceItem updates fields on a draft invoice item.