types

package
v0.0.10 Latest Latest
Warning

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

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

Documentation

Overview

Package types defines shared types for payment providers.

Index

Constants

View Source
const (
	EventCustomerCreated          = "customer.created"
	EventCustomerUpdated          = "customer.updated"
	EventCustomerDeleted          = "customer.deleted"
	EventSubscriptionCreated      = "customer.subscription.created"
	EventSubscriptionUpdated      = "customer.subscription.updated"
	EventSubscriptionDeleted      = "customer.subscription.deleted"
	EventSubscriptionTrialWillEnd = "customer.subscription.trial_will_end"
	EventInvoiceCreated           = "invoice.created"
	EventInvoicePaid              = "invoice.paid"
	EventInvoicePaymentFailed     = "invoice.payment_failed"
	EventCheckoutSessionCompleted = "checkout.session.completed"
	EventPaymentIntentSucceeded   = "payment_intent.succeeded"
	EventPaymentIntentFailed      = "payment_intent.payment_failed"
	EventPaymentMethodAttached    = "payment_method.attached"
	EventPaymentMethodDetached    = "payment_method.detached"
)

Common webhook event types

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckoutMode

type CheckoutMode string

CheckoutMode defines the checkout mode

const (
	CheckoutModeSubscription CheckoutMode = "subscription"
	CheckoutModePayment      CheckoutMode = "payment"
	CheckoutModeSetup        CheckoutMode = "setup"
)

type CheckoutRequest

type CheckoutRequest struct {
	CustomerID      string
	PriceID         string
	Quantity        int
	SuccessURL      string
	CancelURL       string
	Mode            CheckoutMode
	AllowPromoCodes bool
	TrialDays       int
	Metadata        map[string]interface{}
}

CheckoutRequest represents a checkout session request

type CheckoutSession

type CheckoutSession struct {
	ID            string
	URL           string
	CustomerID    string
	PaymentStatus string
}

CheckoutSession represents a checkout session response

type PaymentProvider

type PaymentProvider interface {
	// Provider info
	Name() string

	// Customer management
	CreateCustomer(ctx context.Context, email, name string, metadata map[string]interface{}) (customerID string, err error)
	UpdateCustomer(ctx context.Context, customerID, email, name string, metadata map[string]interface{}) error
	DeleteCustomer(ctx context.Context, customerID string) error

	// Product/Price sync (push to provider)
	SyncPlan(ctx context.Context, plan *core.Plan) error
	SyncAddOn(ctx context.Context, addon *core.AddOn) error

	// Product/Price fetch (pull from provider)
	ListProducts(ctx context.Context) ([]*ProviderProduct, error)
	GetProduct(ctx context.Context, productID string) (*ProviderProduct, error)
	ListPrices(ctx context.Context, productID string) ([]*ProviderPrice, error)

	// Subscription management
	CreateSubscription(ctx context.Context, customerID string, priceID string, quantity int, trialDays int, metadata map[string]interface{}) (subscriptionID string, err error)
	UpdateSubscription(ctx context.Context, subscriptionID string, priceID string, quantity int) error
	CancelSubscription(ctx context.Context, subscriptionID string, immediate bool) error
	PauseSubscription(ctx context.Context, subscriptionID string) error
	ResumeSubscription(ctx context.Context, subscriptionID string) error
	GetSubscription(ctx context.Context, subscriptionID string) (*ProviderSubscription, error)

	// Subscription items (for add-ons)
	AddSubscriptionItem(ctx context.Context, subscriptionID string, priceID string, quantity int) (itemID string, err error)
	RemoveSubscriptionItem(ctx context.Context, subscriptionID string, itemID string) error
	UpdateSubscriptionItem(ctx context.Context, subscriptionID string, itemID string, quantity int) error

	// Checkout
	CreateCheckoutSession(ctx context.Context, req *CheckoutRequest) (*CheckoutSession, error)
	CreatePortalSession(ctx context.Context, customerID, returnURL string) (url string, err error)

	// Payment methods
	CreateSetupIntent(ctx context.Context, customerID string) (*core.SetupIntentResult, error)
	GetPaymentMethod(ctx context.Context, paymentMethodID string) (*core.PaymentMethod, error)
	AttachPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
	DetachPaymentMethod(ctx context.Context, paymentMethodID string) error
	SetDefaultPaymentMethod(ctx context.Context, customerID, paymentMethodID string) error

	// Usage reporting
	ReportUsage(ctx context.Context, subscriptionItemID string, records []*core.UsageRecord) (recordID string, err error)

	// Invoices
	GetInvoice(ctx context.Context, invoiceID string) (*ProviderInvoice, error)
	GetInvoicePDF(ctx context.Context, invoiceID string) (url string, err error)
	VoidInvoice(ctx context.Context, invoiceID string) error
	ListInvoices(ctx context.Context, customerID string, limit int) ([]*ProviderInvoice, error)
	ListSubscriptionInvoices(ctx context.Context, subscriptionID string, limit int) ([]*ProviderInvoice, error)

	// Feature management (Stripe Product Features)
	SyncFeature(ctx context.Context, feature *core.Feature) (string, error) // Returns provider feature ID
	ListProviderFeatures(ctx context.Context, productID string) ([]*ProviderFeature, error)
	GetProviderFeature(ctx context.Context, featureID string) (*ProviderFeature, error)
	DeleteProviderFeature(ctx context.Context, featureID string) error

	// Webhooks
	HandleWebhook(ctx context.Context, payload []byte, signature string) (*WebhookEvent, error)
}

PaymentProvider defines the interface for payment provider implementations

type PriceRecurring

type PriceRecurring struct {
	Interval      string // month, year, week, day
	IntervalCount int
}

PriceRecurring represents recurring billing details for a price

type ProviderFeature added in v0.0.5

type ProviderFeature struct {
	ID        string
	Name      string
	LookupKey string // Maps to our Feature.Key
	Active    bool
	Metadata  map[string]interface{}
}

ProviderFeature represents a feature from the payment provider

type ProviderInvoice

type ProviderInvoice struct {
	ID             string
	CustomerID     string
	SubscriptionID string
	Status         string
	Currency       string
	AmountDue      int64
	AmountPaid     int64
	Total          int64
	Subtotal       int64
	Tax            int64
	PeriodStart    int64
	PeriodEnd      int64
	PDFURL         string
	HostedURL      string
}

ProviderInvoice represents invoice data from the provider

type ProviderPrice

type ProviderPrice struct {
	ID         string
	ProductID  string
	Active     bool
	Currency   string
	UnitAmount int64
	Recurring  *PriceRecurring
	Metadata   map[string]string
}

ProviderPrice represents a price from the payment provider

type ProviderProduct

type ProviderProduct struct {
	ID          string
	Name        string
	Description string
	Active      bool
	Metadata    map[string]string
}

ProviderProduct represents a product from the payment provider

type ProviderSubscription

type ProviderSubscription struct {
	ID                 string
	CustomerID         string
	Status             string
	CurrentPeriodStart int64
	CurrentPeriodEnd   int64
	TrialStart         *int64
	TrialEnd           *int64
	CancelAt           *int64
	CanceledAt         *int64
	EndedAt            *int64
	PriceID            string
	Quantity           int
	Metadata           map[string]interface{}
}

ProviderSubscription represents subscription data from the provider

type WebhookEvent

type WebhookEvent struct {
	ID        string
	Type      string
	Data      map[string]interface{}
	Object    interface{}
	Timestamp int64
}

WebhookEvent represents a parsed webhook event

Jump to

Keyboard shortcuts

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