Skip to content

Legacy Referrals

Generate codes, apply referrals, and show referral stats when BillStack runs your checkout.

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: Referrals API.

BillStack owns referral code state and lifecycle. Your app owns the referral UX.

Choose your mode

Referrals work differently depending on who runs checkout.

Your productUseReferrer reward
BillStack creates the checkout and subscription (billingOwnership: "billstack", the default)This page and the by-external-id routes belowBonus months applied to the referrer's entitlement
You keep your own Stripe account, Checkout sessions and subscriptions (external mode)Referrals with your own billingReferee discount through a Stripe promotion code, and referrer credits paid as a Stripe customer-balance credit

The routes on this page are the BillStack checkout mode. Do not use them for a project in external mode; use the v2 routes described in that guide, where rewards come from the credit ledger and BillStack schedules all processing. Already have your own referral system? See Import an existing referral system.

Get or create a referral code

curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/referrals/code/by-external-id/user_123" \
  -H "Authorization: Bearer <private-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "phone": "+14155550123",
    "name": "Example User"
  }'

Response:

{
  "code": {
    "id": "rcode_...",
    "projectId": "proj_abc123",
    "customerId": "pc_...",
    "code": "ABCD1234",
    "usageCount": 0,
    "totalCreditsEarned": 0,
    "totalMonthsEarned": 0,
    "isActive": true,
    "createdAt": "2026-06-01T12:00:00.000Z",
    "updatedAt": "2026-06-01T12:00:00.000Z"
  }
}

The short referral code to show your users is at code.code. Show it in your ambassador or referral dashboard.

Apply a referral code

Apply the code after the referred user has an app identity:

curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/referrals/apply/by-external-id" \
  -H "Authorization: Bearer <private-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "ABCD1234",
    "refereeExternalId": "new_user_456",
    "email": "new@example.com",
    "phone": "+14155550124",
    "name": "New User"
  }'

Response:

{
  "referral": {
    "id": "ref_...",
    "status": "pending"
  }
}

Referral checkout rule

If a logged-out visitor arrives with a referral code, send them through signup/login first. Then apply the referral and use logged-in checkout.

Avoid sending referral visitors directly to anonymous public payment links because the payment would not be attached to the referred app user.

Stats

curl "https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/referrals/stats/by-external-id/user_123" \
  -H "Authorization: Bearer <private-api-key>"

Use stats for ambassador dashboards. Do not compute referral rewards in the product app.

Reward processing is not automatic

Eligible referrals are not converted into rewards on their own. Rewards are only granted when you call:

curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}/referrals/rewards/process" \
  -H "Authorization: Bearer <private-api-key>" \
  -H "Content-Type: application/json" \
  -d '{ "limit": 100 }'

Schedule this endpoint on a periodic job (for example, a daily cron) so referrals that become eligible are rewarded promptly. Referrals that sit past their eligibility window without a call to this endpoint stay unrewarded.

Paying referrers

This guide covers BillStack checkout mode. If your product keeps its own billing and you want referrers to see earnings and request payouts, use the hosted partner portal with Referrals with your own billing.