billingv1
import billingv1 "pocketone.dev/ext/contracts/billing/v1"
Package billingv1 is the billing/v1 contract: selling subscriptions and one-time purchases from an app, whatever processor takes the money. The provider (ext/billing) keeps who bought what (items), turns processors' webhooks into item changes, sums what each owner's items grant (entitlements), and raises OnItemChanged so the app reacts. Processors are payments/v1 providers (ext/stripe, ext/paddle, ext/creem).
Products and items are records in the provider's collections (edited with PocketBase's records API, or the Billing page in the dashboard); this contract runs the actions around them.
A wire contract at /api/_c/billing/v1. Operations a customer calls (checkout, portal, their own items) are public: the provider lets a signed-in owner act on their own items and a superuser act on anyone's. The webhook is public and checked by its processor's signature.
Source: ext/contracts/billing/v1.
Constants
const (
KindSubscription = "subscription"
KindOrder = "order"
KindManual = "manual"
)
Item kinds.
Variables
var Contract = extkit.NewContract[Billing]("billing/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)
Contract is billing/v1.
var ErrNotOwner = &extkit.Error{Code: "not_owner", Message: "that item isn't yours", Status: 403}
ErrNotOwner: the caller isn't the item's owner (or a superuser).
var ErrSignIn = &extkit.Error{Code: "sign_in", Message: "sign in to buy", Status: 401}
ErrSignIn: signed-out checkout is off on this app.
var ErrUnknownProduct = &extkit.Error{Code: "unknown_product", Message: "no such product for sale", Status: 404}
ErrUnknownProduct: no product with that key, or not sold through the checkout processor.
var W = extkit.NewWire(Contract, "billing", func(inner Billing, g *extkit.Guard[Billing]) Billing {
return &guardBilling{inner, g}
},
extkit.Op[Billing]{
Name: "checkout",
Desc: "Starts a purchase of a product. Signed in, it's for the caller; signed out, it's pay-first when the app allows it: the purchase goes to the owner with the checkout email (or the one OnOwnerNeeded makes), and Claim lets the browser claim it.",
Method: "POST",
Path: "checkout",
Scope: "public",
In: reflect.TypeOf(CheckoutInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in CheckoutInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Checkout(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "pay",
Desc: "Serves the checkout page for processors whose checkout must run on a page of the app's.",
Method: "GET",
Path: "pay",
Scope: "public",
In: reflect.TypeOf(PayInput{}),
Out: extkit.OutRaw,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in PayInput
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Pay(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "portal",
Desc: "Links an owner to their processor's customer portal (cards, invoices), for one item or their latest.",
Method: "POST",
Path: "portal",
Scope: "public",
In: reflect.TypeOf(PortalInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in PortalInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Portal(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "items",
Desc: "Lists an owner's items: the caller's own, or anyone's for a superuser.",
Method: "GET",
Path: "items",
Scope: "public",
In: reflect.TypeOf(OwnerRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in OwnerRef
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Items(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "entitlements",
Desc: "Sums what an owner's active items grant (instances = 5), with the items each unit comes from.",
Method: "GET",
Path: "entitlements",
Scope: "public",
In: reflect.TypeOf(OwnerRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in OwnerRef
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Entitlements(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "cancel",
Desc: "Cancels a subscription now or at the end of its paid period.",
Method: "POST",
Path: "cancel",
Scope: "public",
In: reflect.TypeOf(CancelInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in CancelInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Cancel(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "resume",
Desc: "Undoes a cancel scheduled for the end of the period.",
Method: "POST",
Path: "resume",
Scope: "public",
In: reflect.TypeOf(ItemRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in ItemRef
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Resume(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "quantity",
Desc: "Changes how many units a subscription bills for.",
Method: "POST",
Path: "quantity",
Scope: "public",
In: reflect.TypeOf(QuantityInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in QuantityInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Quantity(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "plan",
Desc: "Moves a subscription to another product.",
Method: "POST",
Path: "plan",
Scope: "public",
In: reflect.TypeOf(PlanInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in PlanInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Plan(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "webhook",
Desc: "Takes a processor's webhook call (?provider=stripe). Point each processor's webhook here.",
Method: "POST",
Path: "webhook",
Scope: "public",
RawIn: true,
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
in := extkit.RawIn{Query: req.Query, Body: req.Body, ContentType: req.ContentType, Header: req.Header}
return impl.Webhook(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "refund",
Desc: "Asks the item's processor to refund it (in full, or Amount). The item changes when the refund arrives.",
Method: "POST",
Path: "refund",
In: reflect.TypeOf(RefundInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in RefundInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Refund(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "grant",
Desc: "Gives an owner a manual item: units of a product with no processor (comps, migrations, support).",
Method: "POST",
Path: "grant",
In: reflect.TypeOf(GrantInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in GrantInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Grant(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "revoke",
Desc: "Ends a manual item.",
Method: "POST",
Path: "revoke",
In: reflect.TypeOf(ItemRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in ItemRef
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Revoke(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "sync",
Desc: "Re-reads one item from its processor and writes what it finds.",
Method: "POST",
Path: "sync",
In: reflect.TypeOf(ItemRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in ItemRef
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Sync(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "reconcile",
Desc: "Re-reads every item that hasn't ended from its processor; DryRun reports what would change.",
Method: "POST",
Path: "reconcile",
In: reflect.TypeOf(ReconcileInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in ReconcileInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Reconcile(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "check",
Desc: "Looks up a product's price at each processor it names, so an admin can check the ids.",
Method: "POST",
Path: "check",
Scope: "billing:read",
In: reflect.TypeOf(ProductRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in ProductRef
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Check(ctx, a, in)
},
},
extkit.Op[Billing]{
Name: "processors",
Desc: "Lists the installed payment processors: which takes checkouts, whether each is set up, and the webhook URL to give it.",
Method: "GET",
Path: "processors",
Scope: "billing:read",
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Billing, a extkit.Auth, req extkit.OpRequest) (any, error) {
return impl.Processors(ctx, a)
},
},
)
W is billing/v1's wire side: routes at /api/_c/billing/v1/<op>, action hooks, MCP tools and the client.
Functions
OnCancel
func OnCancel(owner any, fn func(e *extkit.CallEvent, in *CancelInput) error)
OnCancel binds fn to cancel calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnCheck
func OnCheck(owner any, fn func(e *extkit.CallEvent, in *ProductRef) error)
OnCheck binds fn to check calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnCheckout
func OnCheckout(owner any, fn func(e *extkit.CallEvent, in *CheckoutInput) error)
OnCheckout binds fn to checkout calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnEntitlements
func OnEntitlements(owner any, fn func(e *extkit.CallEvent, in *OwnerRef) error)
OnEntitlements binds fn to entitlements calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnGrant
func OnGrant(owner any, fn func(e *extkit.CallEvent, in *GrantInput) error)
OnGrant binds fn to grant calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnGuestPurchase
func OnGuestPurchase(app core.App) *hook.Hook[*GuestEvent]
OnGuestPurchase is the hook a signed-out purchase goes through once its owner is known.
OnItemChanged
func OnItemChanged(app core.App) *hook.Hook[*ItemEvent]
OnItemChanged is the hook every item change goes through, after it's saved.
OnItems
func OnItems(owner any, fn func(e *extkit.CallEvent, in *OwnerRef) error)
OnItems binds fn to items calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnOwnerNeeded
func OnOwnerNeeded(app core.App) *hook.Hook[*OwnerEvent]
OnOwnerNeeded is the hook a signed-out purchase goes through when no owner has its email: the app's chance to make one (OwnerEvent).
OnPay
func OnPay(owner any, fn func(e *extkit.CallEvent, in *PayInput) error)
OnPay binds fn to pay calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnPlan
func OnPlan(owner any, fn func(e *extkit.CallEvent, in *PlanInput) error)
OnPlan binds fn to plan calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnPortal
func OnPortal(owner any, fn func(e *extkit.CallEvent, in *PortalInput) error)
OnPortal binds fn to portal calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnProcessors
func OnProcessors(owner any, fn func(e *extkit.CallEvent) error)
OnProcessors binds fn to processors calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse.
OnQuantity
func OnQuantity(owner any, fn func(e *extkit.CallEvent, in *QuantityInput) error)
OnQuantity binds fn to quantity calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnReconcile
func OnReconcile(owner any, fn func(e *extkit.CallEvent, in *ReconcileInput) error)
OnReconcile binds fn to reconcile calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnRefund
func OnRefund(owner any, fn func(e *extkit.CallEvent, in *RefundInput) error)
OnRefund binds fn to refund calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnResume
func OnResume(owner any, fn func(e *extkit.CallEvent, in *ItemRef) error)
OnResume binds fn to resume calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnRevoke
func OnRevoke(owner any, fn func(e *extkit.CallEvent, in *ItemRef) error)
OnRevoke binds fn to revoke calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnSync
func OnSync(owner any, fn func(e *extkit.CallEvent, in *ItemRef) error)
OnSync binds fn to sync calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnWebhook
func OnWebhook(owner any, fn func(e *extkit.CallEvent, in *extkit.RawIn) error)
OnWebhook binds fn to webhook calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
Types
Ack
type Ack struct {
Applied int `json:"applied"` // items written
}
Ack is a webhook receipt.
Billing
type Billing interface {
// Checkout starts a purchase of a product. Signed in, it's for the caller; signed out, it's pay-first when the
// app allows it: the purchase goes to the owner with the checkout email (or the one OnOwnerNeeded makes), and Claim
// lets the browser claim it.
//
//op: POST checkout scope=public
Checkout(ctx context.Context, a extkit.Auth, in CheckoutInput) (CheckoutResult, error)
// Pay serves the checkout page for processors whose checkout must run on a page of the app's.
//
//op: GET pay scope=public
Pay(ctx context.Context, a extkit.Auth, in PayInput) (extkit.RawOut, error)
// Portal links an owner to their processor's customer portal (cards, invoices), for one item or their latest.
//
//op: POST portal scope=public
Portal(ctx context.Context, a extkit.Auth, in PortalInput) (Link, error)
// Items lists an owner's items: the caller's own, or anyone's for a superuser.
//
//op: GET items scope=public
Items(ctx context.Context, a extkit.Auth, in OwnerRef) (ItemList, error)
// Entitlements sums what an owner's active items grant (instances = 5), with the items each unit comes from.
//
//op: GET entitlements scope=public
Entitlements(ctx context.Context, a extkit.Auth, in OwnerRef) (Entitlements, error)
// Cancel cancels a subscription now or at the end of its paid period.
//
//op: POST cancel scope=public
Cancel(ctx context.Context, a extkit.Auth, in CancelInput) (Item, error)
// Resume undoes a cancel scheduled for the end of the period.
//
//op: POST resume scope=public
Resume(ctx context.Context, a extkit.Auth, in ItemRef) (Item, error)
// Quantity changes how many units a subscription bills for.
//
//op: POST quantity scope=public
Quantity(ctx context.Context, a extkit.Auth, in QuantityInput) (Item, error)
// Plan moves a subscription to another product.
//
//op: POST plan scope=public
Plan(ctx context.Context, a extkit.Auth, in PlanInput) (Item, error)
// Webhook takes a processor's webhook call (?provider=stripe). Point each processor's webhook here.
//
//op: POST webhook scope=public
Webhook(ctx context.Context, a extkit.Auth, in extkit.RawIn) (Ack, error)
// Refund asks the item's processor to refund it (in full, or Amount). The item changes when the refund arrives.
//
//op: POST refund
Refund(ctx context.Context, a extkit.Auth, in RefundInput) (RefundResult, error)
// Grant gives an owner a manual item: units of a product with no processor (comps, migrations, support).
//
//op: POST grant
Grant(ctx context.Context, a extkit.Auth, in GrantInput) (Item, error)
// Revoke ends a manual item.
//
//op: POST revoke
Revoke(ctx context.Context, a extkit.Auth, in ItemRef) (Item, error)
// Sync re-reads one item from its processor and writes what it finds.
//
//op: POST sync
Sync(ctx context.Context, a extkit.Auth, in ItemRef) (Item, error)
// Reconcile re-reads every item that hasn't ended from its processor; DryRun reports what would change.
//
//op: POST reconcile
Reconcile(ctx context.Context, a extkit.Auth, in ReconcileInput) (ReconcileResult, error)
// Check looks up a product's price at each processor it names, so an admin can check the ids.
//
//op: POST check scope=billing:read
Check(ctx context.Context, a extkit.Auth, in ProductRef) (CheckResult, error)
// Processors lists the installed payment processors: which takes checkouts, whether each is set up, and the
// webhook URL to give it.
//
//op: GET processors scope=billing:read
Processors(ctx context.Context, a extkit.Auth) (ProcessorList, error)
}
Billing sells an app's products and keeps track of who bought what.
CancelInput
type CancelInput struct {
Item string `json:"item"`
AtPeriodEnd bool `json:"atPeriodEnd"`
}
CancelInput cancels a subscription.
CheckResult
type CheckResult struct {
Prices []PriceCheck `json:"prices"`
}
CheckResult is a product's price at each processor it names.
CheckoutInput
type CheckoutInput struct {
Product string `json:"product"` // a product key (`_billing_products`)
Quantity int `json:"quantity,omitempty"` // 0 means 1
Email string `json:"email,omitempty"` // signed out: prefill
Discount string `json:"discount,omitempty"` // a discount or promotion code
SuccessURL string `json:"successUrl,omitempty"` // default: billing's setting
CancelURL string `json:"cancelUrl,omitempty"` // default: billing's setting
// Server is what only the app's own Go code may set (it's trusted to decide trials and off-sale products); a
// checkout over the wire or from $billing never carries it.
Server CheckoutServer `json:"-"`
}
CheckoutInput starts a purchase.
CheckoutResult
type CheckoutResult struct {
URL string `json:"url"`
Processor string `json:"processor"`
Claim string `json:"claim,omitempty"` // signed out: keep it in the browser to claim the purchase
}
CheckoutResult is where to send the buyer.
CheckoutServer
type CheckoutServer struct {
TrialDays int // the first charge comes this many days after checkout; 0: charged at checkout
Metadata map[string]string // copied onto the purchase at the processor (Stripe: the subscription's metadata); billing's own keys win
AllowOffSalePurchase bool // the product may be bought while off sale (active false), such as a retired plan a customer keeps
}
CheckoutServer is a checkout's server-only options, such as moving a customer from another processor without charging them twice.
Client
type Client struct {
// contains filtered or unexported fields
}
Client is billing/v1 over HTTP, for the CLI and other apps. It implements Billing; the token it was made with is the credential, so the extkit.Auth argument is ignored.
NewClient
func NewClient(baseURL, token string, hc *http.Client) *Client
NewClient calls billing/v1 on the app at baseURL with token (a PocketBase auth token or an API token).
Client.Cancel
func (c *Client) Cancel(ctx context.Context, _ extkit.Auth, in CancelInput) (Item, error)
Client.Check
func (c *Client) Check(ctx context.Context, _ extkit.Auth, in ProductRef) (CheckResult, error)
Client.Checkout
func (c *Client) Checkout(ctx context.Context, _ extkit.Auth, in CheckoutInput) (CheckoutResult, error)
Client.Entitlements
func (c *Client) Entitlements(ctx context.Context, _ extkit.Auth, in OwnerRef) (Entitlements, error)
Client.Grant
func (c *Client) Grant(ctx context.Context, _ extkit.Auth, in GrantInput) (Item, error)
Client.Items
func (c *Client) Items(ctx context.Context, _ extkit.Auth, in OwnerRef) (ItemList, error)
Client.Pay
func (c *Client) Pay(ctx context.Context, _ extkit.Auth, in PayInput) (extkit.RawOut, error)
Client.Plan
func (c *Client) Plan(ctx context.Context, _ extkit.Auth, in PlanInput) (Item, error)
Client.Portal
func (c *Client) Portal(ctx context.Context, _ extkit.Auth, in PortalInput) (Link, error)
Client.Processors
func (c *Client) Processors(ctx context.Context, _ extkit.Auth) (ProcessorList, error)
Client.Quantity
func (c *Client) Quantity(ctx context.Context, _ extkit.Auth, in QuantityInput) (Item, error)
Client.Reconcile
func (c *Client) Reconcile(ctx context.Context, _ extkit.Auth, in ReconcileInput) (ReconcileResult, error)
Client.Refund
func (c *Client) Refund(ctx context.Context, _ extkit.Auth, in RefundInput) (RefundResult, error)
Client.Resume
func (c *Client) Resume(ctx context.Context, _ extkit.Auth, in ItemRef) (Item, error)
Client.Revoke
func (c *Client) Revoke(ctx context.Context, _ extkit.Auth, in ItemRef) (Item, error)
Client.Sync
func (c *Client) Sync(ctx context.Context, _ extkit.Auth, in ItemRef) (Item, error)
Client.Webhook
func (c *Client) Webhook(ctx context.Context, _ extkit.Auth, in extkit.RawIn) (Ack, error)
EntitlementPart
type EntitlementPart struct {
Name string `json:"name"`
Amount int `json:"amount"`
Item string `json:"item"`
}
EntitlementPart is one item's share of one entitlement.
Entitlements
type Entitlements struct {
Totals map[string]int `json:"totals"` // instances: 5
Sources []EntitlementPart `json:"sources"` // where each total comes from
}
Entitlements is what an owner's active items grant.
GrantInput
type GrantInput struct {
OwnerCollection string `json:"ownerCollection,omitempty"`
Owner string `json:"owner"`
Product string `json:"product"`
Quantity int `json:"quantity"`
EndsAt *time.Time `json:"endsAt,omitempty"`
Note string `json:"note,omitempty"`
}
GrantInput gives an owner a manual item.
GuestEvent
type GuestEvent struct {
hook.Event
App core.App
Item Item
Checkout string // the checkout's id (its record in the provider's checkouts), whose claim the browser holds
Email string // the checkout email
Created bool // the owner was created for this purchase (by an OnOwnerNeeded handler)
}
GuestEvent is raised when a signed-out purchase found or created its owner, so the app can send its claim email.
Item
type Item struct {
ID string `json:"id"`
OwnerCollection string `json:"ownerCollection"`
Owner string `json:"owner"`
Processor string `json:"processor"` // payments/v1 key; "" for manual
Kind string `json:"kind"` // KindSubscription, KindOrder, KindManual
ExternalID string `json:"externalId"`
Customer string `json:"customer,omitempty"` // the processor's customer id
Product string `json:"product"`
Quantity int `json:"quantity"`
Status string `json:"status"` // payments/v1's statuses; manual: active or ended
Active bool `json:"active"` // counts toward entitlements now
RenewsAt *time.Time `json:"renewsAt,omitempty"`
EndsAt *time.Time `json:"endsAt,omitempty"`
Note string `json:"note,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
Item is one subscription, order or manual grant.
ItemChange
type ItemChange struct {
Item string `json:"item"`
Before string `json:"before"` // status quantity
After string `json:"after"`
}
ItemChange is one item a reconcile changed (or would).
ItemEvent
type ItemEvent struct {
hook.Event
App core.App
Before *Item // nil for a new item
After Item //
EntitlementsBefore map[string]int // the owner's totals before and after
EntitlementsAfter map[string]int //
Source string // webhook, action, grant, reconcile
EventKind string // payments/v1 event kind, for a webhook
}
ItemEvent is raised after an item is written: a webhook, an action, a grant, a reconcile.
ItemList
type ItemList struct {
Items []Item `json:"items"`
}
ItemList is an owner's items, newest first.
ItemRef
type ItemRef struct {
Item string `json:"item"`
}
ItemRef names an item (its record id).
Link
type Link struct {
URL string `json:"url"`
}
Link is a URL.
OwnerEvent
type OwnerEvent struct {
hook.Event
App core.App // the purchase's transaction
Collection *core.Collection // the owner collection (Settings' ownerCollection)
Email string // the checkout email
Checkout string // the checkout's id
Owner string // set by the handler: the new owner's id
}
OwnerEvent is raised inside the purchase's transaction when a signed-out purchase's email matches no owner. The app decides what a new buyer's account is: a handler that makes one creates it with App (the transaction, so it commits with the purchase) and sets Owner to its id. With no Owner the purchase waits for an owner with that email. An error fails the webhook, so the processor sends it again.
OwnerRef
type OwnerRef struct {
Collection string `json:"collection,omitempty"`
Owner string `json:"owner,omitempty"`
}
OwnerRef names an owner (an auth record); empty means the caller.
PayInput
type PayInput struct {
Checkout string `json:"checkout"`
}
PayInput names a checkout whose page to serve.
PlanInput
type PlanInput struct {
Item string `json:"item"`
Product string `json:"product"`
Proration string `json:"proration,omitempty"`
}
PlanInput moves a subscription to another product.
PortalInput
type PortalInput struct {
Item string `json:"item,omitempty"`
ReturnURL string `json:"returnUrl,omitempty"`
}
PortalInput picks the item whose customer portal to open ("" = the owner's latest).
PriceCheck
type PriceCheck struct {
Processor string `json:"processor"`
Price string `json:"price"`
OK bool `json:"ok"`
Name string `json:"name,omitempty"`
Recurring bool `json:"recurring"`
Amount int64 `json:"amount"`
Currency string `json:"currency,omitempty"`
Message string `json:"message,omitempty"`
}
PriceCheck is one processor's answer.
ProcessorInfo
type ProcessorInfo struct {
Name string `json:"name"`
Title string `json:"title"`
MerchantOfRecord bool `json:"merchantOfRecord"`
Sandbox bool `json:"sandbox"`
Configured bool `json:"configured"`
WebhookURL string `json:"webhookUrl"`
}
ProcessorInfo is one installed processor.
ProcessorList
type ProcessorList struct {
Checkout string `json:"checkout"` // the one that takes new checkouts
Processors []ProcessorInfo `json:"processors"`
}
ProcessorList is the installed payment processors.
ProductRef
type ProductRef struct {
Product string `json:"product"`
}
ProductRef names a product key.
QuantityInput
type QuantityInput struct {
Item string `json:"item"`
Quantity int `json:"quantity"`
Proration string `json:"proration,omitempty"` // payments/v1's; default: billing's setting
}
QuantityInput changes a subscription's quantity.
ReconcileErr
type ReconcileErr struct {
Item string `json:"item"`
Error string `json:"error"`
}
ReconcileErr is an item a reconcile couldn't read.
ReconcileInput
type ReconcileInput struct {
DryRun bool `json:"dryRun"`
}
ReconcileInput runs a reconcile.
ReconcileResult
type ReconcileResult struct {
Checked int `json:"checked"`
Changed []ItemChange `json:"changed"`
Errors []ReconcileErr `json:"errors,omitempty"`
}
ReconcileResult is what a reconcile found.
RefundInput
type RefundInput struct {
Item string `json:"item"`
Amount int64 `json:"amount,omitempty"` // minor units; 0 = in full
Currency string `json:"currency,omitempty"`
Reason string `json:"reason,omitempty"`
}
RefundInput refunds an item.
RefundResult
type RefundResult struct {
ID string `json:"id"`
Status string `json:"status"` // pending (the processor approves it later) or done
}
RefundResult is the refund's state at the processor.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.