What to Expect from Payment Gateway Integration
Capture, webhooks, reconcile, refunds, and test mode — the operational contract behind “add Razorpay / Stripe,” not a checkout button mockup.
Robin Singh · Published 24 July 2026 · 5 min read
Integrating a payment gateway (such as Stripe, Razorpay, Adyen, or PayU) is never just embedding a JavaScript SDK and dropping a "Pay Now" button into a checkout template. A production payment pipeline is a mission-critical distributed state machine: payment intent creation, 3D Secure redirects, asynchronous cryptographic webhooks, funds capture, partial refunds, chargeback dispute handling, and automated daily bank reconciliation. Palmate’s e-commerce development and API integration practice budgets for this entire ledger lifecycle, ensuring financial consistency under peak traffic.
You can evaluate integration complexity using our API project estimator. A payment gateway is not a single API; it is a multi-directional event exchange between your customer's browser, your application server, the payment processor, and issuing bank networks.
The Browser Redirect Is a Hint; The Webhook Is the Ledger
A foundational architectural flaw in naive payment integrations is trusting the client browser to confirm payment success:
[User Browser] ---> (Completes 3DS Auth) ---> [Redirects to /checkout/success]
If your server marks an order as "PAID" solely because the customer arrived at the /checkout/success redirect URL:
- A shopper who closes their mobile browser tab immediately after seeing their bank confirmation screen will have their money deducted, but your server will leave the order marked as "UNPAID" (an orphaned charge).
- A malicious actor can inspect network traffic, forge the redirect URL parameters, and trigger order fulfillment without ever transferring funds.
The True Ledger Pattern
The customer redirect URL should only display a "Processing Payment..." polling state. The signed server-to-server webhook is the only authoritative event that triggers database mutations, captures funds, reserves warehouse inventory, and issues customer receipts:
- The gateway dispatches an encrypted webhook payload (
payment_intent.succeededororder.paid). - Your server validates the cryptographic HMAC signature (
X-Razorpay-SignatureorStripe-Signature). - Your server checks the event ID against an idempotency table to prevent duplicate execution.
- Your server immediately returns HTTP 200 OK to acknowledge receipt.
- A background worker commits the database transaction and triggers downstream fulfillment.
Review our technical guide on REST vs webhooks vs polling for architectural details on fast ACK processing.
The Payment State Machine
Your relational database must track payment status independently from order fulfillment status. Map external gateway statuses into an explicit internal state machine:
[CREATED] ──> [AUTHENTICATING] ──> [AUTHORIZED] ──> [CAPTURED] ──> [SETTLED]
│ │ │ │
├──> [EXPIRED] └──> [FAILED] └──> [VOIDED] ├──> [PARTIALLY_REFUNDED]
├──> [REFUNDED]
└──> [DISPUTED]
| Internal State | Trigger Condition | System Action | Inventory Action |
|---|---|---|---|
| Created / Pending | Shopper initiates checkout; Intent generated. | Record order draft with checkout TTL. | Temporary Soft Hold on ATP. |
| Authorized | Bank approves hold on funds (two-step capture). | Await manual review or automated fraud check. | Soft Hold maintained. |
| Captured | Funds successfully captured by merchant. | Convert draft to confirmed order; issue invoice. | Convert to Hard Allocation. |
| Failed | Card declined, insufficient funds, or 3DS timeout. | Present clear user error; prompt for alternate method. | Release Soft Hold to ATP. |
| Refunded | Admin issues full or partial refund. | Credit ledger; generate credit note. | Restock to physical inventory if items returned. |
| Disputed / Chargeback | Customer files dispute with card issuer. | Flag order; freeze customer account; notify finance. | No change (goods already shipped). |
Ensure that customer-facing errors distinguish operational failures from cardholder issues. As detailed in how to design API error handling that operations can use, an expired card or insufficient balance should prompt for another payment method, whereas an HTTP 504 from the gateway should trigger an automatic retry.
The Midnight Reconciliation Worker: Catching Missed Events
Webhooks are delivered over public networks and can occasionally fail: Cloudflare rate limits, DNS glitches, or brief application restarts can result in missed notifications. If a webhook drops, an order can remain stuck in "Pending" forever while customer funds sit captured at the gateway.
A robust architecture implements an automated reconciliation cron running every 15 to 60 minutes:
- Query Pending Transactions: The worker selects all orders created more than 15 minutes ago with status
PENDINGorAUTHORIZED. - Gateway Verification: For each record, the worker calls the gateway's REST API (
GET /v1/payment_intents/{id}) to poll current status directly. - State Catch-Up: If the gateway reports the payment succeeded, the worker replays the capture workflow, updates the internal ledger, and triggers fulfillment.
- Stale Expiration: If the gateway reports the transaction expired or was abandoned, the worker cancels the order and releases reserved inventory.
This guarantees that stock is never permanently trapped in limbo and ensures zero lost orders.
PCI-DSS Scope: Hosted Elements vs. Direct Vaulting
Small and mid-sized businesses should never handle raw Primary Account Numbers (PAN), CVVs, or expiration dates on their own servers. Doing so subjects your company to PCI-DSS SAQ-D compliance audits, specialized vulnerability scans, and severe legal liability.
- SAQ-A Compliant (Recommended): Use hosted payment fields (Stripe Elements, Razorpay Checkout, Adyen Drop-in). Card inputs render inside secure iframes hosted directly on the gateway's PCI-certified domain. Tokenized references (
tok_1N...) are returned to your frontend, and your servers only ever handle non-sensitive tokens. - Card Vaulting (SAQ-D): Only necessary if your business operates as a licensed payment aggregator or banking institution. Building direct card capture requires isolated hardware security modules (HSMs) and extensive quarterly compliance audits.
Refund Workflows and Multi-Currency Settlements
Refunds introduce operational edge cases that must be governed in software:
- Partial Refunds: When an order contains multiple line items and one is out of stock, your system must support refunding a specific amount while keeping the remaining order active. Avoid tying order totals to a single rigid payment identifier.
- Settlement Lag: A gateway transaction marked "Paid" on Monday may not deposit into your corporate bank account until Wednesday (T+2 settlement cycles). Your accounting exports must separate gross customer charges from net bank deposits after gateway processing fees.
A payment integration is finished when finance can reconcile every rupee or dollar on the bank statement with a specific order ID in your database, and when an engineer can disconnect the network during checkout without losing state. If you are building or refactoring a payment pipeline, evaluate your system with our API project estimator or contact Palmate for an e-commerce architecture review.
Authoritative References & Standards
To cross-reference the engineering patterns and regulatory considerations described in this guide, consult the following authoritative industry documentation and RFC standards:
- PCI Security Standards Council (PCI-DSS) — Global data security standards for payment card processing and tokenization.
- W3C Web Payments Architecture — Technical specifications streamlining checkout workflows across web platforms.
