Overview
The Subscription API enables recurring billing with automatic payment collection. You can create plans, manage subscriptions, and handle the complete subscription lifecycle from initiation to cancellation.
Subscription Lifecycle
Code
Key Concepts
- Plan: Defines the amount, currency, and billing interval
- Subscription: A customer's recurring billing agreement
- Invoice: Generated automatically per billing cycle
- Payment Intent: Embedded in invoices for payment collection
Quick Start
Step 1: Create a Plan
Code
Step 2: Initiate a Subscription
Code
Step 3: Process Payment
Code
API Reference
Plan Management
Create Plan
POST /api/subscription/plans
Code
List Plans
GET /api/subscription/plans?limit=10&after=plan_xxx
Get Plan
GET /api/subscription/plans/{planId}
Subscription Management
Initiate Subscription
POST /api/subscription/initiate
Code
Process Subscription Payment
POST /api/subscription/process-payment
Code
Get Subscription
GET /api/subscription/{subscriptionId}
List Subscriptions
GET /api/subscription?status=active&limit=10
Update Plan
PATCH /api/subscription/{subscriptionId}/plan
Code
Update Payment Method
PATCH /api/subscription/{subscriptionId}/payment-method
Code
Cancel Subscription
DELETE /api/subscription/{subscriptionId}?reason=requested_by_customer
SDK Reference
SubscriptionResource
| Method | Description |
|---|---|
initiate(options) | Start subscription with payment setup |
processPayment(options) | Process the initial payment |
getSession(sessionToken) | Get subscription session details |
get(subscriptionId) | Get subscription details |
list(query?) | List subscriptions with filters |
updatePlan(subscriptionId, dto) | Change plan (next cycle) |
updatePaymentMethod(subscriptionId, dto) | Update payment method |
cancel(subscriptionId, reason?) | Cancel subscription |
createPlan(data) | Create a subscription plan |
listPlans(query?) | List plans |
getPlan(planId) | Get plan details |
Subscription Statuses
| Status | Description |
|---|---|
incomplete | Initial status; first payment must succeed |
incomplete_cancelled | Auto-cancelled after 24 hours if unpaid |
active | All invoices paid successfully |
past_due | Latest invoice payment failed; auto-retried |
unpaid | Invoice failed after 3 retries |
cancelled | Subscription manually cancelled |
Webhook Events
Handle these subscription webhook events:
| Event | Action |
|---|---|
subscription.activated | Mark subscription as active |
subscription.past_due | Notify customer of failed payment |
subscription.unpaid | Suspend service |
subscription.cancelled | Clean up resources |
subscription.invoice.paid | Log successful payment |
subscription.invoice.payment_failed | Log failure, notify customer |
Best Practices
- Plan changes take effect on the next billing cycle
- Implement webhook handlers for real-time status updates
- Use
getSession()to retrieve payment details for frontend - Handle
past_duestatus with retry notifications - Store subscription IDs for customer account management
Related Guides:
- Webhooks Guide - For subscription event handling
- Plans SDK - For plan management details
Last modified on
