Sandbox

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.

Use an sk_test_… secret key against https://sandbox.key2pay.ai/api/v1. The test methods + simulate endpoint are available in sandbox only.

How it works

  1. List methods → sandbox always returns the built-in test rails below (even before you configure anything).
  2. Create a payment with a test paymentMethodId → it lands as pending.
  3. Call the simulate endpoint to move it to the status your test needs.
  4. We fire the matching signed webhook(s) to your registered URL; assert + repeat.
Where it shows up.The transaction's environment follows the KEY: a charge with an 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.

paymentMethodIdMethodCountryChannel
sbx_pixPIXBrazil (BRA)Online
sbx_speiSPEIMexico (MEX)Online
sbx_psePSE / bank transferColombia (COL)Online
sbx_cardCardGlobal (USA)Card
sbx_cashCash / OXXOMexico (MEX)Cash

Simulate endpoint

POST/api/v1/payments/{id}/simulate

Drives 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" }.

bash
# 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

actionRequiresResultWebhooks fired
paidpending→ completedpayment.completed,
payment.captured
failedpending→ failedpayment.failed
expiredpending→ expiredpayment.failed
refundedcompleted→ refundedpayment.refunded
chargebackcompletedstays completed + opens a claimchargeback.created,
claim.opened
Need fixed delays instead of on-demand control (e.g. CI that waits for a webhook)? Use the Sandbox-Simulate header on the create call instead.

End-to-end walkthrough

  1. Get an sk_test_… key from the dashboard (API keys) for your sandbox shop.
  2. Register a webhook URL for the events you want to test (or use a tunnel like ngrok).
  3. GET /payment-methods → pick a test rail (e.g. sbx_pix).
  4. POST /payments with that paymentMethodId → get the transactionId (pending).
  5. POST /payments/{id}/simulate with {"action":"paid"} → assert you received payment.completed.
  6. Repeat with failed / expired on fresh payments, and refunded / chargeback on a completed one.
  7. 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).
Prefer a UI? The interactive sandbox at 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.