Platform
Testing & Debugging
Understand exactly what test mode simulates, how to exercise your webhook handlers, how to test gateway outcomes, and how to read API errors.
Test mode vs Live mode
Test or live is an account-level setting. New accounts start in test mode so you can try hosted checkout before connecting a gateway. Switch modes under Developers > Developer Settings (the Environment card); while in test mode, a banner at the top of the dashboard links there. The change applies to your whole account immediately.
| Property | Test mode | Live mode |
|---|---|---|
| Hosted checkout payments | Simulated. No gateway is called; the payment is recorded as success with gateway ph_test. | Routed to your gateway connections whose mode is live. |
| Payments API | Not simulated: routed only to your sandbox (non-live) gateway connections. | Routed only to your gateway connections whose mode is live. |
| Payment link direct pay | Not simulated: routed to your active gateway connections, sandbox or live. | Routed to your active gateway connections, sandbox or live. |
| API keys | Same keys as live mode | Same keys as test mode |
| Response livemode field | false | true |
| Data | Shared with live mode | Shared with test mode |
| Dashboard indicator | Test badge in the top bar | Live badge in the top bar |
In test mode, hosted checkout (/checkout/:sessionId) simulates the charge. Payments created with POST /api/v1/payments are sent to a real gateway, but only to sandbox connections while you are in test mode and only to live connections while you are in live mode, so a test-mode API payment can never charge a live gateway. Passing a gatewayId that has no connection in the current mode returns 422 GATEWAY_NOT_CONNECTED. Payments made through the payment link direct pay endpoint are sent to the gateway connection chosen by your routing rules in either mode.
Card details in test mode
In test mode, a hosted checkout payment succeeds whenever the customer submits an email address and the fraud check allows it. No gateway is contacted, so the card number, expiry and CVC do not influence the outcome. Simulated payments are recorded with status success, gateway ph_test, zero fees, and metadata.testMode = "true", and the session is marked complete.
Test webhook events
Use the webhook simulator to send a synthetic event to one of your registered endpoints without creating a payment:
- 1Open Developers → Webhooks in your merchant dashboard and select the Simulator tab.
- 2Choose one of your registered endpoints and an event type.
- 3Click Send Test Event. The event is delivered to the endpoint over HTTPS.
- 4Inspect the result and the Delivery Logs tab to see the status code and response body your server returned.
The simulator accepts up to 20 events per minute per dashboard session. A simulated test-mode checkout also sends real events with livemode: false: checkout.session.completed and payment.succeeded to your registered endpoints, and checkout.session.completed to the checkout session's webhookUrl when you set one. Every delivery uses this envelope (abbreviated):
{"id": "ph_evt_5f0c2a9e41b7d3c8a6e1f0247b9d3e5a","object": "event","api_version": "2026-04-22","created": 1792771200,"type": "payment.succeeded","data": {"object": {"object": "payment_intent","amount": 4999,"currency": "usd","amount_usd_cents": 4999,"usd_to_local_currency_rate": 1,"status": "succeeded"}},"request": { "id": null, "idempotency_key": null }}
Testing declines and 3DS
PaymentHooks does not simulate declines, 3D Secure challenges or other failure outcomes: there are no magic card numbers or amounts. Test-mode hosted checkout always simulates a successful payment.
To exercise real decline and authentication paths, connect a gateway using that gateway's own sandbox credentials, keep your account in test mode, send a payment through it (for example with POST /api/v1/payments, optionally forcing the connection with gatewayId), and use the gateway's sandbox cards. The outcome is then decided by the gateway's sandbox, not by PaymentHooks. See Gateway sandbox cards for the numbers each gateway publishes.
Debugging checklist
If your integration is not behaving as expected, work through the following common causes before opening a support ticket.
Authentication fails (401)
Server requests must send your secret key (phk_live_ prefix) as Authorization: Bearer phk_live_... or in the x-api-key header. The phk_live_ prefix identifies a secret key; it does not mean the account is in live mode. Publishable keys start with phk_pub_.
Missing or invalid parameters (400 VALIDATION_ERROR)
Read error.fields: it maps each invalid field path to a message. A common omission is customerId on POST /payments, which is required.
Webhook signature verification failures
Hash the raw request body bytes before any JSON parsing, and use the right secret: registered endpoints are signed with that endpoint's signing secret, per-session webhooks with your session webhook secret.
Currency codes
Send a 3-letter ISO 4217 code. Checkout sessions and payment links upper-case it for you; send uppercase codes (USD, EUR, INR) everywhere so stored values are consistent.
Idempotency key conflicts (409)
On POST /payments the key is the idempotencyKey body field; reusing it with a different body returns 409 IDEMPOTENCY_CONFLICT. Refund, capture, checkout session, subscription and webhook endpoint creation read the Idempotency-Key header and replay the first response with X-Idempotent-Replayed: true.
Hosted checkout payment rejected (402 FRAUD_BLOCKED)
Fraud screening runs before every hosted checkout charge, including simulated test-mode charges. error.details lists the score and the rules that fired. If fraud screening itself is unavailable, the charge is rejected with 500 INTERNAL_ERROR rather than sent unscreened.
Error response format
Every API response uses the same envelope. On failure data is null and error is populated, alongside a 4xx or 5xx status code:
{"data": null,"error": {"code": "VALIDATION_ERROR","message": "Customer ID is required","fields": { "customerId": "Customer ID is required" }}}
| Field | Type | Description |
|---|---|---|
| code | string | Machine-readable error code, for example VALIDATION_ERROR, UNAUTHORIZED, NOT_FOUND or RATE_LIMITED. Branch on this value. |
| message | string | Human-readable explanation for logs. Do not show it verbatim to customers. |
| fields | object (optional) | Present on validation errors: maps each invalid field path to its message. |
| details | object (optional) | Extra structured context for some errors, for example the fraud score on FRAUD_BLOCKED. |