---
name: legacy-billstack-lifetime-deals
description: "Legacy (v1, Stripe-first) campaign routes only, for campaigns that already exist on legacy Stripe tier prices. Run a tiered lifetime-deal (LTD) campaign with BillStack: create a step-priced one-time offer with a total unit cap, activate and edit it safely, show its live price on a pricing page, sell it through checkout or payment links, handle sold-out fallback and revocation, and operate it with the REST API or authenticated MCP tools, starting in the test environment. New lifetime deals on a Catalog price use the v2 skill run-billstack-lifetime-deals instead."
---

# Run BillStack lifetime deals (legacy routes)

**Generation: legacy (v1).** This skill is only for campaigns on legacy Stripe tier prices, through the legacy-path routes `/api/billstack/teams/{teamId}/projects/{projectId}/lifetime-campaigns` (no `/v2`). Dashboard campaigns of the legacy generation are read-only. **Do not use it to build a new lifetime deal:** new deals are built on a one-time Catalog price with the v2 routes, described in [run-billstack-lifetime-deals](https://billing.w3dev.app/.well-known/agent-skills/run-billstack-lifetime-deals/SKILL.md) (v2). The campaign routes below can still list, read, launch and end a Catalog deal, but creating, editing steps, sales, refunds and revoking a Catalog deal belong to the v2 skill. For checkout and entitlements load [integrate-billstack](https://billing.w3dev.app/.well-known/agent-skills/integrate-billstack/SKILL.md) (v2).

Use this skill to run a legacy campaign: one project tier sold as a lifetime (one-time) purchase whose price steps up as units sell, up to a total cap. The skill covers the whole campaign: setup, activation, the pricing page, selling, editing, ending and revoking. For the checkout and entitlement integration itself, load [integrate-billstack](https://billing.w3dev.app/.well-known/agent-skills/integrate-billstack/SKILL.md). Human-readable guide: https://docs.billing.w3dev.app/integration/lifetime-deal-campaigns

Prefix `P = https://billing.w3dev.app/api/billstack/teams/{teamId}/projects/{projectId}`. These are the Stripe-first routes (no `/v2`). Reads work with a project key (`bs_test_` or `bs_live_`) on a trusted backend. Creating, editing, activating and ending campaigns, and revoking entitlements, need a personal access token (`bsu_`, as `BILLSTACK_SETUP_TOKEN`), a signed-in project session, or a legacy full-access key: a key created since 2026-12-01 is refused with `403`. In the examples, send the token in place of `$BILLING_PORTAL_API_KEY` for the write calls. Reference the key by environment variable name (`BILLING_PORTAL_API_KEY`); never paste it. Errors are `{ "error": string, "code"?: string }`. Reads need IAM `project:GetProject`; creating, editing, activating, ending and revoking need `project:UpdateProject`.

## Prerequisites

1. A team and project with a **Stripe** region. A team that sells in a single region and bills only through Razorpay cannot create or edit campaigns (`409 CAMPAIGN_PROVIDER_UNSUPPORTED`). A team with a Stripe region plus a Razorpay region can, once every step has a price for both (see "Regions" below).
2. A tier (product) with at least one active price, and a connected Stripe account for the environment you use. `GET P/tiers` (IAM `product:ListProducts` and `price:ListPrices`) returns `{ tiers }`, each with its `product` and `prices`. You need the product's `id` as `productId`, the price's `tierAlias`, and the BillStack id (not the Stripe id) of any price you want as a sold-out fallback.
3. A private server key and, for a pricing page, a publishable key (`pk_test_` or `pk_live_`).
4. Start in test. A `bs_test_` key lists, creates, edits, activates and ends only **test** campaigns, sells through your Stripe test-mode account, and never counts a sale against a live campaign. A live key sees only live campaigns, and a campaign id from the other environment answers `404 CAMPAIGN_NOT_FOUND`. The public pricing endpoint shows the campaign of the publishable key's environment. A `bs_live_` key works only after the team is promoted to live (`403 LIVE_ENVIRONMENT_NOT_ENABLED` before).
5. At most one campaign can be `active` per tier and environment. Statuses move `draft` to `active` to `ended`; an ended campaign cannot be reactivated. There is no manual pause, but a multi-region team's campaign can be switched back to `draft` by the region gate (see "Regions").

This skill describes campaigns on legacy Stripe tier prices only. A Catalog deal (one with a `basePriceVariantId`) is built and run with [run-billstack-lifetime-deals](https://billing.w3dev.app/.well-known/agent-skills/run-billstack-lifetime-deals/SKILL.md).

## Create a campaign

`POST P/lifetime-campaigns` creates a `draft` and answers `201 { campaign, steps }`. Send exactly one of `steps` or `generator`.

```bash
curl -X POST "$P/lifetime-campaigns" -H "Authorization: Bearer $BILLING_PORTAL_API_KEY" -H "Content-Type: application/json" -d '{
  "productId": "<product-id>",
  "tierAlias": "growth",
  "name": "Founders deal",
  "currency": "usd",
  "availableUntil": "2026-11-30T23:59:59.999Z",
  "afterSoldOutPriceId": "<standard-price-id>",
  "steps": [
    { "unitAmount": 4900, "units": 50 },
    { "unitAmount": 6900, "units": 100 },
    { "unitAmount": 9900, "units": 350 }
  ]
}'
```

- `productId`, `tierAlias`, `name` and `currency` are required; `availableFrom`, `availableUntil` and `afterSoldOutPriceId` are optional. Amounts are positive integers in minor units. The total cap is the sum of all `units` (500 above).
- The generator replaces `steps`: `{ "startAmount": 4900, "increment": 500, "unitsPerStep": 50, "totalCap": 220 }` makes `ceil(totalCap / unitsPerStep)` steps priced `startAmount + i * increment`; the last step absorbs the remainder (here five steps: 4900, 5400, 5900, 6400, 6900, the last selling 20). `increment` may be `0`. A campaign has at most 50 steps.
- Currency is a 3-letter code. Zero- and three-decimal currencies (for example JPY, KWD) are unsupported.
- `afterSoldOutPriceId` must be an active `standard` price of this project in the campaign currency, not a lifetime or campaign price.
- Creation makes one Stripe one-time price and Payment Link per step. Nothing sells yet. Read `campaign.id` from the response, then activate: `PATCH P/lifetime-campaigns/{campaignId}` with `{ "action": "activate" }` (`draft` to `active`; repeating it on an active campaign is harmless; `409 TIER_HAS_ACTIVE_CAMPAIGN` if another is active for the tier).

## Honor price, count post-payment

BillStack does not reserve units at checkout. The step price a customer was shown is the price they pay, even if others finish checkout at the same time. Each completed payment is recorded once and adds one to `soldUnits`; the current step is always derived from `soldUnits` against the cumulative step sizes.

For the seller this means:

- Under heavy concurrency at a step or cap boundary, a few buyers can pay a cheaper step price after it "should" have sold out, and `soldUnits` can exceed the total cap. The campaign is then simply sold out.
- There are no reservations or waitlists, and BillStack never refunds over-sold units. Refund such buyers yourself if you do not want to honor them.
- A Checkout Session created before an edit keeps its original step and price and can still complete after the edit.
- Revoking an entitlement does not give the unit back; `soldUnits` only moves on a recorded payment.

## Read status

`GET P/lifetime-campaigns` lists every campaign of the key's environment, newest first (`{ campaigns }`). `GET P/lifetime-campaigns/{campaignId}` answers `{ campaign, steps, state, recentSales }`:

- `campaign`: `id`, `status`, `soldUnits`, `availableFrom`, `availableUntil`, `afterSoldOutPriceId`.
- `regions`: `{ applies, activeRegions, missingRegions, pause }`; see "Regions".
- `state`: `purchasable`, `reason` (`null`, `inactive` for a draft, `not_started`, `ended`, `sold_out`), `currentStepIndex`, `unitsLeftInStep`, `totalSold`, `totalCap`, `soldOut`. `recentSales` holds the latest 20 recorded payments.

## Edit, window, end

`PATCH P/lifetime-campaigns/{campaignId}` takes **either** a lifecycle action **or** field and step edits, never both (`400`; `action` is `activate` or `end`).

```json
{ "name": "Founders deal", "availableFrom": "2026-11-01T00:00:00.000Z", "availableUntil": "2026-11-30T23:59:59.999Z",
  "afterSoldOutPriceId": null, "steps": [{ "unitAmount": 5900, "units": 40 }],
  "expectedSoldUnits": 10, "expectedFromStepIndex": 1 }
```

- `name`, the window and `afterSoldOutPriceId` can change at any time; `null` clears a window bound or the fallback. An invalid ladder (`steps` or `generator`) is rejected before anything is written, but detail edits and step edits are separate writes, not one transaction (see the `409` note below).
- `steps` or `generator` (at most one) replace every **unsold** step from the first unlocked step onward. A step is locked once any unit of it has sold, so the step in progress and earlier ones are kept. Replaced steps get new Stripe prices and old ones are retired.
- Always read status first and send its `soldUnits` as `expectedSoldUnits` and the first unlocked step index as `expectedFromStepIndex` (both only valid with `steps` or `generator`). Status has no field for that index; compute it: the lowest `stepIndex` whose cumulative start (the sum of the `units` of the steps before it) is at least `soldUnits`, or the last `stepIndex` + 1 if there is none. It is not `state.currentStepIndex` when a step is part-sold. If sales moved, the call fails with `409 CAMPAIGN_CHANGED` before any Stripe price is created: re-read and retry.
- A combined request saves `name`, the window and `afterSoldOutPriceId` first and checks the snapshot afterwards, so a `409 CAMPAIGN_CHANGED` can still have saved the detail fields. Re-read status after any failure, or send detail edits and step edits as separate requests.
- The window is exact UTC instants. `availableFrom` after `availableUntil` is `400 INVALID_WINDOW`. To sell through a whole UTC day, send `...T23:59:59.999Z` as `availableUntil`.
- **Ending** (`{ "action": "end" }`, from `draft` or `active`, idempotent) is permanent and disables the campaign's step links. To stop selling temporarily, there is no pause: either end the campaign for good or set `availableFrom` to a future time so the state is `not_started`.
- Leave a sold-out campaign `active` if you want the fallback. The fallback is used only while the campaign is `active` and sold out or past `availableUntil`. Once ended, the tier's checkout reverts to its ordinary lifetime flow.

## Show it on a pricing page

`GET P/tiers/public` with `Authorization: Bearer <publishable-key>` (or `?pk=`) returns `{ tiers }`. Each tier has the usual `prices` (campaign step prices are never listed there) and a `lifetimeCampaign` that is `null` unless the tier has an `active` campaign:

```json
{ "campaignId": "ltdcamp_...", "name": "Founders deal", "currency": "usd", "status": "active",
  "purchasable": true, "reason": null, "currentStepIndex": 1, "currentUnitAmount": 6900,
  "unitsLeftInStep": 37, "nextUnitAmount": 9900, "totalSold": 113, "totalCap": 500, "soldOut": false,
  "availableFrom": null, "availableUntil": null,
  "steps": [{ "unitAmount": 4900, "units": 50 }, { "unitAmount": 6900, "units": 100 }, { "unitAmount": 9900, "units": 350 }] }
```

Show `currentUnitAmount`, `unitsLeftInStep`, `nextUnitAmount` and `totalSold` of `totalCap`; show the buy button only when `purchasable` is true; when it is false, explain `reason`. Responses with an active campaign are cached for about 10 seconds, so counters can lag slightly. `401 Publishable key required` means a missing or wrong `pk_` key.

## Sell it

With an active campaign the checkout simply uses the current step; no extra parameter is needed.

- **Anonymous payment link:** `GET P/checkout/public-link?tier=lifetime&cycle=once` with a private or publishable key returns `{ checkoutUrl, provider: "stripe", mode: "payment_link", tier, cycle }`. `tier` is `pro`, `growth` or `lifetime`; the tier's entitlement policy decides which tier alias it resolves to, and that alias must equal the campaign's `tierAlias`. Fetch the link when the buyer clicks, not at page build time, because the step changes as units sell.
- **Logged-in checkout:** `POST P/checkout/start` with `{ externalId, email, tier, cycle: "once", successUrl, cancelUrl }` answers `201 { checkoutUrl, customerId, provider, intentId }`. For `tier: "lifetime"` the campaign tier alias is `growth`. Send the buyer to `checkoutUrl`. This path keeps the duplicate-purchase guard for a known customer; anonymous links do not, so a guest can buy twice.
- Do not pass a campaign step's price id to `POST P/checkout`: it answers `422 CAMPAIGN_STEP_PRICE_NOT_DIRECTLY_PURCHASABLE`. Always check out by tier.
- A paid campaign checkout grants a lifetime entitlement for the tier. Keep your app in step with it through [sync-billstack-entitlements](https://billing.w3dev.app/.well-known/agent-skills/sync-billstack-entitlements/SKILL.md).

## Sold out and closed

When the campaign is sold out or its `availableUntil` has passed, and it has `afterSoldOutPriceId`, checkout and payment links switch to that price (typically the regular recurring price; a recurring fallback needs its own configured Payment Link). Before `availableFrom` the fallback is never offered. With no fallback, or before the start, tier checkout answers `400 { "error": "Lifetime campaign is not currently purchasable" }` and the payment-link endpoint answers `404 { "error": "No matching active price found" }`.

## Regions (Stripe plus Razorpay)

A team with two or more **active** regions (stored status; an unavailable connection still counts) can run a campaign only if every step still on sale has a price for every active region. A Stripe region sells the step's own Stripe price; a Razorpay region needs a **regional alternate** for the step (INR only). Single-region teams are unchanged.

- Without alternates, activation answers `409 CAMPAIGN_REGION_ALTERNATE_MISSING`; the message and `missingRegions` name regions and 0-based step indexes.
- Supply alternates per step as `steps[].alternates = { "<regionId>": { "amount": 399900, "currency": "inr" } }` on create or step edits (explicit steps only), or add them to existing steps with a `PATCH` that carries only `{ "regionalAlternates": { "regionId": "<regionId>", "alternates": [{ "stepIndex": 0, "amount": 399900 }] } }`. They are add-only: the same value again is a no-op, a different one is `409 REGIONAL_ALTERNATE_IMMUTABLE`; replace the unsold step to change a price. Malformed ones are `400 INVALID_REGIONAL_ALTERNATE`. Promotion to live does not copy them.
- Activating a non-default region, or a step edit that drops an alternate, switches active campaigns lacking one back to `draft` (a 5-minute sweep is the backstop). The region activation response lists `pausedCampaigns` with warning `LIFETIME_CAMPAIGNS_PAUSED`; status shows `regions.pause`. A paused campaign is never resumed automatically: add the alternates, then activate it again.
- The routes above serve the default region only (`409 REGION_REQUIRES_V2` for a customer pinned elsewhere). To sell in any region use the v2 checkout `POST /api/billstack/v2/teams/{teamId}/projects/{projectId}/checkout` with `campaignTier` instead of `priceVariantId`; it routes by the customer's pin, else the confirmed country, and sells that region's price. Errors: `422 PRICE_UNAVAILABLE_IN_REGION` (token not spent), `409 CAMPAIGN_UNAVAILABLE`, `409 LIFETIME_ALREADY_OWNED`. Load [integrate-billstack](https://billing.w3dev.app/.well-known/agent-skills/integrate-billstack/SKILL.md) for country confirmation.
- A Razorpay campaign payment is settled by the connection's webhook, so its `canonicalWebhookUrl` must be registered with Razorpay (the legacy per-team URL also settles it, once). Settlement records the sale, grants the entitlement and pins the customer.
- If a customer pays for a tier they already own (checkouts open in two regions), the money is kept, no second unit or entitlement is sold, and a rejection row with reason `ALREADY_OWNED` and `refund_required` is left for you. Refunds are always manual. A payment in a different region than the pin also raises the `customer.region_conflict` webhook event.
- The dashboard campaign card shows a regions warning and a "Regional prices" button when more than one region is active.

## Razorpay in brief

Razorpay campaign payment links expire after 60 minutes or at `availableUntil`, whichever is sooner (never under about 16 minutes); a payment made before expiry is honored at the price shown. A captured payment that is not honored (expired link, wrong amount, incomplete notes) records no sale, grants no access, is saved once as a rejection row, and is never refunded automatically: refund it in the Razorpay dashboard and mark the rejection row resolved (there is nothing to revoke). To refund an honored Razorpay purchase, refund in the dashboard and then revoke its entitlement (below).

## Revoke a lifetime entitlement

```bash
curl "$P/customers/by-external-id?externalId=<app-customer-id>" -H "Authorization: Bearer $BILLING_PORTAL_API_KEY"
curl "$P/customers/{customerId}/lifetime-entitlements" -H "Authorization: Bearer $BILLING_PORTAL_API_KEY"
curl -X POST "$P/customers/{customerId}/lifetime-entitlements/{entitlementId}/revoke" -H "Authorization: Bearer $BILLING_PORTAL_API_KEY" -H "Content-Type: application/json" -d '{ "reason": "chargeback" }'
```

The first returns `{ customer }` (use `customer.id`), the second `{ entitlements }` including revoked rows. Revoking needs the IAM action `project:UpdateProject`, for API keys as well as sessions; a key without it gets `403`. Revoke answers `{ entitlement, refund }`. For a **Stripe** purchase it first issues a **full Stripe refund** (`refund` is `{ id, status }`), then ends the entitlement and the customer's lifetime access unless another active lifetime entitlement still grants the tier. For a Razorpay purchase `refund` is `null`: refund in Razorpay yourself. Revoking twice answers `409 Entitlement is already revoked` and refunds nothing again. Confirm with the customer before revoking; a refund cannot be undone.

## MCP tools for operators

Connect an MCP client to https://billing.w3dev.app/mcp and sign in with OAuth. Every tool takes `projectId`, optional `teamId` and optional `environment` (`test` or `live`; a key can only name its own, OAuth defaults to the team default). Read tools need `mcp:read` and `project:GetProject`; write tools need `mcp:write` and `project:UpdateProject`.

| Tool | Access | Does |
| --- | --- | --- |
| `list_lifetime_campaigns` | read | Same as `GET P/lifetime-campaigns`. |
| `get_lifetime_campaign_status` | read | Same as `GET P/lifetime-campaigns/{campaignId}`. |
| `create_lifetime_campaign` | write | Same as `POST P/lifetime-campaigns` (exactly one of `steps` or `generator`). |
| `update_lifetime_campaign` | write | Field and step edit, including `expectedSoldUnits` and `expectedFromStepIndex`; it takes no `action`. |
| `set_lifetime_campaign_status` | write | `action` of `activate` or `end`. |

Failures read `Error: <CODE>: <message>`; malformed input reads `Error: INVALID_INPUT: <message>`. There is no MCP tool for revocation; use the REST route.

Teams with more than one enabled region also get `list_regions`, `get_region_coverage` (both need `mcp:read` and `billing:GetProviders`) and `set_lifetime_campaign_regional_alternates` (add-only; `mcp:write`, `project:UpdateProject`), and `create_lifetime_campaign` / `update_lifetime_campaign` accept `steps[].alternates`. A single-region team does not see these tools, and calls answer `Error: REGIONAL_PRICING_NOT_ENABLED`. Region writes (create, activate, make default, countries) are REST or dashboard only.

## Errors

| Status | Code | Meaning and fix |
| --- | --- | --- |
| 400 | `INVALID_STEPS`, `INVALID_GENERATOR_CONFIG`, `TOO_MANY_STEPS` | Empty or non-positive steps, bad generator values, or more than 50 steps. |
| 400 | `INVALID_WINDOW` | `availableFrom` is after `availableUntil`. |
| 400 | `INVALID_CURRENCY`, `UNSUPPORTED_CURRENCY` | Not a 3-letter code, or a zero- or three-decimal currency. |
| 400 | `INVALID_AFTER_SOLD_OUT_PRICE` | Fallback is missing, inactive, a lifetime or campaign price, or in another currency or project. |
| 400 | `INVALID_CAMPAIGN_STATUS` | Transition not allowed, for example activating an ended campaign. |
| 400 | none | Malformed body: both `steps` and `generator`, neither on create, `action` mixed with other fields, or no updatable field. |
| 403 | none | Missing or insufficient credentials (or `LIVE_ENVIRONMENT_NOT_ENABLED` for a live key). |
| 404 | `CAMPAIGN_NOT_FOUND`, `PRODUCT_NOT_FOUND` | Not in this project and environment. |
| 409 | `TIER_HAS_ACTIVE_CAMPAIGN` | Another campaign is already active for the tier; end it first. |
| 409 | `CAMPAIGN_CHANGED` | Sales or steps changed since your snapshot; re-read and retry. |
| 409 | `CAMPAIGN_PROVIDER_UNSUPPORTED` | The team sells in one region and it bills through Razorpay. |
| 409 | `CAMPAIGN_REGION_ALTERNATE_MISSING` | Two or more active regions and a region has no price for a step on sale; add regional alternates. |
| 409 | `REGIONAL_ALTERNATE_IMMUTABLE` | A different alternate already exists for that step and region. |
| 400 | `INVALID_REGIONAL_ALTERNATE` | Bad alternate shape, unknown or Stripe region, missing or sold-out step, or non-INR amount for a Razorpay region. |
| 422 | `PRICE_UNAVAILABLE_IN_REGION` | v2 checkout: the customer's region has no price for the campaign. |
| 409 | `CAMPAIGN_UNAVAILABLE`, `LIFETIME_ALREADY_OWNED` | v2 checkout: nothing on sale for the tier, or the customer already owns it. |
| 422 | `CAMPAIGN_STEP_PRICE_NOT_DIRECTLY_PURCHASABLE` | A step price id was sent to `POST P/checkout`; use tier checkout. |
| 500 | `PRODUCT_NOT_RESOLVABLE` | The product could not be resolved to a provider product; contact support. |

## Verify

1. In test, create a campaign, then `GET` it: `status` is `draft`, `state.reason` is `inactive`, `totalCap` equals the sum of units.
2. Activate it, then fetch `P/tiers/public` with a `pk_test_` key: `lifetimeCampaign.purchasable` is true and `currentUnitAmount` equals step 0.
3. Fetch the payment link for the tier and complete a Stripe test payment. After the signed webhook arrives, status shows `soldUnits` up by one, a row in `recentSales`, and the pricing counters moved. Confirm the buyer received lifetime access.
4. Edit the unsold steps with `expectedSoldUnits` from the status you just read and expect success. Resend with a stale `expectedSoldUnits` and expect `409 CAMPAIGN_CHANGED`. Then end the campaign and confirm `lifetimeCampaign` is `null`.
5. Repeat in live only after test works end to end and the team is promoted to live.

## Safety rules

- Never put a private key in a browser, prompt, repository or log. The pricing page uses only a publishable key.
- Do not activate or edit a live campaign from a test-only conclusion: test and live campaigns are separate objects.
- Do not end a campaign you want to keep as a sold-out fallback; ending is final.
- Do not revoke without confirming the customer: on Stripe it refunds in full.
