Subscription Architecture
Create a Subscription Plan
Plans define the pricing, billing interval, and trial period. Create them once and reuse for all subscribers.Plan Intervals
| Interval | Billing Frequency |
|---|---|
daily | Every day |
weekly | Every 7 days |
monthly | Every calendar month |
yearly | Every 12 months |
Trial Periods
Settrial_days to give customers free access before the first charge:
trialing. No charges are made. When the trial ends, the first payment is created automatically.
Subscribe a Customer
Handle Subscription Webhooks
Subscription lifecycle events are delivered via webhooks. Set up handlers for each event to keep your system in sync.- Next.js
- Express
app/api/webhooks/zendfi/route.ts
Subscription Lifecycle
Status Reference
| Status | Description |
|---|---|
trialing | Customer is in a free trial period |
active | Subscription is active with a valid payment |
past_due | Most recent payment failed, retries pending |
cancelled | Subscription has been cancelled |
Cancellation
Cancel immediately
Cancel at period end
To let the customer keep access until the end of their current billing period, handle this in your application logic:Access Control Middleware
Gate features based on subscription status:- Next.js Middleware
- Express Middleware
middleware.ts
Pricing Page Example
Build a pricing page that links to subscription checkout:Testing
zfi_test_ key) to simulate the full subscription lifecycle without real charges. Test keys work against Solana Devnet where transactions are free.