Test mode
What the sandbox simulates, how to choose a payment's outcome, how to get an invoice now, and what only live does.
Every app has two environments: a sandbox, where nothing is real, and live. You integrate against the sandbox, then switch the key and the address of the code to live.
What the sandbox is
| Sandbox | Live | |
|---|---|---|
| Key | prk_test_ | prk_live_ |
| Payments | A simulator, never a real provider | Real payment providers |
| Customer e-mail | [SANDBOX] prefix, sent to a sink | Real customer e-mail |
| Invoice numbers | Their own series (SBX-...), watermark on the PDF | The live invoice numbers |
| Period close | Now, on request | At the end of the billing period |
| Dunning retries | Compressed to minutes | The configured retry schedule |
idempotency_key on events | Optional | Required |
Same API, same code, a different key. The two share no data, and nothing sent from the sandbox reaches a real customer.
Include idempotency_key on sandbox events anyway, so your code is the code you ship. See Idempotency.
Choosing how a payment goes
Give a sandbox customer a payment method from GET /v1/sandbox/scenarios, or set it with POST /v1/sandbox/customers/{external_id}/payment-scenario (for example {"scenario": "declined"}).
Each pm_sandbox_* method makes the payment take one path, so you can see how your app behaves when a charge:
- succeeds,
- is declined,
- is declined once and then succeeds,
- fails with an error and then succeeds,
- times out, whether or not it went through.
Getting an invoice now
Set up a customer with usage
Create a customer, subscribe it to a package, and send some usage. Usage-based billing, end to end does it step by step.
Close the period
POST /v1/sandbox/close-period closes the period right away and runs the real billing flow: cutoff, rating, numbering and the payment saga with the simulator. It answers 202; poll GET /v1/invoices until the invoice is there.
Run the payment again, if you want another outcome
POST /v1/sandbox/invoices/{id}/simulate sets the customer's scenario and retries the invoice's payment.
Webhooks are sent from the sandbox too, so you can test your receiver end to end. Send a test webhook on the console's Connect your app page sends a signed ping to an endpoint (see Webhooks and Receive webhooks on your machine).
What only live does
- A live environment starts inactive and is switched on by a go-live checklist (the seller's billing profile, a connected payment provider, accepted terms). Until then it has no keys: creating one is refused with
plans.api_key.tenant_not_active. - Real payment providers, real customer e-mail and the live invoice numbers.
The sandbox routes (/v1/sandbox/*) answer 403 to a live key.
Promoting the sandbox to live
The console can promote the sandbox configuration to live so you do not rebuild it by hand: meters, plans and their prices, tax rates, coupons, mail settings and webhook endpoints (never customers, usage, invoices or payments). It only adds and matches objects by their code, so running it again does nothing, and a dry run shows the difference first.
Test the same flow once more in live with a small real payment before you send customers there.