2.0 KiB
2.0 KiB
settlekit-subscription-lifecycle
A runnable TypeScript walkthrough of the full recurring-billing lifecycle
using @settlekit/sdk:
- create a customer, a product, and a recurring (monthly) price
- subscribe — an entitlement is granted for the product automatically
- verify access — the SDK hot path (
entitlements.verify) - a payment fails → open a dunning campaign, record a failed attempt, then recover it
- cancel the subscription
It exercises the customers, products, subscriptions, entitlements, and
dunning resources end to end against a live SettleKit API.
Run it
First build the SDK (the example imports its compiled output by relative path —
see src/sdk.ts):
pnpm --filter @settlekit/sdk build
Start a SettleKit API locally with a bootstrap key (no database required — it
runs in-memory when DATABASE_URL is unset):
# from the repo root
pnpm --filter @settlekit/api build
API_BOOTSTRAP_KEY=sk_dev PORT=8787 node apps/api/dist/server.js
Then, in this directory:
npm install
SETTLEKIT_API_URL=http://localhost:8787 \
SETTLEKIT_API_KEY=sk_dev \
SETTLEKIT_ORG_ID=org_demo \
npm run dev
Expected output ends with ✓ Subscription lifecycle complete.
Configuration
| Env var | Default | Notes |
|---|---|---|
SETTLEKIT_API_URL |
http://localhost:8787 |
API base URL |
SETTLEKIT_API_KEY |
— (required) | Bearer key; locally use API_BOOTSTRAP_KEY |
SETTLEKIT_ORG_ID |
org_demo |
Organization the entities belong to |
Where to look
src/main.ts— the five-step walkthrough.src/sdk.ts— local re-export of@settlekit/sdk; swap to the published package by changing one import.