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}/sandboxAll 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 with403 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:CreateCheckoutto simulate a checkout,paymentMethod:AttachPaymentMethodto set a card,billing:UpdateBillingto refund and to create, advance or delete a clock, andbilling:GetBillingto read clocks, all on the team. A missing permission answers403 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 with403 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}/advanceA 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).
| Route | Body | Answer |
|---|---|---|
GET .../clocks | 200, 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 empty | 201, 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 frozenTime | 202, 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.
| Code | Status | Meaning |
|---|---|---|
INVALID_REQUEST | 400 | to or frozenTime is not an ISO 8601 date-time, or name is not a string. |
NOT_FOUND | 404 | The clock does not exist for this team. |
CONFLICT | 409 | The 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}/simulatesessionId is the sessionId of the v2 checkout result (cs_sbx_...). Body:
| Field | Type | Meaning |
|---|---|---|
outcome | string, required | pay, decline, insufficient_funds, require_authentication, cancel, complete_authentication or fail_authentication |
card | string, optional | A 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.status | Fields | When |
|---|---|---|
complete | sessionId, redirectUrl, subscriptionId, paymentId | The payment succeeded and the session is complete. subscriptionId is null for a one-time payment, and paymentId is null when nothing was charged |
canceled | sessionId, redirectUrl, reason (customer_canceled or authentication_failed) | cancel, or a failed authentication |
requires_action | sessionId, paymentId | require_authentication, or a card that needs 3D Secure. Finish with complete_authentication or fail_authentication |
card_error | sessionId, code, declineCode, message | The card was declined. The session stays open and can be paid again with another card |
| Code | Status | Meaning |
|---|---|---|
INVALID_REQUEST | 400 | Unknown outcome, or card is not a card number or is sent with another outcome. |
NOT_FOUND | 404 | The session does not exist for this team. |
SESSION_EXPIRED | 410 | The session is older than 24 hours. |
SESSION_ALREADY_COMPLETE | 409 | The session was already paid. |
SESSION_CLOSED | 409 | The session was canceled or expired. |
AUTHENTICATION_PENDING | 409 | The session waits for 3D Secure; only complete_authentication and fail_authentication apply. |
AUTHENTICATION_NOT_PENDING | 409 | There is no authentication to complete or fail. |
Set a customer's card
POST /teams/{teamId}/sandbox/customers/{customerId}/payment-methodAttaches 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}/refundRefunds 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.