Skip to main content

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)

Midtrans (Secondary Provider)


πŸ“‘ Payment API Endpoints

1. Create Payment Request

Membuat payment request untuk transaksi.
Response (QRIS):
Response (E-Wallet):

2. Get Payment Status

Mengecek status payment request.
Response:

3. Webhook Handler

Endpoint untuk menerima notifikasi dari payment provider.
Response:

4. Simulate Payment (Testing)

Endpoint untuk simulasi pembayaran di environment testing.
Response:

πŸ”§ 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:
  1. Check webhook logs di Xendit dashboard
  2. Verify webhook URL accessible dari internet
  3. Manual check payment status via API
  4. Re-send webhook dari Xendit dashboard

Problem: QR Code Not Generated

Symptoms: Error saat create QR code Solution:
  1. Verify Xendit API key valid
  2. Check amount minimum (Rp 1.500)
  3. Verify currency = β€œIDR”
  4. Check Xendit API status

Problem: Webhook Signature Invalid

Symptoms: Webhook rejected dengan error signature Solution:
  1. Verify webhook token di environment
  2. Check payload format (raw body)
  3. Verify HMAC calculation
  4. Check Xendit webhook settings

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