Stripe Billing
accounts.svc.plus is the server-side owner of Stripe billing.
It now provides:
POST /api/auth/stripe/checkoutPOST /api/auth/stripe/portalPOST /api/billing/stripe/webhook
Required Environment Variables
Set these before starting the service:
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx
STRIPE_ALLOWED_PRICE_IDS=price_xstream_paygo,price_xstream_subscription
STRIPE_ALLOWED_PRICE_IDS is optional but recommended. When set, the checkout endpoint rejects any price_id that is not explicitly allowed.
Create Sandbox Stripe Secrets
Use the Stripe Dashboard in Sandbox/Test mode. Sandbox API keys and live
API keys are separate; use only sk_test_... for UAT and keep it on the
server. Stripe's API key page is Developers → API keys.
STRIPE_SECRET_KEY
- Open the Sandbox API keys page.
- In Standard keys, find Secret key and choose Reveal test key.
- Copy the value beginning with
sk_test_into the environment-specific Vault field. Do not copy apk_test_publishable key; this service calls Stripe server-side and needs the secret key.
STRIPE_WEBHOOK_SECRET
- Open Stripe Webhooks while Sandbox/Test mode is selected.
- Create or open the endpoint for the deployed Accounts service:
https://accounts-<env>.onwalk.net/api/billing/stripe/webhook. - Subscribe to the events listed in Webhook Notes, then open Signing secret and choose Reveal.
- Copy the value beginning with
whsec_into Vault. This is not the same as the API secret key and not the local Stripe CLI secret.
For local development, stripe listen --forward-to ... prints a temporary
whsec_...; use that only for the local process. The deployed UAT endpoint
must use the signing secret belonging to the Dashboard endpoint itself.
Production / Live mode
Production uses a separate Stripe mode and a separate pair of secrets:
- Switch the Stripe Dashboard from Sandbox/Test mode to Live mode.
- On the Live API keys page, reveal
the production Secret key and copy the value beginning with
sk_live_. - On Live Webhooks, create or open the production Accounts endpoint and subscribe to the same billing events.
- Reveal that endpoint's Signing secret and copy the value beginning with
whsec_. It is different from the Sandbox endpoint secret, even when the endpoint path is the same. - Store both values under the production Vault fields below, then deploy or restart Accounts so the runtime mapping takes effect.
Do not copy sk_test_... or the Sandbox whsec_... into production. A
production webhook endpoint must use its own Live-mode signing secret. The
local Stripe CLI whsec_... remains local-only in both modes.
Vault mapping
Use separate Sandbox and production fields so a mode switch cannot silently mix credentials:
kv/uat/billing-service/SANDBOX_STRIPE_SECRET_KEY -> STRIPE_SECRET_KEY
kv/uat/billing-service/SANDBOX_STRIPE_WEBHOOK_SECRET -> STRIPE_WEBHOOK_SECRET
kv/prod/billing-service/PROD_STRIPE_SECRET_KEY -> STRIPE_SECRET_KEY
kv/prod/billing-service/PROD_STRIPE_WEBHOOK_SECRET -> STRIPE_WEBHOOK_SECRET
The deployment layer performs this mapping; do not rename the runtime variables in the Accounts service.
Local Test Mode Runbook
- Start the account service with Stripe test-mode credentials.
- Expose the service so Stripe webhooks can reach it, or use the Stripe CLI:
stripe listen --forward-to http://127.0.0.1:8080/api/billing/stripe/webhook
- Copy the webhook secret printed by Stripe CLI into
STRIPE_WEBHOOK_SECRET. - Restart
accounts.svc.plus. - Sign in through the console and start a checkout flow from a plan published by the Accounts billing catalog.
- Complete the payment with Stripe test card data.
- Verify:
- checkout redirects back to the console
- webhook delivery succeeds
GET /api/auth/subscriptionscontains aprovider = striperecord- Stripe portal opens for the same user
Webhook Notes
The webhook currently handles these events:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.paidinvoice.payment_failedcharge.refunded
The webhook is the authoritative source for Stripe subscription status in the local subscriptions store.
Operational Notes
- Keep Stripe secret values server-side only.
- Use test mode until the complete flow is verified end to end.
- If checkout succeeds but no subscription record appears, inspect webhook delivery first.