
A payment gateway integration is not finished when the happy path returns “success.” Customers retry, banks decline, webhooks arrive late, and refunds must land on the same ledger entry as the original charge. Testing has to follow that path in a sandbox before any live key is used.
Your system and the gateway share a small contract:
Tests should assert your order and ledger, not only the gateway’s demo page.
Use the gateway sandbox, test cards, and a webhook endpoint that only the sandbox can reach. Keep live keys out of CI and out of developer laptops that run automated suites.
Give every test its own order id and idempotency key. A reused key hides double-submit bugs or, worse, makes a retry look like a pass when the second call never created a payment.
Success. Pay with a test card, receive the success webhook, mark the order paid, store the provider reference, write one ledger line.
Decline. Insufficient funds or a generic decline. The order stays unpaid. No capture. The customer sees a reason they can act on, not a stack trace.
Authentication. When 3-D Secure or a similar step applies, cover both a completed challenge and an abandoned one. Abandoned must not capture.
Timeout and retry. The customer submits twice, or your server times out and retries. One idempotency key means one payment at the gateway.
Webhook problems. Duplicate delivery, delivery before you have saved the payment row, and a signature that does not match. Invalid signatures are rejected. Duplicates do not double-post.
Refund and void. Full refund, partial refund, and void-before-capture if the gateway supports it. The ledger amount must match the gateway amount.
Amount mismatch. If the webhook amount differs from the order, fail closed and alert. Do not mark the order paid.
Sandbox payment created
↓
Auth / challenge / decline
↓
Webhook signature checked
↓
Order + ledger updated once
↓
Refund or void references the same payment
↓
Gateway record and your ledger agree
After each case, check:
Query the gateway for the payment when you need a second source of truth. A green button on the return URL is not evidence.
Do not point load tests at the sandbox and call that gateway certification. Rate limits there are not your production ceiling. Do not run this suite against live cards “just once.” Settlement, chargeback, and payout reports stay in a separate reconciliation test with fixture files.
Keep a short matrix: gateway, case, expected order status, expected ledger outcome. When the gateway changes an event name, that matrix is what you update first.
Test the gateway as a contract: sandbox keys, unique idempotency keys, signed webhooks, and a ledger that agrees with the provider. Success, decline, retry, and refund belong in the suite. The return URL alone does not.
At KIS Technology, we help businesses transform their ideas into secure and scalable digital solutions through software development, API integration, and quality engineering.
Build smarter. Build securely. Build for growth.
Connect with our Founder: