3 min read
Payment Gateway Integration Guide for Apps in Indonesia
What Problem Does a Payment Gateway Solve
Without a gateway, you would have to build integrations with every bank and digital wallet provider yourself — contracts, certificates, and per-channel maintenance. A gateway like Midtrans or Xendit compresses all of that into one API: customers are free to choose a payment method, and your app only needs to respond to the payment status.
Payment Channels That Matter in Indonesia
- Virtual Account (VA) — the most dominant for e-commerce and B2B SaaS; fixed amount, automatic confirmation, flat and cheap per-transaction fees.
- QRIS — strong for mobile customers and offline-to-online transactions; scan from any bank/e-wallet app.
- Digital wallets (GoPay, OVO, ShopeePay, DANA) — important if your customer base buys retail through their phones.
- Credit cards — needed for B2B SaaS and large transaction values; chargeback risk and higher percentage fees.
- Physical outlets (Alfamart, Indomaret) — relevant when your customers do not yet have a bank account.
Rule of thumb: start with 2–3 channels that your target market actually uses. Every channel adds cost, testing flow, and reporting complexity.
The Common Mistake: Trusting the Frontend Response
This is the most common and most dangerous mistake. When a customer presses "Pay", the browser says "success" — but the only trustworthy source is the notification from the gateway server, not the frontend callback.
The correct flow:
- The app creates a transaction with the gateway (server-side) and stores its ID.
- The customer completes payment on the gateway's page/overlay.
- The gateway sends a webhook to your server: "transaction X status paid".
- The server verifies the webhook's security signature (signature/HMAC), matches the amount, and only then marks the order as paid.
- The frontend only displays the status requested from your server — not from the browser response.
Without steps 3–4, an order could be "paid" by replaying the success page.
Reconciliation and Pending Statuses
Some channels (especially manual transfers and outlets) have delayed confirmation. Therefore:
- Store transaction status as a state machine (
pending → paid / expired / failed / refunded), not ais_paidboolean. - Run a daily match between orders in your database and the gateway's settlement report — small discrepancies not found this week become hard to trace next month.
- Prepare refund flows and revoke access/fulfillment when the status changes to refunded.
Test Before Production
All gateways provide a sandbox mode. At minimum, test these scenarios before going live:
- A fully successful payment (until the webhook arrives).
- An expired transaction.
- A webhook sent twice (must be idempotent — the status must not change twice).
- A webhook with a mismatched amount (must be rejected).
Costs to Assume
Each provider's fee structure differs (flat per VA, percentage per card, QRIS MDR). The exact numbers change, so check the latest rate tables on the official Midtrans/Xendit sites and put them into the project cost estimate — do not copy numbers from any article, including this one.
Conclusion
Payment integration is 20% API hookup, 80% status discipline: verified webhooks as the single source of truth, a clear state machine, and routine reconciliation. If you need the implementation, we cover it in our Payment Integration service.