Payments Overview
How Nebutra's billing system works — Creem for global card payments, plan sync, and quota enforcement.
Providers
Per ADR 2026-09-26, the payments pair is:
- Creem — cards, worldwide, merchant of record (it collects and remits sales tax/VAT itself). This is the current rail for one-time card checkout. See Creem integration.
- WeChat Pay / Alipay — mainland China.
Subscriptions still run on Stripe today (legacy) — the plan-sync architecture described below. Stripe is retired from new work; nothing new is built on it. When subscriptions move, they become Creem subscriptions (subscription.* events) through the same payment-order and fulfillment seams. See Stripe integration for what still depends on it.
Architecture (subscriptions, Stripe — legacy)
Nebutra's subscription billing pipeline is built on three layers that work together to gate access by plan and enforce usage quotas in real time.
User
└─▶ Stripe Checkout
└─▶ Stripe sends webhook
└─▶ /api/webhooks/stripe
└─▶ DB plan updated (tenant record)
└─▶ @nebutra/metering enforces quotasAll billing integration code (Creem, Stripe, WeChat Pay/Alipay) lives in packages/commerce/billing/. Application code calls helpers from @nebutra/billing — it never touches a provider SDK directly.
Plans
FREE
$0 / month
- 1,000 API calls / month
- 1 organization member
- Community support
PRO
$29 / month
- 100,000 API calls / month
- 10 organization members
- Email support
- All features unlocked
ENTERPRISE
Custom pricing
- Unlimited API calls
- Unlimited members
- SSO / SAML
- SLA guarantee
- Custom contract
How plan sync works (subscriptions, Stripe — legacy)
The user is redirected to a Stripe-hosted checkout page. On success, Stripe fires a checkout.session.completed event.
The API gateway endpoint POST /api/webhooks/stripe (backends/gateway/src/routes/webhooks/stripe.ts) receives the event, verifies the signature using STRIPE_WEBHOOK_SECRET, and dispatches it to the matching handler inline.
The handler updates the tenant's plan and planExpiresAt columns in the database, synchronizing the Stripe subscription state.
On every subsequent API request, @nebutra/metering reads the tenant's current plan limits from the database and compares them against accumulated ClickHouse usage. Requests over quota receive a 429 Too Many Requests response.
How one-time card checkout works (Creem — current)
A one-time card purchase (e.g. credits, an add-on) opens the shared Creem product with custom_price set to that offer's price. The order id travels as request_id.
POST /api/webhooks/creem verifies the creem-signature header (hex HMAC-SHA256 of the raw body under CREEM_WEBHOOK_SECRET) and looks for checkout.completed.
The order's pre-tax amount (Creem adds tax on top as merchant of record) is compared against the locked offer price, and the payment order is settled.
GET /v1/checkouts?checkout_id=… lets a reconciliation job check a pending checkout directly, so a dropped webhook costs minutes, not a sale.
Where provider config lives
| Location | Purpose |
|---|---|
packages/commerce/billing/src/creem/index.ts | Creem client — checkout, reconcile, refund, webhook signature |
packages/commerce/billing/src/stripe/ | Stripe client, customers, checkout/billing-portal sessions (legacy — subscriptions) |
packages/commerce/billing/src/config/plan-config.ts | Database-driven plan configuration (PlanConfig, limits, features) |
packages/commerce/billing/src/entitlements/ | Plan-based feature entitlements (FEATURES, PLAN_FEATURES, checkEntitlement) |
backends/gateway/src/routes/webhooks/stripe.ts | Stripe webhook handler (inline Hono route, not a re-exported helper) |
backends/gateway/src/routes/webhooks/creem.ts | Creem webhook handler |
packages/commerce/billing/src/checkout/ | Checkout session creation helpers (Stripe, Creem, ChinaPay, manual) |
packages/commerce/billing/src/orders/ | Payment orders — offer → order → fulfillment (ADR 2026-09-25) |
Environment variables
Set the following in your .env file (or your deployment platform's secret manager):
# Creem — the current card rail (merchant of record)
CREEM_API_KEY=creem_xxxxxxxxxxxxxxxxxxxx
CREEM_PRODUCT_ID=prod_xxxxxxxxxxxxxxxxxxxx
CREEM_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxx
CREEM_TEST_MODE=true # points at test-api.creem.io
# Stripe (legacy) — use sk_test_ in development, sk_live_ in production.
# Only feeds subscriptions, the billing portal, and pre-switch checkouts.
STRIPE_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxx
# Webhook signing secret — obtained from the Stripe Dashboard or Stripe CLI
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxx
# Publishable key for the frontend (safe to expose)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxxxxxxxxxxx
# Price IDs for each paid plan (from Stripe Dashboard → Products → Prices)
STRIPE_PRICE_ID_PRO_MONTHLY=price_xxxxxxxxxxxxxxxxxxxx
STRIPE_PRICE_ID_PRO_YEARLY=price_xxxxxxxxxxxxxxxxxxxx
STRIPE_PRICE_ID_ENTERPRISE_MONTHLY=price_xxxxxxxxxxxxxxxxxxxx
STRIPE_PRICE_ID_ENTERPRISE_YEARLY=price_xxxxxxxxxxxxxxxxxxxxNever commit real Creem or Stripe keys to source control. Use .env.local locally and inject secrets through your CI/CD environment for production deployments.
Stripe Dashboard setup (legacy — subscriptions)
Sign up at stripe.com and activate your account.
Go to Stripe Dashboard → Products → Add product. Create one product for PRO ($29/month recurring) and one for ENTERPRISE (custom). Copy the Price IDs into your environment variables.
Go to Developers → Webhooks → Add endpoint. Set the URL to https://api.yourdomain.com/api/webhooks/stripe and select the events listed in the Webhooks page.
After creating the endpoint, reveal and copy the Signing secret (whsec_...) into STRIPE_WEBHOOK_SECRET.
During local development, use the Stripe CLI to forward live events to your local server instead of setting up a public endpoint.
Related
How is this guide?
Last updated on