Guides
Test your billing with test clocks and failure injection
Run renewals, declines, retries, reminders and period ends in seconds. A test clock moves a customer's subscriptions through time with the real billing code; fail_next_charges makes a test card's next charges decline or go unknown. Test mode only.
A test clock is a frozen time that a customer, and every subscription of that customer, lives on. Advancing it walks every renewal, retry, reminder and period end in between with the same billing code that will run on real time: real sandbox charges on the saved test card, real events and real webhooks. Failure injection makes a test card's next billing charges end without reaching the processor, so you can rehearse what your app does on a decline or an unknown outcome.
Both are test mode only. A live key is refused, a clock can never hold a live merchant's customer, and an injected outcome never touches a live card. In this release the scheduler that renews on real time is not switched on, so a test clock is also the only way to see a renewal at all.
1. Create a clock and a customer on it
MCP: create_test_clock. Answer: {id: clock_..., object: test_helpers.test_clock, status: ready, frozen_time}. Start at the current time or close to it.
MCP: create_customer with test_clock. The customer's test_clock names the clock. Save a test card for that customer with no browser (POST /v1/payment_methods or save_payment_method with "nonce": "tok_visa"; or test card 4761739001010010 typed in a browser on sandbox_form_url), then subscribe it: POST /v1/subscriptions (MCP create_subscription) or a subscription-mode checkout session for that customer, paid with POST /v1/test_helpers/checkout/sessions/{id}/confirm and {"card": "tok_visa", "email": "buyer@example.com"} (MCP confirm_checkout_session). The customer above has no email, so the confirm needs email (without it: 400 parameter_missing, param: email); it is ignored when the session's customer has an email or the session has customer_email. The subscription's test_clock names the clock, and its first period starts at the clock's frozen_time.
The create, with the saved card's id (default_payment_method is required; without it the answer is 400 payment_method_required):
2. Advance past the renewal
MCP: advance_test_clock. Choose a time just past current_period_end. The answer comes at once with status: advancing; a worker then processes the clock. Poll GET /v1/test_helpers/test_clocks/{test_clock_id} (MCP get_test_clock) every second or two until status is ready. A clock whose status is internal_failure can never advance again (409 test_clock_internal_failure): stop polling, delete it and create a new one.
An advance can move at most two intervals of the shortest subscription on the clock, or 13 months if that is more (two years with none); further is 400 parameter_invalid on frozen_time. At most 3 clocks of one platform advance at once; a fourth answers 409 test_clock_advance_limit with Retry-After. Advance again for more. A ready clock whose frozen_time is short of your target says why in status_details.last_advance.stopped:
stopped | Meaning | Do |
|---|---|---|
attempt_in_flight | A charge's answer is still coming | A real charge: advance again in a few seconds. After an injected processor_unavailable: resolve the invoice's hold now (step 4), then advance again |
invoice_held | A charge's outcome is unknown, or a duplicate screen is held | Resolve the hold (step 4), then advance again |
billing_paused | Billing is paused for the deployment | Try later |
error | The advance failed; detail says where | Advance again; report it if it repeats |
Then read what happened: get_subscription shows the new period, list_invoices a paid subscription_cycle invoice, and list_events (or your webhook receiver) invoice.upcoming (3 days before the renewal by default), customer.subscription.updated (latest_invoice names the new renewal invoice), invoice.paid, invoice.payment_succeeded and customer.subscription.updated (the new period). integration_checklist marks renew_on_test_clock done.
ready means the billing work is done and its events are written, not that your webhook receiver has them: deliveries go out a few seconds later (usually under 10 seconds; longer while your receiver is failing and being retried). So after ready, wait for the events at your receiver, or read them at once with list_events (GET /v1/events) and since, before you assert on your app's state. GET /v1/webhooks/{webhook_id}/deliveries shows each delivery's status and next_attempt.
Times on a clock: an invoice's created, its periods and the subscription's dates are clock time. The event envelope's own created, and payments, are real time.
3. Rehearse a failed renewal
MCP: fail_next_charges. The next count billing charges of that card (a first payment, a renewal, a retry; 1 to 10) end with outcome and never reach the processor. A second call replaces the first. Then advance past the renewal and through the retries (+1, +3, +7 days by default):
outcome | What you see |
|---|---|
card_declined | A decline: invoice.payment_failed, past_due, retries on schedule, and the final action at the last declined retry. See Failed renewals and retries |
duplicate_transaction | The processor's duplicate screen: never counted as a decline, never retried automatically. The invoice is held (collection_status: reconciling), the subscription gets payment_hold, and the clock stops with invoice_held until you resolve the hold (step 4) |
processor_unavailable | Unknown outcome: the payment stays pending, the invoice is open with collection_status: in_progress and the clock stops with attempt_in_flight. No failure event is sent. Resolve the hold (step 4) to continue; you do not wait for the 15 minutes a real lost answer takes |
lost_card, stolen_card | A hard decline that blocks this card at the merchant: past_due, last_payment_error.decline_code names it, requires_new_payment_method: true, and later retries of this card are skipped |
revocation_of_authorization, stop_payment_order | A hard decline that blocks this card for this subscription |
transaction_not_allowed | A hard decline that blocks this card for this invoice only |
There is no success outcome: a success comes from the card itself (a tok_visa card approves every charge, a typed 4761739001010010 is approved by the sandbox processor). A hard-decline outcome carries the same processor code the real decline carries, so the block, requires_new_payment_method and the events are the real ones; only the processor call is skipped.
The sandbox test cards cannot rehearse a hard decline: 4761739001010010 approves, and 4111111111111111 and 4242424242424242 are declined by the sandbox (reason RISK DECLINED), which billing treats as an ordinary retried decline. No sandbox card is known to answer lost, stolen or revoked. Use the outcomes above for hard declines, or save tok_chargeDeclinedLostCard or tok_chargeDeclinedStolenCard, whose every charge is that hard decline (sandbox, "Test card tokens").
A hard decline leaves the card blocked, and in the sandbox that is usually the one approving card you saved. A block is matched by the card (brand, last four, expiry), and every tok_visa card is Visa 0010 12/2034, so a lost_card or stolen_card rehearsal blocks tok_visa for every customer of that test merchant, a newly saved one too, until you lift it. The checkout confirm helper's 402 payment_method_blocked says so and names lift_card_block. After the rehearsal, lift the block:
MCP: lift_card_block. It lifts every block of that test card at its merchant and returns what it lifted; it charges nothing. Test mode only.
4. End an injected hold
MCP: resolve_invoice_hold. There is no outcome to choose; the attempt always ends as not collected: nothing counted as a decline, never a sale, and a renewal is retried on schedule. Then advance again.
- After
processor_unavailablecall it right away. A real lost answer stayspendingfor 15 minutes of real time before the sweeper ends it; an injected one sent nothing, so the call ends it at once the same way:payment.failed(processor_unverified), acustomer.subscription.updatedthat setspayment_hold, then one that clears it. - After
duplicate_transactionthe call reads the processor back by the charge's reference. No sale (always the case for an injected one): the hold ends with onecustomer.subscription.updatedthat clearspayment_hold(the hold was set when the charge was screened, so no event sets it now). A sale behind a duplicate screen is for ZeroPoint to rule on (409 invoice_hold_has_sale): delete the clock and start a new rehearsal. - A hold on an invoice that is not on a test clock answers
400 invoice_hold_not_injected.
Paying by hand on a clock
A clock's customer lives in the clock's time everywhere billing decides something, the manual pay cap included. The 60 second gap between two payments of one invoice (the portal's "Wait a minute, then try the payment again.", the API's invoice_pay_limit with a short Retry-After) is measured on the clock, so while the clock stands still that gap does not pass. Advance the clock by a minute or more, then pay again. The same holds for the cap's other counts (3 sends per invoice in 24 hours, 10 per card in 30 days).
5. Clean up
DELETE /v1/test_helpers/test_clocks/{test_clock_id} (MCP delete_test_clock) cancels every subscription on the clock, deletes its customers where it can, and deletes the clock. History is kept. A platform keeps at most 100 clocks, and a clock is deleted 30 days after it was created.
A full rehearsal in one pass
create_test_clockat now.create_customerwithtest_clock, save a test card,create_subscription(statusactive).advance_test_clockpastcurrent_period_end;get_test_clockuntilready. Renewal paid.fail_next_chargescard_declinedwithcount: 4.- Advance past the next renewal:
past_due. Events:invoice.upcoming(if the advance passes 3 days before the renewal),customer.subscription.updated(latest_invoice),payment.processing,payment.failed,invoice.payment_failed(attempt_count1),customer.subscription.updated(past_due). - Advance to the first decline plus 1 day, then plus 3 days: each time
payment.processing,payment.failed,invoice.payment_failed; stillpast_due. - Advance to the first decline plus 7 days: the last retry is declined and the final action runs in the same change:
payment.processing,payment.failed,invoice.payment_failed(next_payment_attempt: null,attempt_count4: one per slot, plus one for each declined manual payment if you made any),invoice.marked_uncollectible,customer.subscription.deleted. Advancing further does nothing more.
Each advance that passes 3 days before a renewal sends invoice.upcoming for it (steps 3 and 5). Check that your app sent each email (the last-chance one on the +3 day failure) and revoked access at the end. That is the behaviour your users will see once billing is live.