Skip to content

Migrate from Razorpay (legacy)

Move Razorpay checkout and subscription ownership into 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.

Use this migration when India billing or Razorpay subscriptions must stay supported.

This page documents the legacy v1 Razorpay integration and its project-level provider configuration. v2 uses team-scoped provider connections, project-scoped bindings, regions (a team can take Razorpay for some countries and Stripe for the rest), and explicit country confirmation; it does not silently fall back between providers. To sell in India through Razorpay while Stripe stays the default, see Regions in the multi-provider v2 guide.

Target state

  • Razorpay API credentials and webhook secret live in BillStack.
  • Project provider config includes subscription plan IDs and payment amounts.
  • Product apps do not read Razorpay secrets.
  • Checkout starts through BillStack.
  • Entitlements come from BillStack after webhook processing.

Required data

BillStack needs real provider credentials. Public payment links alone are not enough for subscription and webhook ownership.

Prepare:

  • Razorpay key ID and key secret.
  • Razorpay webhook secret.
  • Subscription plan IDs for recurring tiers.
  • Amount mappings for one-time or payment-link flows.
  • Existing customer/subscription identifiers if backfilling active users.

Migration steps

  1. Configure Razorpay provider settings in BillStack (there is no dashboard UI for this — see Configure the provider via API below).
  2. Map every app tier and cycle to a BillStack price.
  3. Store recurring Razorpay plan IDs for subscription prices.
  4. Store amount mappings for one-time prices when needed.
  5. Update app checkout to call /checkout/start with provider: "razorpay" when Razorpay should be used.
  6. Point Razorpay webhooks to BillStack.
  7. Subscribe the Razorpay webhook to payment_link.paid for BillStack-created Payment Links, and verify entitlement state after payment_link.paid, payment.captured, subscription.activated, subscription.charged, and subscription.cancelled events (see Entitlement sync below).
  8. Remove Razorpay secret environment variables from the product app.

Configure the provider via API

There is no dashboard screen for Razorpay provider config. Set it with PUT /api/billstack/teams/{teamId}/projects/{projectId}/providers:

curl -X PUT \
  "https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/providers" \
  -H "Content-Type: application/json" \
  -H "Cookie: <session-cookie>" \
  -d '{
    "provider": "razorpay",
    "keyId": "rzp_live_xxx",
    "secret": "<razorpay-key-secret>",
    "webhookSecret": "<razorpay-webhook-secret>",
    "metadata": {
      "razorpayPlanIds": {
        "pro_monthly": "plan_ABC123",
        "pro_annual": "plan_DEF456",
        "growth_monthly": "plan_GHI789"
      },
      "razorpayAmounts": {
        "lifetime_once": 999900
      }
    }
  }'

provider and secret are required; keyId becomes the stored publishableKey.

Plan ID and amount mappings

Subscription plan IDs and one-time amounts are not stored on BillStack prices — they live in the Razorpay provider config's metadata, under two maps:

  • metadata.razorpayPlanIds — used for recurring checkout (cycle is monthly/annual/yearly). Values are Razorpay plan IDs.
  • metadata.razorpayAmounts — used for one-time/lifetime checkout (cycle: "once" or tier: "lifetime"). Values are amounts in the smallest currency unit (paise for INR).

Both maps are keyed {tier}_{cycle}, e.g. pro_monthly, growth_annual, lifetime_once. yearly is normalized to annual for the lookup key.

If a key is missing when a customer checks out with that tier/cycle, checkout fails with:

  • Razorpay plan id is not configured for {key} (subscription flow)
  • Razorpay amount is not configured for {key} (one-time/lifetime flow)

razorpayAmounts is only consulted when the tier has no active tiered Lifetime Deal campaign. If a campaign is active for the tier, its current step's price (or sold-out fallback) takes over the one-time/lifetime checkout entirely — see Lifetime Deal Campaigns → Razorpay for the full behavior, including the order-currency match requirement and the sold-out/unavailable error cases.

Provider selection

A team has a default region, the payment provider that serves every customer unless a country is assigned elsewhere. The default is chosen when the team is created (a team created without one takes the provider of the first connection). The v1 checkout described on this page always uses the default region's provider: the customer's phone number never picks Razorpay, and there is no fallback to Stripe. If the project's Razorpay config is missing, inactive, or incomplete (no key ID or secret), checkout fails with a 400. A provider you pass to startProjectCheckout must match the default region's provider, otherwise the request fails with PAYMENT_PROVIDER_CONFLICT.

A team can also connect the other provider and give it a region, for example Stripe as the default and Razorpay for IN. That setup is v2 only:

  • The v1 checkout never takes a country and always serves the default region. A customer who has already paid in a non-default region (their pin) gets 409 REGION_REQUIRES_V2 from v1 and is never billed in the default region instead.
  • Saving a Razorpay project config on a team whose default is Stripe is accepted, and its legacy webhook URL is served; it does not make v1 checkout use Razorpay for that team.
  • Use a Razorpay provider connection (POST /provider-connections), INR price links, and a region. The Razorpay webhook of a connection goes to the connection's own canonicalWebhookUrl. A payment of a v2 lifetime campaign is settled once even when the same Razorpay account also delivers to the legacy per-team URL.
  • A Razorpay region sells INR only. Variants in other currencies are served by the default region; a Razorpay-routed customer asked to pay a non-INR variant gets 422 PRICE_UNAVAILABLE_IN_REGION.
  • Razorpay cannot issue refunds or portal sessions through BillStack, and Stripe-only features (public payment links, referral credit payouts) return 409 FEATURE_UNAVAILABLE_IN_REGION for a Razorpay-region customer.

A team can connect one Razorpay account. A second Razorpay account (for example for another legal entity) needs a separate team.

Entitlement sync

BillStack syncs entitlement state from these Razorpay webhook events only:

  • payment_link.paid — activates the entitlement for a paid BillStack Payment Link and moves any pending referral into its refund window. BillStack reads project/customer attribution from the signed Payment Link entity's notes; Razorpay's nested payment entity supplies the payment ID, captured amount, and currency. The link must have status: "paid" and its nested payment must have status: "captured". If both entities include an order_id, they must match. Lifetime campaign links expire after 60 minutes (or at the campaign's availableUntil); a payment captured after its link expired is not fulfilled and needs a manual refund. See Razorpay link expiry.
  • payment.captured — activates the entitlement (used for lifetime/one-time purchases) and moves any pending referral into its refund window. For legacy order-based tiered LTD purchases, when payment notes carry billstack_campaign_id/billstack_campaign_step_id, the captured amount is verified against the step's canonical price and the sale is recorded idempotently and lifetime (non-expiring) access is granted for the campaign's tier; a mismatch is rejected. A recorded Razorpay sale also immediately closes the exhausted step's Stripe Payment Link. BillStack-created Payment Links use payment_link.paid and their link notes instead.
  • subscription.activated / subscription.charged — activates or refreshes the subscription entitlement and moves any pending referral into its refund window.
  • subscription.cancelled — marks the entitlement canceled.

Failed and expired payments are not currently synced — there is no handler for Razorpay's failure/expiry events, so a failed or expired payment does not change entitlement state in BillStack. Reconcile these cases manually until that handler exists.

Common gap

Legacy apps often store only public Razorpay payment links. That is not enough to recreate BillStack provider config. You still need API credentials, webhook secret, and plan IDs for subscription flows.