stripe

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowInsecureWebhook

func AllowInsecureWebhook(ctx context.Context, ip netip.Addr) context.Context

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

func LoadConfig(loader *config.Loader) Config

LoadConfig reads Stripe config from environment.

type Option

type Option func(*Provider)

Option customizes Provider behavior.

func WithDevMode

func WithDevMode(dev bool) Option

WithDevMode enables development-only webhook behavior (e.g., skipping verification).

func WithSkipVerify

func WithSkipVerify(skip bool) Option

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 New

func New(secretKey, webhookSecret string, opts ...Option) *Provider

New returns a Stripe-backed payment provider.

func (*Provider) CreateBillingPortalSession

CreateBillingPortalSession creates a customer portal session.

func (*Provider) CreateCheckoutSession

CreateCheckoutSession creates a hosted checkout session for a single line item.

func (*Provider) CreateCustomer

CreateCustomer creates a Stripe customer.

func (*Provider) CreateInvoice

CreateInvoice creates a draft invoice for the customer.

func (*Provider) CreateInvoiceItem

CreateInvoiceItem creates a pending invoice item.

func (*Provider) CreateSetupIntent

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

func (p *Provider) ListPrices(ctx context.Context) ([]compatbilling.Price, error)

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

func (p *Provider) PayInvoice(ctx context.Context, invoiceID string) (compatbilling.Invoice, error)

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.

Jump to

Keyboard shortcuts

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