A minimal Bun + TypeScript example demonstrating how to create a Pocketsflow Checkout Session for a subscription product using the Pocketsflow API.
- Bun + TypeScript
- Hosted Checkout Session
- Subscription product support
- Environment variable configuration
- Simple, production-ready structure
- Bun v1.3+
- A Pocketsflow account
- A Subscription Product created in the Pocketsflow Dashboard
- Your Pocketsflow Secret API Key
Install dependencies:
bun installCreate a .env file in the project root.
POCKETSFLOW_SECRET_KEY=your_secret_api_keyUpdate the following values inside src/index.ts:
productId: "YOUR_PRODUCT_ID",
successUrl: "https://yourdomain.com/success",
cancelUrl: "https://yourdomain.com/cancel",Run the project:
bun run src/index.tsor
bun src/index.ts{
"id": "cs_xxxxxxxxxxxxxxxxx",
"url": "https://checkout.pocketsflow.com/checkout?subscriptionId=..."
}Redirect your customer to the returned url to start the checkout flow.
.
├── src
│ ├── index.ts
│ ├── pocketsflow.ts
│ └── types.ts
├── .env
├── package.json
└── tsconfig.json
Customer
│
▼
Create Checkout Session
│
▼
Receive Checkout URL
│
▼
Redirect Customer
│
▼
Hosted Pocketsflow Checkout
│
▼
Successful Payment
│
├── Redirect to Success URL
└── Send Webhook to Your Backend
In a production application, you should:
- Redirect users to the returned checkout URL.
- Listen for Pocketsflow webhook events.
- Update your database when a subscription becomes active.
- Grant or revoke access based on the subscription status.