Documentation
¶
Overview ¶
Package billing exposes the provider-shaped v2 billing compatibility surface outside the generic ports package.
New code that wants the existing hosted-checkout, webhook, invoicing, and billing-portal contract should depend on this package explicitly instead of importing those types from ports. All identifiers here are aliases to the existing ports exports so migration stays source-compatible for the rest of v2.
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 ¶
- type BillingPortalFlowAfterCompletion
- type BillingPortalFlowAfterCompletionType
- type BillingPortalFlowData
- type BillingPortalFlowSubscriptionUpdateConfirm
- type BillingPortalFlowSubscriptionUpdateConfirmItem
- type BillingPortalFlowType
- type BillingPortalSession
- type BillingPortalSessionInput
- type BillingProvider
- type CheckoutSession
- type CheckoutSessionRequest
- type Customer
- type CustomerAddress
- type CustomerInput
- type Invoice
- type InvoiceInput
- type InvoiceItem
- type InvoiceItemInput
- type InvoiceItemUpdate
- type PaymentMethod
- type PaymentProvider
- type Price
- type SetupIntent
- type SetupIntentInput
- type WebhookEvent
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
SetupIntent represents a setup intent response.
type SetupIntentInput ¶
SetupIntentInput describes a payment method setup intent request.
type WebhookEvent ¶
WebhookEvent is a generic payment provider webhook payload wrapper.