Overview
After a customer completes checkout, the SDK provides helpers to manage the full purchase lifecycle:- Cancel renewal — stop auto-renewal; access continues until the period ends
- Reactivate renewal — undo a pending cancellation while still in the active period
- Activate plan — activate a product for a customer on a specific plan without checkout (free units or credit balance)
- Plan switching — activating a different plan automatically expires the current purchase and creates a new one
Request object and a body, get back either a data object or a NextResponse error.
Cancel renewal
Cancels auto-renewal on a purchase. The customer keeps access until the current billing period ends.| Parameter | Type | Required | Description |
|---|---|---|---|
purchaseRef | string | Yes | The purchase reference to cancel |
reason | string | No | Optional cancellation reason |
active with cancelledAt set. When the billing period ends, the purchase transitions to expired.
Reactivate renewal
Undoes a pending cancellation, restoring auto-renewal. Only works while the purchase is still active (before the period ends).| Parameter | Type | Required | Description |
|---|---|---|---|
purchaseRef | string | Yes | The purchase reference to reactivate |
- Purchase status must be
active cancelledAtmust be set (cancellation is pending)endDatemust not have passed
cancelledAt is cleared and autoRenew is restored. A purchase.updated webhook fires.
Activate plan
Activates a product for a customer on a specific plan without going through checkout. Useful for free plans, credit-based activation, or programmatic plan assignment.| Parameter | Type | Required | Description |
|---|---|---|---|
productRef | string | Yes | The product to activate |
planRef | string | Yes | The plan to activate on |
Response statuses
| Status | Meaning |
|---|---|
activated | Purchase created successfully |
already_active | Customer already has an active purchase on this plan |
topup_required | Customer needs more credits — response includes creditBalance and creditsPerUnit |
payment_required | Plan requires payment — response includes checkoutUrl and checkoutSessionId |
invalid | Invalid product or plan reference |
Plan switching
When a customer already has an active purchase on a product and you callactivatePlan with a different planRef, the SDK automatically:
- Expires the existing purchase (fires
purchase.expiredwebhook) - Creates a new purchase on the requested plan (fires
purchase.createdwebhook)
activatePlan handles the switch.
Complete Next.js example
Next steps
- Webhooks — handle
purchase.updated,purchase.expired, andpurchase.createdevents from lifecycle changes - Billing — understand billing cycles, renewal processing, and purchase states
- Next.js guide — full Next.js integration walkthrough