Skip to content

Sandbox API

v2 routes of the BillStack sandbox - test clocks and the headless simulate API for hosted checkouts, cards and refunds.

These routes drive the BillStack sandbox, the simulated payment provider a team can run its test environment on. They live under the v2 API:

/api/billstack/v2/teams/{teamId}/sandbox

All routes are team-wide (no projectId), take a private key in the Bearer header and answer in the v2 envelope ({ data, meta }, or { error, meta }). See the v2 reference for the envelope and Authentication for keys.

  • Test keys only. A bs_live_ key, or any request that runs in the live environment, is refused with 403 SANDBOX_TEST_ONLY.
  • Native sandbox only. A team whose test environment runs on the provider sandbox answers 409 NOT_NATIVE_SANDBOX.
  • Permissions. A key created by the setup wizard can call every route. A key with an IAM policy needs checkout:CreateCheckout to simulate a checkout, paymentMethod:AttachPaymentMethod to set a card, billing:UpdateBilling to refund and to create, advance or delete a clock, and billing:GetBilling to read clocks, all on the team. A missing permission answers 403 UNAUTHORIZED.
  • Project-scoped keys. A key limited to one project can simulate checkouts, set cards and refund only for that project's checkout sessions, customers and payments; anything else answers 404 NOT_FOUND. Test clocks belong to the whole team, so a project-scoped key is refused on every clock route with 403 UNAUTHORIZED: use a team-scoped key or the dashboard.

Test clocks

GET    /teams/{teamId}/sandbox/clocks
POST   /teams/{teamId}/sandbox/clocks
GET    /teams/{teamId}/sandbox/clocks/{clockId}
DELETE /teams/{teamId}/sandbox/clocks/{clockId}
POST   /teams/{teamId}/sandbox/clocks/{clockId}/advance

A clock object:

{
  "id": "clock_...",
  "name": "renewal test",
  "frozenTime": "2026-01-01T00:00:00.000Z",
  "status": "ready",
  "advanceTarget": null,
  "createdAt": "2026-01-01T00:00:00.000Z"
}

status is ready (time is frozen), advancing (an advance is running toward advanceTarget) or internal_failure (an advance gave up).

RouteBodyAnswer
GET .../clocks200, data is an array of clocks
POST .../clocks{ name?, frozenTime? }. frozenTime is an ISO 8601 date-time and defaults to now. The body may be empty201, the clock
GET .../clocks/{clockId}200, the clock. Poll it after an advance
DELETE .../clocks/{clockId}200, { id, deleted: true }. Removes the clock with its customers and subscriptions (each emits customer.deleted)
POST .../clocks/{clockId}/advance{ to }, an ISO 8601 date-time after the clock's frozenTime202, the clock in advancing

Advancing runs the renewals, trial ends, invoices, payment attempts, retries and cancellations that fall due up to to, in time order, in the background. Poll the clock until status is ready and frozenTime equals to. Customers attach to a clock when they are created (at most 10 per clock) and never move; the dashboard creates them with sample data.

CodeStatusMeaning
INVALID_REQUEST400to or frozenTime is not an ISO 8601 date-time, or name is not a string.
NOT_FOUND404The clock does not exist for this team.
CONFLICT409The clock is already advancing (or failed), to is not after frozenTime, or the clock is advancing and cannot be deleted.

Simulate a hosted checkout

POST /teams/{teamId}/sandbox/checkout-sessions/{sessionId}/simulate

sessionId is the sessionId of the v2 checkout result (cs_sbx_...). Body:

FieldTypeMeaning
outcomestring, requiredpay, decline, insufficient_funds, require_authentication, cancel, complete_authentication or fail_authentication
cardstring, optionalA test card number. Only with pay; defaults to 4242 4242 4242 4242. 4000 0000 0000 0341 returns card_error here (the checkout charges at once); use it with the set-card route

Answers 200 with one of:

data.statusFieldsWhen
completesessionId, redirectUrl, subscriptionId, paymentIdThe payment succeeded and the session is complete. subscriptionId is null for a one-time payment, and paymentId is null when nothing was charged
canceledsessionId, redirectUrl, reason (customer_canceled or authentication_failed)cancel, or a failed authentication
requires_actionsessionId, paymentIdrequire_authentication, or a card that needs 3D Secure. Finish with complete_authentication or fail_authentication
card_errorsessionId, code, declineCode, messageThe card was declined. The session stays open and can be paid again with another card
CodeStatusMeaning
INVALID_REQUEST400Unknown outcome, or card is not a card number or is sent with another outcome.
NOT_FOUND404The session does not exist for this team.
SESSION_EXPIRED410The session is older than 24 hours.
SESSION_ALREADY_COMPLETE409The session was already paid.
SESSION_CLOSED409The session was canceled or expired.
AUTHENTICATION_PENDING409The session waits for 3D Secure; only complete_authentication and fail_authentication apply.
AUTHENTICATION_NOT_PENDING409There is no authentication to complete or fail.

Set a customer's card

POST /teams/{teamId}/sandbox/customers/{customerId}/payment-method

Attaches a test card to a sandbox customer (cus_sbx_...) and makes it the card the customer is charged with from now on, renewals and retries included. Body: { "card": "4000 0000 0000 0341" }. Answers 201:

{
  "paymentMethodId": "pm_sbx_...",
  "brand": "visa",
  "last4": "0341",
  "requiresAction": false,
  "isDefault": true
}

requiresAction is true for a card that asks for authentication when it is attached. 4000 0000 0000 0341 attaches and then fails every charge, which is how to test a failing renewal. Errors: 400 INVALID_REQUEST (not a card number), 404 NOT_FOUND (unknown customer), 402 CARD_ERROR (a card that fails at setup, such as 4000 0000 0000 0002).

Refund a payment

POST /teams/{teamId}/sandbox/payments/{paymentId}/refund

Refunds a sandbox payment (the paymentId of a simulation result). Body: { "amount"?: 500, "reason"?: "requested_by_customer" }. amount is a positive integer in minor units; omit it, or send an empty body, to refund what is left. Answers 201:

{
  "refundId": "re_sbx_...",
  "paymentId": "pi_sbx_...",
  "amountMinor": 500,
  "currency": "usd",
  "reason": "requested_by_customer"
}

Errors: 400 INVALID_REQUEST (amount is not a positive integer, or reason is not a string), 404 NOT_FOUND and 409 CONFLICT (the amount is more than the payment has left).

TypeScript SDK

BillStackV2Client.sandbox wraps every route above: sandbox.clocks.list, get, create, delete, advance and advanceAndWait, plus sandbox.simulateCheckout, sandbox.setPaymentMethod and sandbox.refund. See BillStack sandbox for examples.