Legacy Providers and Webhooks
Keep provider credentials and webhook handling inside BillStack.
Legacy (v1) API. This page describes the Stripe-first legacy API. It stays supported for existing integrations but is frozen: new features ship only in v2. Prefer v2 for new work: Connect test and live accounts.
The routes on this page describe legacy v1 provider configuration and webhooks. v2 uses team-scoped provider connections (one account per payment provider), project-scoped bindings, regions (a provider connection plus the countries it serves), and explicit country confirmation; v2 does not silently fall back between providers. See Multi-provider v2 and the v2 API reference.
Legacy v1 owns provider configuration at the team and project level.
Provider credentials
Configure provider credentials in BillStack, not in product apps.
For Stripe, BillStack needs the connected Stripe credentials and webhook configuration.
For Razorpay, BillStack needs usable API credentials, webhook secret, plan IDs for subscription flows, and amount mappings for payment-link flows when applicable.
Webhook endpoint
BillStack provides a per-team webhook endpoint:
https://billing.w3dev.app/api/webhooks/stripe/{teamId}This URL is your live endpoint and has not changed: register it in Stripe's live mode and it accepts live-mode events only. Your Stripe account's test mode has its own endpoint:
https://billing.w3dev.app/api/webhooks/stripe/{teamId}/testRegister that URL in Stripe's test mode. It uses its own signing secret and accepts test-mode events only. An event delivered to the wrong URL (a test-mode event sent to the live endpoint, or the reverse) is rejected with 400 and code: "LIVEMODE_MISMATCH", recorded in the webhook log with the reason, and never processed. Webhook endpoints that BillStack creates for a test-mode key point at the /test URL automatically.
When a Stripe event arrives:
- BillStack verifies the
stripe-signatureheader using your webhook secret for that environment and checks the event'slivemodeagainst the endpoint - The sync engine writes raw event data into your team's isolated schema for that environment (live and test data are stored separately)
- The webhook processor routes the event to the correct project using the
project_idin the event object's own metadata (subscription, invoice, checkout session, price, product, or customer), falling back to a lookup by Stripe customer or subscription ID when metadata is absent. Theproject_idmust name a project of the team that owns the endpoint; an event naming any other project is recorded but not applied to project tables - Project-level tables (customers, subscriptions, invoices) are updated
- The event is recorded for idempotency
Supported Stripe events
| Event type | What BillStack does |
|---|---|
checkout.session.completed | Only processed for one-time (mode=payment) sessions carrying metadata.billing_scheme=lifetime: creates a lifetime entitlement and moves the referral into its refund window. Subscription checkouts are synced via customer.subscription.* events instead, not this event. |
charge.captured / expired / failed / pending / refunded / succeeded / updated | Syncs charge data into your team schema (visible under team Payments) |
charge.dispute.created / updated / closed / funds_withdrawn / funds_reinstated | Syncs dispute data into your team schema (visible under team Disputes and via MCP) |
customer.created / updated / deleted | Syncs customer data |
customer.subscription.created / updated / deleted | Updates subscription records and syncs entitlements |
invoice.created / finalized / marked_uncollectible / paid / payment_failed / payment_succeeded / voided | Updates invoice records |
product.created / updated / deleted | Syncs product data |
price.created / updated / deleted | Syncs price data |
charge.* and payment_intent.* events are mirrored into your team schema by the sync engine but are not routed to project-level tables by the webhook processor.
Configure in Stripe Dashboard
- Get your webhook URL from BillStack team settings or:
curl "https://billing.w3dev.app/api/billstack/teams/{teamId}/stripe/webhook-url" \
-H "Cookie: <session-cookie>"- Go to Stripe Dashboard > Developers > Webhooks
- Click Add endpoint and paste your BillStack webhook URL
- Select all events (or at minimum the events listed above)
- Copy the signing secret (
whsec_...) and update your Stripe connection
Transitional dual webhooks
During migration, run both webhook endpoints simultaneously:
- Keep your old endpoint active
- Add the BillStack endpoint as a second endpoint
- Stripe sends events to both
- Once verified, disable the old endpoint
Razorpay webhook
BillStack provides a per-team webhook endpoint for Razorpay:
POST https://billing.w3dev.app/api/webhooks/razorpay/{teamId}
POST https://billing.w3dev.app/api/webhooks/razorpay/{teamId}/testThe first URL is the live endpoint and is unchanged. It is served for any team whose project has an active Razorpay config, including a team whose default payment provider is Stripe: the project's active Razorpay config plus a valid signature is the only rule. The /test URL writes events to the test environment, and only accepts projects configured with an rzp_test_ key id; a project with a live key id gets 400 with code: "ENVIRONMENT_MISMATCH". Razorpay events carry no live/test flag, so the key id decides.
When a Razorpay event arrives:
- BillStack reads
notes.project_id,notes.billstack_customer_id, andnotes.external_idfrom the event entity. Forpayment_link.paid, that is the Payment Link entity; the nested payment entity supplies the payment ID and captured payment details. All three notes must be present or the request is rejected with400. - BillStack verifies the
x-razorpay-signatureheader as an HMAC-SHA256 signature of the raw request body, using the project's configured Razorpay webhook secret. - BillStack looks up the customer and updates entitlements for the matching project.
Your Razorpay subscription or payment must be created with notes.project_id, notes.billstack_customer_id, and notes.external_id set so the webhook can route the event.
Supported Razorpay events
Subscribe Razorpay to payment_link.paid when using BillStack-created Payment
Links. Keep payment.captured enabled for other one-time payments and order
flows.
| Event type | What BillStack does |
|---|---|
payment_link.paid | Requires a paid link and captured nested payment, then creates or updates the entitlement and moves the referral into its refund window. Link notes provide BillStack attribution; if both entities include an order ID, they must match. |
payment.captured | Creates or updates the entitlement for the payment (lifetime or one-time) and moves the referral into its refund window |
subscription.activated | Creates or updates the subscription entitlement and moves the referral into its refund window |
subscription.charged | Updates the subscription entitlement (renewal) and moves the referral into its refund window |
subscription.cancelled | Marks the subscription entitlement as canceled |
RevenueCat webhook
RevenueCat is entitlement-only — there is no checkout flow for it. See RevenueCat for connecting an API key, configuring the webhook at https://billing.w3dev.app/api/webhooks/revenuecat/{teamId}/{projectId}, and the full list of supported event types.
Product app callbacks
Use success and cancel URLs for user experience only. Do not treat a success redirect as final payment truth.
Always rely on BillStack entitlements and webhook-processed state for access decisions.
Your product app should not process provider webhooks after cutover unless doing unrelated non-billing work.