---
name: run-billstack-lifetime-deals
description: "v2 (provider-neutral). Run a stepped-price lifetime deal on a one-time Catalog price with BillStack: create a draft with an idempotency key, launch it to the project's provider (Stripe, or the native sandbox in test), show its live price on a pricing page with a publishable key, sell it through checkout or the hosted payment link, edit unsold steps safely, end it, list its sales and the payments to refund, and revoke a buyer, with the v2 routes, BillStackV2Client or authenticated MCP tools, starting in the test environment."
---

# Run BillStack lifetime deals

**Generation: v2** (provider-neutral, `/api/billstack/v2/...`, `BillStackV2Client`). This skill covers v2 only. A lifetime deal sells one plan for good at a price that steps up as units sell, up to a total cap, and then at the regular price. It is built on a one-time Catalog price that has a plan (`tierAlias`). Campaigns created earlier on legacy Stripe tier prices (the routes `/api/billstack/teams/{teamId}/projects/{projectId}/lifetime-campaigns`, with a `productId`) are a different object and are not served here: for those only, load [legacy-billstack-lifetime-deals](https://billing.w3dev.app/.well-known/agent-skills/legacy-billstack-lifetime-deals/SKILL.md).

For checkout and entitlements load [integrate-billstack](https://billing.w3dev.app/.well-known/agent-skills/integrate-billstack/SKILL.md); for the one-time price and its provider link load [configure-billstack-billing](https://billing.w3dev.app/.well-known/agent-skills/configure-billstack-billing/SKILL.md). Human-readable guide: https://docs.billing.w3dev.app/integration/lifetime-deals

Prefix `P = https://billing.w3dev.app/api/billstack/v2/teams/{teamId}/projects/{projectId}`. Responses are `{ "data": ..., "meta": { "apiVersion": "2", "requestId": ... } }`; errors are `{ "error": { "code", "message", "fieldErrors"? }, "meta": ... }`. Send `x-request-id` to choose the request id. Amounts are integers in minor units.

## Credentials and permissions

| Call | Needs | Credential |
| --- | --- | --- |
| `GET P/lifetime-deals`, `GET P/lifetime-deals/{dealId}` | `price:ListPrices` / `price:GetPrice` | project key (`bs_`), personal access token or dashboard session |
| `GET P/lifetime-deals/{dealId}/sales` and `/payment-rejections` | `invoice:ListInvoices` | the same |
| `POST P/lifetime-deals`, `PUT .../steps`, `POST .../launch` | `price:CreatePrice` | personal access token (`bsu_`, as `BILLSTACK_SETUP_TOKEN`) or dashboard session |
| `PATCH P/lifetime-deals/{dealId}`, `POST .../end` | `price:UpdatePrice` | the same |
| `POST .../sales/{saleId}/revoke` | `price:UpdatePrice` | personal access token or dashboard session only; every API key is refused |
| `GET P/lifetime-deals/public` | none | publishable key (`pk_test_`, `pk_live_`) only |

Setup is not runtime work: an app-runtime project key created since 2026-12-01 is refused on every write with `403 USER_TOKEN_REQUIRED`, exactly like catalog writes. A publishable key is refused everywhere except the public route, and a secret key is refused there. Reference keys by environment variable name (`BILLING_PORTAL_API_KEY`); never paste one. A call runs in the credential's own environment: `bs_test_` and `bsu_test_` see and change test deals only, a deal id of the other environment answers `404 LIFETIME_DEAL_NOT_FOUND`, and `?mode=` naming the other one is `403 ENVIRONMENT_MISMATCH`. Start in test; live needs the team promoted to live. The routes list only Catalog deals; an id of a legacy campaign is `404`. No new permission and no new role: the actions are the catalog and invoice ones above.

SDK: `client.lifetimeDeals` on `BillStackV2Client` from `@billstack/sdk/v2` ships in the next SDK release after 0.7.0 (0.7.0 does not have it; the HTTP routes work until then). It has `list`, `get`, `create`, `update`, `replaceSteps`, `launch`, `end`, `sales`, `paymentRejections`, `revokeSale` and `publicOffers`.

## Prerequisites

1. A project bound to a payment provider in the environment you use (Stripe, or a team on the native sandbox in test, which needs no keys). Otherwise launch answers `409 PROVIDER_BINDING_MISSING`. Razorpay and RevenueCat cannot publish a deal (`409 CAPABILITY_UNSUPPORTED`).
2. A one-time Catalog price with a `tierAlias`: `POST P/catalog/price-variants` with `"interval": "one_time"` and a `tierAlias`, `billingScheme` `standard` or `lifetime` (not consumable), see configure-billstack-billing. Its `id` is `basePriceVariantId`. The deal copies its product, currency and plan; buyers pay this price after the last step.
3. A project key for your server's reads and checkout, a setup token for writes, and for a pricing page a publishable key.

At most one deal per plan and environment is `active`. Statuses move `draft` to `active` to `ended`; an ended deal cannot be launched again. There is no pause. A deal belongs to one environment: launch it again from the same price in live (a sync between environments does not copy deals). No regional prices, no sold-out fallback price and no Razorpay for deals.

## Create a draft

```bash
curl -X POST "$P/lifetime-deals" -H "Authorization: Bearer $BILLSTACK_SETUP_TOKEN" -H "Content-Type: application/json" -d '{
  "idempotencyKey": "founders-deal-2026-12",
  "basePriceVariantId": "<one-time catalog price id>",
  "name": "Founders deal",
  "steps": [{ "unitAmount": 4900, "units": 50 }, { "unitAmount": 6900, "units": 100 }, { "unitAmount": 9900, "units": 350 }],
  "paymentLinkEnabled": true
}'
```

- `idempotencyKey` (1 to 200 characters) and `basePriceVariantId` are required. Send exactly one of `steps` (1 to 50, lowest price first) and `generator` (`{ "startAmount": 4900, "increment": 500, "unitsPerStep": 50, "totalCap": 220 }`: `ceil(totalCap / unitsPerStep)` steps priced `startAmount + i * increment`, the last taking the remainder). `name`, `availableFrom`, `availableUntil` (ISO 8601 with an offset; `availableFrom` after `availableUntil` is `400 INVALID_WINDOW`) and `paymentLinkEnabled` are optional. An unknown field is `400 INVALID_REQUEST` with `fieldErrors`.
- `201 { deal, replayed: false }`. Nothing is published to the provider and nothing sells yet. The same key and input again answers `200` with `replayed: true` and the same deal; the same key with other input is `409 IDEMPOTENCY_CONFLICT`. A deal is created completely or not at all, so a retry after a timeout is safe. Keys are never recycled: a key whose deal ended returns that deal.
- The deal view: `id`, `status`, `soldUnits`, `steps` (`stepIndex`, `unitAmount`, `units`), `state` (`purchasable`, `reason`, `currentStepIndex`, `currentUnitAmount`, `nextUnitAmount`, `unitsLeftInStep`, `totalSold`, `totalCap`, `soldOut`), `paymentLink` (`enabled`, `token` while enabled), `editableFromStepIndex`, the window and timestamps. Step `priceVariantId` is a hidden price, not purchasable by id.
- Errors: `400 BASE_PRICE_NOT_ONE_TIME` or `BASE_PRICE_NEEDS_PLAN`, `404 BASE_PRICE_NOT_FOUND`, `400 INVALID_STEPS`, `TOO_MANY_STEPS`, `INVALID_GENERATOR_CONFIG`.

## Launch, read, end

- `POST P/lifetime-deals/{dealId}/launch` (empty body or `{}`; any field is `400 INVALID_REQUEST`) publishes the base price and the step prices to the project's provider in the credential's environment, then makes the deal the plan's active deal. Launching an active deal publishes what is missing. Launch in test first. `409 TIER_HAS_ACTIVE_DEAL` if another deal of the plan is active, `409 INVALID_DEAL_STATUS` for an ended deal. `502 PROVIDER_WRITE_UNKNOWN` means the provider may have created a price: call launch again, it finishes what is missing. A provider that refuses a write answers `502` under its own `*_FAILED` code (`PRICE_CREATE_FAILED`, ...) with the message redacted; nothing was activated. An intent row goes to the audit log before the provider is called; `503 AUDIT_UNAVAILABLE` means nothing was sent.
- `GET P/lifetime-deals?status=active&limit=50&cursor=...` lists newest first (`{ items, nextCursor }`, `limit` 1 to 100, also `basePriceVariantId`); `GET P/lifetime-deals/{dealId}` reads one (`{ deal }`).
- `PATCH P/lifetime-deals/{dealId}` takes at least one of `name`, `availableFrom`, `availableUntil` (`null` clears) and `paymentLinkEnabled`. An ended deal is `409 LIFETIME_DEAL_ENDED`.
- `POST P/lifetime-deals/{dealId}/end` with an optional `{ "reason": "..." }` (up to 500 characters) ends it for good, audited and idempotent. New buyers then pay the base price; buyers so far keep their access.

## Edit unsold steps

`PUT P/lifetime-deals/{dealId}/steps` replaces the unsold steps; a step with any sale, even one unit of a step that has not sold out, is kept as it is. Read the deal first and send its `soldUnits` as `expectedSoldUnits` (required) and its `editableFromStepIndex` as `expectedFromStepIndex`:

```json
{ "steps": [{ "unitAmount": 5900, "units": 40 }], "expectedSoldUnits": 10, "expectedFromStepIndex": 1 }
```

If sales moved or the ladder changed since your read, the answer is `409 LIFETIME_DEAL_CHANGED` and nothing was written: read again and retry. `steps` or `generator` (exactly one) describe only the replaced part. On an active deal the new prices are published (and the change audited), so `502 PROVIDER_WRITE_UNKNOWN` can occur: retry the same call.

## Show it on a pricing page

`GET P/lifetime-deals/public` with `Authorization: Bearer <publishable-key>` (or `?pk=`) returns `{ offers }`, the active deals of the key's environment:

```json
{ "dealId": "ltdcamp_...", "name": "Founders deal", "tierAlias": "growth", "currency": "USD", "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 }], "basePrice": { "amountMinor": 9900, "currency": "USD" } }
```

Show `currentUnitAmount`, `unitsLeftInStep`, `nextUnitAmount` and `totalSold` of `totalCap`; show the buy button only when `purchasable` is true, and explain `reason` otherwise (`not_started`, `ended`, `sold_out`, `inactive`). It carries no payment link token, variant or step ids and no customer data. Responses, with or without an offer, are cached for about 10 seconds (`Vary: Authorization`), so counters can lag and a deal that just launched can take that long to appear. A secret key or a missing key is `403`.

## Sell it

- **Checkout:** a v2 checkout `POST P/checkout` with `{ "campaignTier": "<tierAlias>", ... }` sells the current step (one unit), then the base price once every step is sold (see integrate-billstack for the rest of the body and country confirmation). Buying a step price by id answers `400 CAMPAIGN_STEP_NOT_DIRECTLY_PURCHASABLE`. A customer who already owns the deal gets `409 LIFETIME_ALREADY_OWNED`.
- **Payment link:** with `paymentLinkEnabled`, `deal.paymentLink.token` gives a BillStack page `https://billing.w3dev.app/pay/<token>` that opens a checkout for what the deal sells right now. Add `?customer=<your user id>` to buy as one of your customers; without it the buyer is a guest. It is never a provider payment link. Switch it off and on with `PATCH` and the URL stays.
- A paid checkout grants the plan for good. Keep your app in step through [sync-billstack-entitlements](https://billing.w3dev.app/.well-known/agent-skills/sync-billstack-entitlements/SKILL.md).

BillStack does not reserve units at checkout: the step price the buyer was shown is what they pay, each completed payment counts one unit once, and the current step comes from `soldUnits` against the cumulative step sizes. 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 `totalCap`; the deal is then sold out. A checkout opened before a step edit keeps its price and can still complete.

## Sales, refunds and revoking

- `GET P/lifetime-deals/{dealId}/sales` lists the units sold, newest first: `stepIndex`, `unitAmount`, `amount`, `currency`, `provider`, `providerPaymentId`, `customerRef` (your id for the buyer), `access` (`granted`, `pending` while the provider event is not processed, `inactive` when refunded or expired at the provider, `revoked`), `revokedAt`.
- `GET P/lifetime-deals/{dealId}/payment-rejections?unresolved=true` (`true` or `false`; another value is `400 INVALID_FILTER`) is the refund list: payments the deal did not count because the buyer already owned it (`ALREADY_OWNED`: two payments by one buyer count one unit; the money is kept and the extra payment waits for you) and sales you revoked (`SALE_REVOKED`). BillStack never refunds: refund each row at the provider. There is no call to mark a row resolved yet.
- `POST P/lifetime-deals/{dealId}/sales/{saleId}/revoke` with `{ "reason": "chargeback" }` (1 to 500 characters, kept in the audit log) ends the access that sale gave. It answers `{ saleId, dealId, access: "revoked", alreadyRevoked, grantRevoked, refundRequired: true }`; calling it again answers `alreadyRevoked: true` and writes nothing. The unit is not given back and the step price does not come back, a late provider event of that payment cannot re-entitle the buyer, and the buyer may check out again at the current step. Only access changes: the grant keeps the status the provider reported, so the payment still reads as paid and a refund you make later is still seen as a refund. The grant is found through the payment, not through your id for the buyer, so a renamed customer id does not matter. `grantRevoked: false` means the provider event is not processed yet: the sale is marked and the grant is written without access when it arrives. When the buyer had access, your webhook endpoints also receive `entitlement.updated` with `cause.type` `lifetime_deal_revoked`; it is not a refund and no `purchase.refunded` follows from it. A sale with no grant that is older than one hour (the customer was deleted, or the event never projected) is `409 SALE_ACCESS_NOT_FOUND` and nothing is changed. It needs a personal access token or a dashboard session; confirm with the customer first. A sale of another deal is `404 SALE_NOT_FOUND`; a sale of a deal of another project or environment is `404 LIFETIME_DEAL_NOT_FOUND`, the same answer as for an id that does not exist.

All lists are keyset paged (`limit` 1 to 100, `nextCursor`; a malformed `cursor` is `400 INVALID_CURSOR`).

## MCP tools for operators

Connect an MCP client to https://billing.w3dev.app/mcp. Tool descriptions start with the generation they read (`v2: `).

| Tool | Does |
| --- | --- |
| `create_lifetime_deal` | Same as `POST P/lifetime-deals` (`projectId`, `basePriceVariantId`, exactly one of `steps` or `generator`, optional `idempotencyKey`; without one every call is a new deal). Needs `mcp:write`, `project:UpdateProject` and `price:CreatePrice`. Returns `{ deal, replayed }`. |
| `set_lifetime_deal_payment_link` | Switch the hosted link (`campaignId` is the deal id, `enabled`); the URL is `/pay/<deal.paymentLink.token>`. Needs `price:UpdatePrice`. Returns `{ deal }`. |
| `list_lifetime_campaigns`, `get_lifetime_campaign_status`, `set_lifetime_campaign_status`, `update_lifetime_campaign` | Read, launch (`activate`), end and edit steps of a deal. These tools serve Catalog deals and legacy campaigns alike. |

There is no MCP tool for sales, the refund list or revoking; use the routes. The output is the v2 deal view (`{ deal, replayed }`, `{ deal }`), not the earlier campaign status shape. Failures read `Error: <CODE>: <message>`; an invalid request lists its fields, `Error: INVALID_REQUEST: <message> (<field>: <message>; ...)`. The campaign tools in the last row are older: `set_lifetime_campaign_status` and `update_lifetime_campaign` need only `project:UpdateProject` (not `price:CreatePrice` or `price:UpdatePrice`) and write no audit row, so prefer the routes for launching, ending and editing steps when you need either.

## Errors

| Status | Code | Meaning and fix |
| --- | --- | --- |
| 400 | `INVALID_REQUEST`, `INVALID_FILTER`, `INVALID_CURSOR` | Bad or unknown body field (see `fieldErrors`), query value or cursor. |
| 400 | `INVALID_STEPS`, `TOO_MANY_STEPS`, `INVALID_GENERATOR_CONFIG`, `INVALID_WINDOW`, `INVALID_CURRENCY`, `UNSUPPORTED_CURRENCY` | The ladder, generator, window or currency is invalid. |
| 400 | `BASE_PRICE_NOT_ONE_TIME`, `BASE_PRICE_NEEDS_PLAN` | The price must be one-time and have a `tierAlias`. |
| 403 | `UNAUTHORIZED`, `USER_TOKEN_REQUIRED`, `ENVIRONMENT_MISMATCH`, `FORBIDDEN` | Missing permission or credential; a runtime key on a write; the other environment; an API key on revoke. |
| 404 | `LIFETIME_DEAL_NOT_FOUND`, `SALE_NOT_FOUND`, `BASE_PRICE_NOT_FOUND` | Not in this project and environment (a legacy campaign id included). |
| 409 | `IDEMPOTENCY_CONFLICT` | Same `idempotencyKey`, other input. Use a new key for new input. |
| 409 | `LIFETIME_DEAL_CHANGED` | Sales or steps moved since your read. Read again and retry. |
| 409 | `SALE_ACCESS_NOT_FOUND` | Revoke found no grant for an old sale (customer deleted or event never projected); nothing was changed. |
| 409 | `LIFETIME_DEAL_ENDED`, `INVALID_DEAL_STATUS`, `TIER_HAS_ACTIVE_DEAL` | Ended deals cannot be edited or launched; end the plan's other active deal first. |
| 409 | `PROVIDER_BINDING_MISSING`, `PROVIDER_ACCOUNT_UNAVAILABLE`, `CAPABILITY_UNSUPPORTED`, `PRODUCT_UNAVAILABLE`, `PRICE_VARIANT_INACTIVE`, `PROVIDER_PRICE_LINK_UNAVAILABLE`, `PROVIDER_SCOPE_MISMATCH` | The project cannot publish in this environment (no binding, no verified price link, a binding for another account); fix the binding or the price. |
| 400 | `UNSUPPORTED_TARGET`, `INVALID_PROVIDER` | A named target or provider cannot be published to; a deal uses the project's one binding. |
| 502 | `PROVIDER_PRICE_INVALID`, `PROVIDER_PRICE_VALIDATION_FAILED`, `PROVIDER_PRICE_LOOKUP_FAILED` | The provider failed, or made a price that does not match the Catalog's. Nothing was activated; retry `launch`. |
| 502 | `PRICE_CREATE_FAILED`, `PRODUCT_CREATE_FAILED` and any other code ending in `_FAILED` | The provider refused the write (launch, or a step edit on an active deal). The message is redacted. Fix the provider account or price, then retry the same call. |
| 502 | `PROVIDER_WRITE_UNKNOWN` | A provider write may have happened. Call the same operation again. |
| 503 | `AUDIT_UNAVAILABLE` | The audit row could not be written; nothing changed. Retry. |

## Verify

1. In test, create a draft: `status` is `draft`, `state.reason` is `inactive`, `state.totalCap` equals the sum of units. Repeat the call with the same key: `200` and `replayed: true`.
2. Launch it, then `GET P/lifetime-deals/public` with a `pk_test_` key: the offer is `purchasable` and `currentUnitAmount` equals step 0.
3. Check out with `campaignTier` (on the native sandbox, finish it with the simulate API, see integrate-billstack) and confirm `soldUnits` is up by one, a row is in `sales` with `access: "granted"`, and the buyer has the plan.
4. Edit the unsold steps with `expectedSoldUnits` from the read you just made and expect success; resend with a stale value and expect `409 LIFETIME_DEAL_CHANGED`. End the deal and confirm it leaves the public offers.
5. Repeat in live only after test works end to end and the team is promoted to live.

## Safety rules

- Never put a project key or token in a browser, prompt, repository or log. A pricing page uses only a publishable key.
- Test and live deals are separate objects; do not launch or edit a live deal from a test-only conclusion.
- Do not end a deal you still want to sell: ending is final.
- Do not revoke without confirming the customer, and refund at the provider yourself: revoking does not move money.
