Skip to content

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}/test

Register 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:

  1. BillStack verifies the stripe-signature header using your webhook secret for that environment and checks the event's livemode against the endpoint
  2. The sync engine writes raw event data into your team's isolated schema for that environment (live and test data are stored separately)
  3. The webhook processor routes the event to the correct project using the project_id in 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. The project_id must name a project of the team that owns the endpoint; an event naming any other project is recorded but not applied to project tables
  4. Project-level tables (customers, subscriptions, invoices) are updated
  5. The event is recorded for idempotency

Supported Stripe events

Event typeWhat BillStack does
checkout.session.completedOnly 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 / updatedSyncs charge data into your team schema (visible under team Payments)
charge.dispute.created / updated / closed / funds_withdrawn / funds_reinstatedSyncs dispute data into your team schema (visible under team Disputes and via MCP)
customer.created / updated / deletedSyncs customer data
customer.subscription.created / updated / deletedUpdates subscription records and syncs entitlements
invoice.created / finalized / marked_uncollectible / paid / payment_failed / payment_succeeded / voidedUpdates invoice records
product.created / updated / deletedSyncs product data
price.created / updated / deletedSyncs 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

  1. 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>"
  1. Go to Stripe Dashboard > Developers > Webhooks
  2. Click Add endpoint and paste your BillStack webhook URL
  3. Select all events (or at minimum the events listed above)
  4. Copy the signing secret (whsec_...) and update your Stripe connection

Transitional dual webhooks

During migration, run both webhook endpoints simultaneously:

  1. Keep your old endpoint active
  2. Add the BillStack endpoint as a second endpoint
  3. Stripe sends events to both
  4. 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}/test

The 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:

  1. BillStack reads notes.project_id, notes.billstack_customer_id, and notes.external_id from the event entity. For payment_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 with 400.
  2. BillStack verifies the x-razorpay-signature header as an HMAC-SHA256 signature of the raw request body, using the project's configured Razorpay webhook secret.
  3. 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 typeWhat BillStack does
payment_link.paidRequires 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.capturedCreates or updates the entitlement for the payment (lifetime or one-time) and moves the referral into its refund window
subscription.activatedCreates or updates the subscription entitlement and moves the referral into its refund window
subscription.chargedUpdates the subscription entitlement (renewal) and moves the referral into its refund window
subscription.cancelledMarks 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.