Guides
Subscriptions
Manage the full subscription lifecycle including creation, pausing, cancellation, and plan changes.
Subscription Management
Subscriptions link customers to plans and manage the billing lifecycle automatically.
Subscription Lifecycle
TRIALING → ACTIVE → PAUSED → ACTIVE → CANCELED
→ PAST_DUE → ACTIVE (after retry)
→ CANCELED (after max retries)
Create a Subscription
curl -X POST http://localhost:3000/api/subscriptions \
-H "Authorization: Bearer sk_live_a1b2c3d4..." \
-H "Content-Type: application/json" \
-d '{
"customerId": "cust_x1y2z3",
"planId": "plan_abc123",
"currency": "UGX"
}'
import { NovaBillingClient } from 'novabilling';
const client = new NovaBillingClient({ token: 'sk_live_a1b2c3d4...' });
const subscription = await client.subscriptions.create({
customerId: 'cust_x1y2z3',
planId: 'plan_abc123',
currency: 'UGX'
});
console.log(subscription.id); // sub_...
console.log(subscription.status); // "ACTIVE"
from novabilling import NovaBilling
client = NovaBilling(token="sk_live_a1b2c3d4...")
subscription = client.subscriptions.create(
customer_id="cust_x1y2z3",
plan_id="plan_abc123",
currency="UGX"
)
print(subscription.id) # sub_...
print(subscription.status) # "ACTIVE"
List Subscriptions
curl -X GET "http://localhost:3000/api/subscriptions?status=ACTIVE&page=1&limit=20" \
-H "Authorization: Bearer sk_live_a1b2c3d4..."
// List all active subscriptions
const subs = await client.subscriptions.list({
status: 'ACTIVE',
page: 1,
limit: 20
});
// Filter by customer
const customerSubs = await client.subscriptions.list({
customerId: 'cust_x1y2z3'
});
subs = client.subscriptions.list(status="ACTIVE", page=1, limit=20)
customer_subs = client.subscriptions.list(customer_id="cust_x1y2z3")
Cancel a Subscription
curl -X POST http://localhost:3000/api/subscriptions/sub_j3k4l5/cancel \
-H "Authorization: Bearer sk_live_a1b2c3d4..." \
-H "Content-Type: application/json" \
-d '{
"cancelAt": "period_end"
}'
const canceled = await client.subscriptions.cancel('sub_j3k4l5', {
reason: 'Customer requested cancellation',
cancelAt: 'period_end' // Don't cancel immediately
});
canceled = client.subscriptions.cancel(
"sub_j3k4l5",
reason="Customer requested cancellation",
cancel_at="period_end"
)
Pause and Resume
Pause a Subscription
curl -X POST http://localhost:3000/api/subscriptions/sub_j3k4l5/pause \
-H "Authorization: Bearer sk_live_a1b2c3d4..."
await client.subscriptions.pause('sub_j3k4l5');
client.subscriptions.pause("sub_j3k4l5")
Resume a Subscription
curl -X POST http://localhost:3000/api/subscriptions/sub_j3k4l5/resume \
-H "Authorization: Bearer sk_live_a1b2c3d4..."
await client.subscriptions.resume('sub_j3k4l5');
client.subscriptions.resume("sub_j3k4l5")
Change Plan
curl -X POST http://localhost:3000/api/subscriptions/sub_j3k4l5/change-plan \
-H "Authorization: Bearer sk_live_a1b2c3d4..." \
-H "Content-Type: application/json" \
-d '{
"newPlanId": "plan_premium",
"prorate": true
}'
const updated = await client.subscriptions.changePlan('sub_j3k4l5', {
newPlanId: 'plan_premium',
prorate: true
});
updated = client.subscriptions.change_plan(
"sub_j3k4l5",
new_plan_id="plan_premium",
prorate=True
)
Subscription Statuses
| Status | Description |
|---|---|
TRIALING | Customer is in a free trial period |
ACTIVE | Subscription is active and billing normally |
PAST_DUE | Payment failed, retrying automatically |
PAUSED | Subscription is temporarily paused |
CANCELED | Subscription has been canceled |