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
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
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.