Payments
Payments
The payment module uses a shared paymentService contract with either Creem or
Stripe selected during generation. Product pages and credit logic consume
normalized checkout, subscription, and webhook events.
Confirm the selection
Check adapters.payment in nextdevtpl.generated.json:
| Selection | Variables | Signature header |
|---|---|---|
payment:creem | CREEM_API_KEY, CREEM_WEBHOOK_SECRET | creem-signature |
payment:stripe | STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET | stripe-signature |
Both use the shared endpoint:
https://your-domain.com/api/webhooks/payment
Main code
| Path | Purpose |
|---|---|
src/core/services/payment.ts | Shared payment types and capabilities |
src/adapters/payment | Creem or Stripe implementation |
src/services/payment.ts | Selected payment instance |
src/features/payment/actions.ts | Checkout Server Actions |
src/app/api/webhooks/payment/route.ts | Shared signature and event handling |
src/config/payment.ts | Products and price IDs |
src/config/subscription-plan.ts | Plan allowances |
Production steps
- Create products and prices in the provider dashboard.
- Add price IDs to
NEXT_PUBLIC_PRICE_*variables and plan configuration. - Configure the API key and webhook secret.
- Point the webhook to
/api/webhooks/payment. - Test subscription, cancellation, renewal, and one-time payment flows.
- Confirm duplicate webhooks do not grant credits twice.
pnpm test:run -- src/test/adapters/payment.test.ts
pnpm test:run -- src/test/payment
See Credits for ledger behavior and Service Adapters for provider replacement.