Sandbox testing guide
Built-in test payment methods + an on-demand simulate endpoint so you can drive every status (paid / failed / expired / refunded / chargeback) and verify your webhook handling end to end.
Sandbox is a fully isolated environment that never touches real money or real providers. It ships with built-in test payment methods and a simulate endpoint so you can create a payment and drive it through every outcome — completed, failed, expired, refunded, chargeback — asserting your webhook handler at each step. No provider credentials, no waiting.
sk_test_… secret key against https://sandbox.key2pay.ai/api/v1. The test methods + simulate endpoint are available in sandbox only.How it works
- List methods → sandbox always returns the built-in test rails below (even before you configure anything).
- Create a payment with a test
paymentMethodId→ it lands aspending. - Call the simulate endpoint to move it to the status your test needs.
- We fire the matching signed webhook(s) to your registered URL; assert + repeat.
sk_test_…key is ALWAYS a sandbox transaction, so it appears in your merchant dashboard's sandbox viewand in the playground's activity feed — regardless of which environment the dashboard toggle is on. Production (sk_live_…) and sandbox data never mix.Test payment methods
GET https://sandbox.key2pay.ai/api/v1/payment-methods returns these in sandbox. They mirror real LATAM rails so your request shape (e.g. PIX/SPEI requiring a buyer documentId) matches production. Any country/method also works — the sandbox cascade always accepts.
| paymentMethodId | Method | Country | Channel |
|---|---|---|---|
| sbx_pix | PIX | Brazil (BRA) | Online |
| sbx_spei | SPEI | Mexico (MEX) | Online |
| sbx_pse | PSE / bank transfer | Colombia (COL) | Online |
| sbx_card | Card | Global (USA) | Card |
| sbx_cash | Cash / OXXO | Mexico (MEX) | Cash |
Simulate endpoint
/api/v1/payments/{id}/simulateDrives a sandbox payment to a terminal status on demand and fires the matching webhook(s). Bearer-authenticated, sandbox-only (refused with 400 in production). Body: { "action": "paid" | "failed" | "expired" | "refunded" | "chargeback" }.
# 1) Create a sandbox payment (lands as "pending"):
curl https://sandbox.key2pay.ai/api/v1/payments \
-H "Authorization: Bearer sk_test_51N8mP...exampleK3Y" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "amount": 50, "paymentMethodId": "sbx_pix", "country": "BRA",
"documentId": "12345678909", "userEmail": "test@test.com" }'
# → { "transactionId": "TXN-…", "status": "pending", … }
# 2) Mark it paid (fires payment.completed to your webhook):
curl https://sandbox.key2pay.ai/api/v1/payments/TXN-XXXX/simulate \
-H "Authorization: Bearer sk_test_51N8mP...exampleK3Y" \
-H "Content-Type: application/json" \
-d '{ "action": "paid" }'
# → { "id":"TXN-XXXX","status":"completed","eventsFired":["payment.completed","payment.captured"] }
# Test a refund (needs a completed tx first):
curl https://sandbox.key2pay.ai/api/v1/payments/TXN-XXXX/simulate \
-H "Authorization: Bearer sk_test_51N8mP...exampleK3Y" \
-d '{ "action": "refunded" }'
# Test a chargeback (mark paid first, then chargeback):
curl https://sandbox.key2pay.ai/api/v1/payments/TXN-XXXX/simulate -d '{ "action": "paid" }' -H "Authorization: Bearer sk_test_51N8mP...exampleK3Y"
curl https://sandbox.key2pay.ai/api/v1/payments/TXN-XXXX/simulate -d '{ "action": "chargeback" }' -H "Authorization: Bearer sk_test_51N8mP...exampleK3Y"Statuses you can simulate
| action | Requires | Result | Webhooks fired |
|---|---|---|---|
| paid | pending | → completed | payment.completed, payment.captured |
| failed | pending | → failed | payment.failed |
| expired | pending | → expired | payment.failed |
| refunded | completed | → refunded | payment.refunded |
| chargeback | completed | stays completed + opens a claim | chargeback.created, claim.opened |
End-to-end walkthrough
- Get an
sk_test_…key from the dashboard (API keys) for your sandbox shop. - Register a webhook URL for the events you want to test (or use a tunnel like ngrok).
GET /payment-methods→ pick a test rail (e.g.sbx_pix).POST /paymentswith thatpaymentMethodId→ get thetransactionId(pending).POST /payments/{id}/simulatewith{"action":"paid"}→ assert you receivedpayment.completed.- Repeat with
failed/expiredon fresh payments, andrefunded/chargebackon a completed one. - When green, flip to production: swap the base URL +
sk_live_…key and drop the simulate calls (production status comes from real providers + signed webhooks).
sandbox.key2pay.ai/sandbox/login lets you paste your sk_test_… to create transactions, flip their status with a click, watch the webhook deliveries — and run "Probar todos los endpoints", a one-click suite that exercises every endpoint above and reports pass/fail per call.