Versions in this module Expand all Collapse all v0 v0.1.0 Oct 28, 2026 Changes in this version + const MetaApp + const MetaPlan + const MetaProduct + const MetaSeller + const MetaSubject + const StatusActive + const StatusCanceled + const StatusIncomplete + const StatusIncompleteExpired + const StatusPastDue + const StatusPaused + const StatusTrialing + const StatusUnpaid + var ErrAlreadySubscribed = errors.New("payforge: subject already has a subscription") + var ErrAmountNotAllowed = errors.New("payforge: product has a fixed price") + var ErrBelowMinimum = errors.New("payforge: amount is below the product's minimum") + var ErrForeignAccount = errors.New("payforge: the connected account does not belong to this app") + var ErrInvalidAccount = errors.New("payforge: invalid connected account") + var ErrInvalidSubject = errors.New("payforge: invalid subject") + var ErrInvalidURL = errors.New("payforge: invalid return URL") + var ErrNoMarketplace = errors.New("payforge: the spec has no marketplace") + var ErrNoPrice = errors.New("payforge: plan has no price for the interval") + var ErrNotConfigured = errors.New("payforge: billing is not configured") + var ErrNotFound = errors.New("payforge: not found") + var ErrNotSelfServe = errors.New("payforge: plan is not self-serve") + var ErrNotSynced = errors.New("payforge: price not found at the provider; sync the catalog") + var ErrPayloadTooLarge = errors.New("payforge: webhook payload too large") + var ErrSellerNotReady = errors.New("payforge: the seller's account cannot take charges") + var ErrSignatureInvalid = errors.New("payforge: webhook signature invalid") + var ErrUnknownPlan = errors.New("payforge: unknown plan") + var ErrUnknownProduct = errors.New("payforge: unknown product") + func CheckStartup(spec *pricingspec.Spec, cfg ProviderConfig) error + func Fee(amountCents int64, bps int) (int64, error) + func FeeBps(spec *pricingspec.Spec, sellerPlan string) (int, error) + func Grants(status string) bool + func LockKey(app, subject string) string + func MetadataPlan(meta map[string]string, legacyPrefixes []string) string + func MetadataSubject(meta map[string]string, legacyPrefixes []string) string + func ParsePlanLookupKey(key string) (app, plan string, interval pricingspec.Interval, ok bool) + func PlanLookupKey(app, plan string, interval pricingspec.Interval) string + func ProductLookupKey(app, product string) string + type AccountReader interface + Account func(ctx context.Context, accountID string) (AccountState, error) + type AccountState struct + ChargesEnabled bool + DetailsSubmitted bool + ID string + PayoutsEnabled bool + type Billing interface + CheckoutPlan func(ctx context.Context, c PlanCheckout) (Session, error) + CheckoutProduct func(ctx context.Context, c ProductCheckout) (Session, error) + Enabled func() bool + EnsureCustomer func(ctx context.Context, s Subject) (string, error) + Plan func(stored string) pricingspec.Plan + Portal func(ctx context.Context, customerID, returnURL string) (string, error) + func Disabled(spec *pricingspec.Spec) Billing + type ChargeDispute struct + AmountCents int64 + ChargeID string + Closed bool + Currency string + DisputeID string + EventID string + Lost bool + PaymentIntent string + Reason string + Status string + Won bool + type CheckoutResult struct + AmountCents int64 + Currency string + Mode string + Paid bool + PaymentIntent string + Reference string + SessionID string + SubscriptionID string + type Connect interface + Account func(ctx context.Context, accountID string) (AccountState, error) + CheckoutSale func(ctx context.Context, s Sale) (Session, error) + CreateAccount func(ctx context.Context, seller Subject, country string) (string, error) + OnboardingLink func(ctx context.Context, accountID, refreshURL, returnURL string) (string, error) + type DisputeResult struct + AmountCents int64 + ChargeID string + Currency string + ID string + PaymentIntent string + Reason string + Status string + type DisputeSink interface + ApplyDispute func(ctx context.Context, d ChargeDispute) error + type Entitlement struct + CustomerID string + EventID string + Granted bool + Origin Origin + Plan string + Status string + Subject string + SubscribedPlan string + SubscriptionID string + ValidUntil time.Time + type EntitlementSink interface + Apply func(ctx context.Context, e Entitlement) error + type Event struct + Account string + AccountState *AccountState + App string + Checkout *CheckoutResult + Created time.Time + CustomerID string + Dispute *DisputeResult + ID string + Invoice *InvoiceResult + Kind EventKind + Livemode bool + Metadata map[string]string + Plan string + Product string + Refund *RefundResult + Subject string + Subscription *SubscriptionState + Type string + type EventKind string + const EventAccountUpdated + const EventCheckoutCompleted + const EventCheckoutFailed + const EventDisputeClosed + const EventDisputeOpened + const EventIgnored + const EventInvoiceFailed + const EventInvoicePaid + const EventRefunded + const EventSubscriptionCreated + const EventSubscriptionEnded + const EventSubscriptionUpdated + type InvoiceResult struct + AmountCents int64 + Currency string + ID string + SubscriptionID string + type Lifecycle struct + Accounts AccountReader + Disputes DisputeSink + LegacyPrices map[string]string + Locker Locker + Provider SubscriptionReader + Sales SaleSink + Sellers SellerSink + Sink EntitlementSink + Spec *pricingspec.Spec + Store Store + func (l *Lifecycle) Handle(ctx context.Context, ev Event) (Result, error) + type Locker interface + Lock func(ctx context.Context, key string) (unlock func(), err error) + type MemoryLocker struct + func (m *MemoryLocker) Lock(ctx context.Context, key string) (func(), error) + type MemorySink struct + func NewMemorySink() *MemorySink + func (m *MemorySink) Apply(_ context.Context, e Entitlement) error + func (m *MemorySink) ApplyDispute(_ context.Context, d ChargeDispute) error + func (m *MemorySink) ApplyRefund(_ context.Context, r SaleRefund) error + func (m *MemorySink) ApplySeller(_ context.Context, a SellerAccount) error + func (m *MemorySink) Dispute(disputeID string) (ChargeDispute, bool) + func (m *MemorySink) Get(subject string) (Entitlement, bool) + func (m *MemorySink) History() []Entitlement + func (m *MemorySink) Refund(chargeID string) (SaleRefund, bool) + func (m *MemorySink) Seller(accountID string) (SellerAccount, bool) + type MemoryStore struct + func NewMemoryStore() *MemoryStore + func (m *MemoryStore) Link(customerID, subject string) + func (m *MemoryStore) MarkSeen(_ context.Context, eventID string) error + func (m *MemoryStore) Seen(_ context.Context, eventID string) (bool, error) + func (m *MemoryStore) SubjectForCustomer(_ context.Context, customerID string) (string, error) + type Origin string + const OriginSubscription + type Outcome string + const OutcomeApplied + const OutcomeDuplicate + const OutcomeIgnored + const OutcomeSkipped + type PlanCheckout struct + CancelURL string + Interval pricingspec.Interval + Plan string + Subject Subject + SuccessURL string + type ProductCheckout struct + AmountCents int64 + CancelURL string + Product string + Reference string + Subject Subject + SuccessURL string + type ProviderConfig struct + SecretKey string + WebhookSecrets []string + func (c ProviderConfig) Configured() bool + type ProviderPlan struct + Prices []ProviderPrice + Products []ProviderProduct + func ProviderPlanFor(spec *pricingspec.Spec) ProviderPlan + type ProviderPrice struct + AmountCents int64 + Currency string + Interval pricingspec.Interval + LookupKey string + Metadata map[string]string + ProductKey string + type ProviderProduct struct + Key string + Metadata map[string]string + Name string + type RefundResult struct + AmountCents int64 + ChargeID string + Full bool + PaymentIntent string + RefundedCents int64 + type Result struct + Dispute *ChargeDispute + Entitlement *Entitlement + Outcome Outcome + Reason string + Refund *SaleRefund + Seller *SellerAccount + type Sale struct + AmountCents int64 + Buyer Subject + CancelURL string + Product string + Reference string + SellerAccount string + SellerPlan string + SuccessURL string + type SaleRefund struct + AmountCents int64 + ChargeID string + EventID string + Full bool + PaymentIntent string + Product string + RefundedCents int64 + Seller string + Subject string + type SaleSink interface + ApplyRefund func(ctx context.Context, r SaleRefund) error + type SellerAccount struct + AccountID string + ChargesEnabled bool + DetailsSubmitted bool + EventID string + PayoutsEnabled bool + Subject string + type SellerSink interface + ApplySeller func(ctx context.Context, a SellerAccount) error + type Session struct + ID string + URL string + type Store interface + MarkSeen func(ctx context.Context, eventID string) error + Seen func(ctx context.Context, eventID string) (bool, error) + SubjectForCustomer func(ctx context.Context, customerID string) (string, error) + type Subject struct + Email string + ID string + Name string + type SubscriptionItem struct + LookupKey string + PriceID string + type SubscriptionReader interface + Subscriptions func(ctx context.Context, customerID string) ([]SubscriptionState, error) + type SubscriptionState struct + CancelAtPeriodEnd bool + ID string + Items []SubscriptionItem + Metadata map[string]string + PeriodEnd time.Time + Status string + TrialEnd time.Time