billing

package
v3.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package billing contains the v3 compatibility model for hosted checkout, billing portal, invoicing, and generic payment-provider webhooks.

These contracts are defined here directly so provider-shaped billing boundaries stay out of the generic ports package. Use this package when the hosted-checkout, webhook, invoicing, and billing-portal shape fits the application; otherwise define an app-owned port or use a dedicated adapter contract.

This package is compatibility-sensitive, not provider-neutral. Applications that need a different billing model should define an app-owned port or use a dedicated adapter contract instead of widening the stable ports package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingPortalFlowAfterCompletion

type BillingPortalFlowAfterCompletion struct {
	Type              BillingPortalFlowAfterCompletionType
	RedirectReturnURL string
}

BillingPortalFlowAfterCompletion configures the post-flow behavior.

type BillingPortalFlowAfterCompletionType

type BillingPortalFlowAfterCompletionType string

BillingPortalFlowAfterCompletionType describes behavior once a deep-link flow completes.

const (
	// BillingPortalFlowAfterCompletionTypeRedirect redirects customer to provided URL after completion.
	BillingPortalFlowAfterCompletionTypeRedirect BillingPortalFlowAfterCompletionType = "redirect"
)

type BillingPortalFlowData

type BillingPortalFlowData struct {
	Type                      BillingPortalFlowType
	AfterCompletion           *BillingPortalFlowAfterCompletion
	SubscriptionUpdateConfirm *BillingPortalFlowSubscriptionUpdateConfirm
}

BillingPortalFlowData configures a deep-link flow in billing portal session creation.

type BillingPortalFlowSubscriptionUpdateConfirm

type BillingPortalFlowSubscriptionUpdateConfirm struct {
	SubscriptionID string
	Items          []BillingPortalFlowSubscriptionUpdateConfirmItem
}

BillingPortalFlowSubscriptionUpdateConfirm configures a targeted subscription update confirmation.

type BillingPortalFlowSubscriptionUpdateConfirmItem

type BillingPortalFlowSubscriptionUpdateConfirmItem struct {
	SubscriptionItemID string
	PriceID            string
	Quantity           int64
}

BillingPortalFlowSubscriptionUpdateConfirmItem describes one item update inside confirm flow.

type BillingPortalFlowType

type BillingPortalFlowType string

BillingPortalFlowType describes customer portal deep-link flow types.

const (
	// BillingPortalFlowTypeSubscriptionUpdateConfirm opens a confirmation flow for a specific plan update.
	BillingPortalFlowTypeSubscriptionUpdateConfirm BillingPortalFlowType = "subscription_update_confirm"
)

type BillingPortalSession

type BillingPortalSession struct {
	ID  string
	URL string
}

BillingPortalSession represents a customer portal session.

type BillingPortalSessionInput

type BillingPortalSessionInput struct {
	CustomerID string
	ReturnURL  string
	Locale     string
	Flow       *BillingPortalFlowData
}

BillingPortalSessionInput describes a customer portal session request.

type BillingProvider

type BillingProvider interface {
	CreateCustomer(ctx context.Context, in CustomerInput) (Customer, error)
	UpdateCustomer(ctx context.Context, customerID string, in CustomerInput) error
	CreateSetupIntent(ctx context.Context, in SetupIntentInput) (SetupIntent, error)
	SetCustomerDefaultPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
	RetrievePaymentMethod(ctx context.Context, paymentMethodID string) (PaymentMethod, error)
	CreateInvoiceItem(ctx context.Context, in InvoiceItemInput) (InvoiceItem, error)
	RetrieveInvoiceItem(ctx context.Context, invoiceItemID string) (InvoiceItem, error)
	UpdateInvoiceItem(ctx context.Context, invoiceItemID string, in InvoiceItemUpdate) (InvoiceItem, error)
	CreateInvoice(ctx context.Context, in InvoiceInput) (Invoice, error)
	FinalizeInvoice(ctx context.Context, invoiceID string) (Invoice, error)
	PayInvoice(ctx context.Context, invoiceID string) (Invoice, error)
	RetrieveInvoice(ctx context.Context, invoiceID string) (Invoice, error)
	CreateBillingPortalSession(ctx context.Context, in BillingPortalSessionInput) (BillingPortalSession, error)
}

BillingProvider defines billing-related operations for hosted invoicing.

type CheckoutSession

type CheckoutSession struct {
	ID  string
	URL string
}

CheckoutSession represents a provider-created hosted checkout session.

type CheckoutSessionRequest

type CheckoutSessionRequest struct {
	Amount               int64             // Minor units (cents)
	Currency             string            // ISO currency, e.g. "eur"
	PriceID              string            // Provider-specific price ID (preferred)
	SuccessURL           string            // Where to redirect on success
	CancelURL            string            // Where to redirect on cancellation
	Metadata             map[string]string // Arbitrary key/value for reconciliation
	Mode                 string            // "payment" | "subscription"
	Locale               string            // Optional locale code, provider-specific
	CustomerID           string            // Optional provider customer ID
	CustomerEmail        string            // Optional customer email address
	ClientReferenceID    string            // Optional client-side correlation ID
	SubscriptionMetadata map[string]string // Metadata for subscription objects
}

CheckoutSessionRequest describes a hosted checkout request.

type Customer

type Customer struct {
	ID string
}

Customer represents a billing customer.

type CustomerAddress

type CustomerAddress struct {
	Line1      string
	Line2      string
	City       string
	State      string
	PostalCode string
	Country    string
}

CustomerAddress describes a customer's billing address.

type CustomerInput

type CustomerInput struct {
	Name     string
	Email    string
	Phone    string
	Address  *CustomerAddress
	Metadata map[string]string
}

CustomerInput describes a new billing customer.

type Invoice

type Invoice struct {
	ID               string
	Status           string
	Currency         string
	AmountDue        int64
	AmountPaid       int64
	HostedInvoiceURL string
	CreatedAt        time.Time
	DueDate          *time.Time
	FinalizedAt      *time.Time
	PaidAt           *time.Time
}

Invoice represents a billing invoice.

type InvoiceInput

type InvoiceInput struct {
	CustomerID                  string
	AutoAdvance                 bool
	AutomaticTax                bool
	CollectionMethod            string
	DueDays                     *int
	PendingInvoiceItemsBehavior string
	Metadata                    map[string]string
	IdempotencyKey              string
}

InvoiceInput describes a draft invoice creation request.

type InvoiceItem

type InvoiceItem struct {
	ID        string
	InvoiceID string
}

InvoiceItem represents a created invoice item.

type InvoiceItemInput

type InvoiceItemInput struct {
	CustomerID     string
	Amount         int64
	Currency       string
	Description    string
	TaxBehavior    string
	Metadata       map[string]string
	IdempotencyKey string
}

InvoiceItemInput describes a pending invoice item.

type InvoiceItemUpdate

type InvoiceItemUpdate struct {
	TaxBehavior string
}

InvoiceItemUpdate describes a patch for an invoice item.

type PaymentMethod

type PaymentMethod struct {
	ID       string
	Brand    string
	Last4    string
	ExpMonth int
	ExpYear  int
}

PaymentMethod describes a stored payment method.

type PaymentProvider

type PaymentProvider interface {
	CreateCheckoutSession(ctx context.Context, req CheckoutSessionRequest) (CheckoutSession, error)
	ParseWebhook(ctx context.Context, payload []byte, sigHeader string) (WebhookEvent, error)
	ListPrices(ctx context.Context) ([]Price, error)
}

PaymentProvider defines a hosted checkout and webhook contract.

type Price

type Price struct {
	ID         string
	ProductID  string
	Currency   string
	UnitAmount int64
	Nickname   string
	Metadata   map[string]string
	Active     bool
}

Price represents a payment provider price.

type SetupIntent

type SetupIntent struct {
	ID              string
	ClientSecret    string
	CustomerID      string
	PaymentMethodID string
}

SetupIntent represents a setup intent response.

type SetupIntentInput

type SetupIntentInput struct {
	CustomerID string
	Usage      string
	Metadata   map[string]string
}

SetupIntentInput describes a payment method setup intent request.

type WebhookEvent

type WebhookEvent struct {
	ID        string
	Type      string
	CreatedAt time.Time
	Payload   json.RawMessage
}

WebhookEvent is a generic payment provider webhook payload wrapper.

Jump to

Keyboard shortcuts

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