basalt / subscriptions/src / RecurringReferenceBilling
Class: RecurringReferenceBilling
Defined in: subscriptions/src/recurring.ts:115
Coordinates reference-per-period recurring billing over a PaymentGateway. Stateful pieces are pluggable (store, ledger) so you can back them with a database; the defaults are in-memory.
Constructors
Constructor
> new RecurringReferenceBilling(options): RecurringReferenceBilling
Defined in: subscriptions/src/recurring.ts:123
Parameters
options
Returns
RecurringReferenceBilling
Methods
cancel()
> cancel(billableId): Promise<void>
Defined in: subscriptions/src/recurring.ts:232
Parameters
billableId
string
Returns
Promise<void>
due()
> due(now?): Promise<RecurringSubscription[]>
Defined in: subscriptions/src/recurring.ts:222
Subscriptions that need their next reference issued now: not canceled, nothing outstanding, and within leadDays of the paid-through date (or never paid). Run this on a schedule and call issueNext() for each.
Parameters
now?
number = ...
Returns
Promise<RecurringSubscription[]>
get()
> get(billableId): Promise<RecurringSubscription | undefined>
Defined in: subscriptions/src/recurring.ts:132
Parameters
billableId
string
Returns
Promise<RecurringSubscription | undefined>
handleEvent()
> handleEvent(event): Promise<HandleEventResult>
Defined in: subscriptions/src/recurring.ts:194
Feed a verified PaymentEvent. Applies it once (via the ledger's idempotency): on success for the outstanding reference, extends paidThrough by one interval and marks the subscription active; on failure, marks it past_due.
Parameters
event
Returns
Promise<HandleEventResult>
issueNext()
> issueNext(billableId, metadata?): Promise<PaymentInstruction>
Defined in: subscriptions/src/recurring.ts:160
Issue the next period's reference for a subscription (call for the ones due() returns, or to re-collect after a lapse). Replaces any outstanding reference as the one now awaited.
Parameters
billableId
string
metadata?
Record<string, string>
Returns
Promise<PaymentInstruction>
subscribe()
> subscribe(input): Promise<{ instruction: PaymentInstruction; subscription: RecurringSubscription; }>
Defined in: subscriptions/src/recurring.ts:137
Start a subscription and issue the first period's reference.
Parameters
input
Returns
Promise<{ instruction: PaymentInstruction; subscription: RecurringSubscription; }>