basalt / subscriptions/src / Coupons
Class: Coupons
Defined in: subscriptions/src/coupon.ts:160
A registry of coupons: define, look up, quote a discount and redeem.
Constructors
Constructor
> new Coupons(options?): Coupons
Defined in: subscriptions/src/coupon.ts:164
Parameters
options?
CouponsOptions = {}
Returns
Coupons
Methods
define()
> define(coupon): Promise<CouponRecord>
Defined in: subscriptions/src/coupon.ts:170
Validate and persist a coupon. Throws CouponInvalidError on a bad shape.
Parameters
coupon
Returns
Promise<CouponRecord>
get()
> get(code): Promise<CouponRecord | null>
Defined in: subscriptions/src/coupon.ts:177
Parameters
code
string
Returns
Promise<CouponRecord | null>
list()
> list(): Promise<CouponRecord[]>
Defined in: subscriptions/src/coupon.ts:180
Returns
Promise<CouponRecord[]>
quote()
> quote(code, subtotalMinor, currency): Promise<{ coupon: CouponRecord; discount: number; }>
Defined in: subscriptions/src/coupon.ts:190
Compute the discount a coupon code yields on a subtotal, validating that it exists and is redeemable. Throws CouponNotFoundError / CouponNotRedeemableError. Does not consume a redemption — call redeem() once the charge succeeds.
Parameters
code
string
subtotalMinor
number
currency
string
Returns
Promise<{ coupon: CouponRecord; discount: number; }>
redeem()
> redeem(code): Promise<CouponRecord>
Defined in: subscriptions/src/coupon.ts:215
Record a successful redemption (increments the counter). Enforces the coupon's rules at the moment of redemption — not only in quote(), whose answer can be stale by the time the charge succeeds: an expired coupon (redeemBy) or one whose maxRedemptions is reached throws CouponNotRedeemableError, and the cap is checked-and-incremented atomically by the store.
Parameters
code
string
Returns
Promise<CouponRecord>