Payment Gateway Integration
Dokumentasi lengkap integrasi payment gateway di MStore Backend dengan support multi-provider (Xendit & Midtrans).π― Overview
Sistem payment gateway MStore mendukung:- β Multi-Provider: Xendit (primary), Midtrans (secondary)
- β Multi-Channel: QRIS, E-Wallet, Virtual Account, Credit Card
- β Webhook Integration: Real-time payment notification
- β Offline-First: Sync payment saat online kembali
- β Idempotent: Retry-safe operations
- β Audit Trail: Full payment lifecycle tracking
ποΈ Architecture
π³ Supported Payment Methods
Xendit (Primary Provider)
| Method | Channel | Status | Notes |
|---|---|---|---|
| QRIS | QR_CODE | β Production | Dynamic QR via QR Codes API |
| GoPay | EWALLET | β Production | E-Wallet Payment API |
| OVO | EWALLET | β Production | E-Wallet Payment API |
| DANA | EWALLET | β Production | E-Wallet Payment API |
| ShopeePay | EWALLET | β Production | E-Wallet Payment API |
| VA BCA | VIRTUAL_ACCOUNT | β Production | Virtual Account API |
| VA BNI | VIRTUAL_ACCOUNT | β Production | Virtual Account API |
| VA BRI | VIRTUAL_ACCOUNT | β Production | Virtual Account API |
| VA Mandiri | VIRTUAL_ACCOUNT | β Production | Virtual Account API |
| Credit Card | CARDS | β Production | Cards API |
Midtrans (Secondary Provider)
| Method | Channel | Status | Notes |
|---|---|---|---|
| QRIS | QR_CODE | π§ Development | Snap API |
| GoPay | EWALLET | π§ Development | Snap API |
| Credit Card | CARDS | π§ Development | Snap API |
π‘ Payment API Endpoints
1. Create Payment Request
Membuat payment request untuk transaksi.2. Get Payment Status
Mengecek status payment request.3. Webhook Handler
Endpoint untuk menerima notifikasi dari payment provider.4. Simulate Payment (Testing)
Endpoint untuk simulasi pembayaran di environment testing.π§ Implementation Details
Xendit Integration
1. QR Codes API (QRIS)
2. Payment Request API (E-Wallet, VA, Cards)
3. Webhook Handler
Payment Model (Database)
π Security
1. Webhook Verification
2. API Key Management
3. Idempotency
π§ͺ Testing
Unit Test Example
Integration Test with Godog
π Monitoring
Payment Metrics
Grafana Dashboard
- Payment Success Rate:
success_count / total_requests * 100 - Payment Latency: P50, P95, P99 response time
- Webhook Delivery: Success vs Failed
- Provider Availability: Uptime per provider
π‘ Best Practices
DO β
- Simpan full request/response payload untuk audit
- Gunakan idempotency key untuk retry safety
- Verify webhook signature sebelum process
- Handle webhook idempotent (cek duplicate)
- Set proper timeout untuk external API calls
- Monitor payment success rate per provider
- Implement circuit breaker untuk provider failures
DONβT β
- Jangan hardcode API keys di source code
- Jangan skip webhook verification
- Jangan block webhook response (process async)
- Jangan expose payment details di client-side
- Jangan retry webhook infinitely
- Jangan ignore payment expiration
π Troubleshooting
Problem: Payment Stuck in Pending
Symptoms: Status tidak update setelah customer bayar Solution:- Check webhook logs di Xendit dashboard
- Verify webhook URL accessible dari internet
- Manual check payment status via API
- Re-send webhook dari Xendit dashboard
Problem: QR Code Not Generated
Symptoms: Error saat create QR code Solution:- Verify Xendit API key valid
- Check amount minimum (Rp 1.500)
- Verify currency = βIDRβ
- Check Xendit API status
Problem: Webhook Signature Invalid
Symptoms: Webhook rejected dengan error signature Solution:- Verify webhook token di environment
- Check payload format (raw body)
- Verify HMAC calculation
- Check Xendit webhook settings
π Related Documentation
Transaction Flow
Alur transaksi lengkap dengan state machine dan offline-first
Xendit API Reference
Official Xendit documentation
Midtrans API Reference
Official Midtrans documentation
Need Help? Contact backend team atau check GitHub Issues