Architecture
Understand teams, projects, customers, external IDs, providers, referrals, and entitlements.
BillStack is designed so product apps call one project-scoped API instead of integrating directly with every billing provider.
Two API generations
BillStack has two API generations. v2 (/api/billstack/v2/..., BillStackV2Client, the /v2/{team} dashboard) is provider-neutral and is the one to use for every new integration. Legacy (v1) (/api/billstack/teams/{teamId}/projects/{projectId}/..., BillStackClient, the /dashboard/{team} dashboard) is the original Stripe-first API. It stays supported for integrations that already call it and is maintenance-only. You can tell which generation you are on from the URL: /v2/ versus /dashboard/ in the dashboard, and /api/billstack/v2/ versus /api/billstack/teams/ in the API. Pages with a legacy- slug document the legacy generation.
Ownership model
| Layer | Owned by | Responsibility |
|---|---|---|
| Team | BillStack | Provider connections (one Stripe and one Razorpay account at most, via Connect or API keys), regions that decide which provider serves which country, and webhook URLs, shared by every project under the team |
| Project | BillStack | Product-specific customers, prices, subscriptions, invoices, referrals, and per-project Razorpay credentials for the legacy v1 integration |
| Product app | Your app | Auth, product UX, app-specific authorization |
| Provider | Stripe or Razorpay | Payment collection and provider-hosted checkout or payment links |
Stripe is connected once per team and shared by all of that team's projects. A team may also connect Razorpay; in the v2 API it is a team-level provider connection like Stripe, and the legacy v1 integration still reads a per-project Razorpay config (PUT /api/billstack/teams/{teamId}/projects/{projectId}/providers).
Teams and projects
A team is the top-level tenant that owns provider credentials. A project represents one SaaS product under that team.
Use one project per product. Do not share one project across unrelated products unless they truly share customers, prices, entitlements, and referrals.
External IDs
externalId is your app user ID. BillStack uses it to map your app user to a project customer.
Good external IDs:
- Stable across login methods.
- Unique inside your app.
- Not a phone number or email that may change.
API key types
Private API keys authenticate server-to-server writes and reads. Keep them only on your server.
Publishable keys are safe for browser use on public-read endpoints such as pricing and public payment-link resolution.
Entitlements
An entitlement is the current billing decision for a user. It contains the plan, status, provider, cycle, limits, features, and validity windows.
Your app should read entitlements from BillStack and optionally cache a copy locally for fast authorization. BillStack remains the source of truth.
Anonymous and logged-in checkout
Use anonymous public payment links for marketing-page purchases that do not need immediate app-side referral attribution.
Use logged-in checkout sessions when the payment must attach to a known app user, apply referral codes, create customer records, or support provider choice.
Checkout provider selection
A team can take payments through Stripe and Razorpay at once. The unit is a region: one provider account plus the countries it serves. One region is the default and serves every country no other region claims, so a team with a single provider has just the default region and works as before. A team has at most one account per provider, so at most two regions; a second account of the same provider needs a separate team.
- Routing. The v2 checkout routes by the country the customer confirmed (a signed, customer-bound, single-use token). Until a customer's first successful payment each checkout is routed again by country; the first payment pins the customer to the region they paid in, and from then on moving country never re-routes them.
- No silent fallback. If a region cannot serve, checkout fails with
PROVIDER_UNAVAILABLE; it is never retried through another provider. The customer's phone number never selects a provider. - One integration. Same API key, customers and entitlements whichever region took the payment.
- v1 checkout serves the default region only and rejects a customer pinned elsewhere with
REGION_REQUIRES_V2. If you sendprovider, it must match the default region's provider.
RevenueCat is an entitlement source, not a payment provider, so it can be connected alongside either one. Regions, pinning, token rules and an India/Stripe example: Multi-provider v2.
Referrals
BillStack owns referral code generation, applying referral codes to customers, conversion tracking, stats, and reward lifecycle.
Your app owns the referral UX. If a referral requires app identity, send anonymous users through signup/login before checkout.