Panduan lengkap untuk mengintegrasikan PayGate payment gateway.
Semua request API memerlukan header X-API-Key dan X-Signature.
Signature dibuat dengan HMAC-SHA256 dari request body menggunakan secret key:
const crypto = require('crypto');
function generateSignature(body, secretKey) {
return crypto
.createHmac('sha256', secretKey)
.update(JSON.stringify(body))
.digest('hex');
}/api/v1/payment/createBuat pembayaran baru via QRIS atau Binance Pay.
{
"amount": 50000,
"method": "QRIS",
"reference": "ORDER-001",
"description": "Pembelian produk"
}curl -X POST https://paygate.example.com/api/v1/payment/create \
-H "Content-Type: application/json" \
-H "X-API-Key: pg_your_api_key" \
-H "X-Signature: your_signature" \
-d '{
"amount": 50000,
"method": "QRIS",
"reference": "ORDER-001",
"description": "Pembelian produk"
}'const crypto = require('crypto');
const API_KEY = 'pg_your_api_key';
const SECRET_KEY = 'sk_your_secret_key';
const body = {
amount: 50000,
method: 'QRIS',
reference: 'ORDER-001',
description: 'Pembelian produk',
};
const signature = crypto
.createHmac('sha256', SECRET_KEY)
.update(JSON.stringify(body))
.digest('hex');
const res = await fetch('https://paygate.example.com/api/v1/payment/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': API_KEY,
'X-Signature': signature,
},
body: JSON.stringify(body),
});
const data = await res.json();
console.log(data);{
"success": true,
"data": {
"txId": "tx_abc123def456",
"method": "QRIS",
"amount": 50000,
"qrImageUrl": "https://...",
"qrString": "00020101...",
"expiresAt": "2025-01-01T01:00:00.000Z",
"status": "PENDING"
}
}{
"success": true,
"data": {
"txId": "tx_abc123def456",
"method": "BINANCE",
"amount": 50000,
"binanceAmount": 3.12,
"checkoutUrl": "https://pay.binance.com/...",
"expiresAt": "2025-01-01T01:00:00.000Z",
"status": "PENDING"
}
}/api/v1/payment/status?txId=tx_abc123Cek status pembayaran berdasarkan TX ID.
curl -X GET "https://paygate.example.com/api/v1/payment/status?txId=tx_abc123" \
-H "X-API-Key: pg_your_api_key" \
-H "X-Signature: your_signature"{
"success": true,
"data": {
"txId": "tx_abc123",
"status": "SUCCESS",
"amount": 50000,
"method": "QRIS",
"paidAt": "2025-01-01T00:30:00.000Z"
}
}/api/v1/payment/cancelBatalkan pembayaran yang masih PENDING.
curl -X POST https://paygate.example.com/api/v1/payment/cancel \
-H "Content-Type: application/json" \
-H "X-API-Key: pg_your_api_key" \
-H "X-Signature: your_signature" \
-d '{ "txId": "tx_abc123" }'/api/v1/payment/verify-binanceVerifikasi manual pembayaran Binance Pay.
curl -X POST https://paygate.example.com/api/v1/payment/verify-binance \
-H "Content-Type: application/json" \
-H "X-API-Key: pg_your_api_key" \
-H "X-Signature: your_signature" \
-d '{ "txId": "tx_abc123" }'PayGate mengirim POST request ke webhook URL Anda saat status pembayaran berubah. Set webhook URL di halaman Pengaturan.
Header X-Webhook-Signature berisi HMAC-SHA256 dari body menggunakan secret key Anda untuk verifikasi.
{
"event": "payment.success",
"data": {
"txId": "tx_abc123def456",
"reference": "ORDER-001",
"amount": 50000,
"method": "QRIS",
"status": "SUCCESS",
"fee": 200,
"netAmount": 49800,
"paidAt": "2025-01-01T00:30:00.000Z"
}
}const crypto = require('crypto');
function verifyWebhook(body, signature, secretKey) {
const expected = crypto
.createHmac('sha256', secretKey)
.update(JSON.stringify(body))
.digest('hex');
return signature === expected;
}
// Express.js example
app.post('/webhook', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const isValid = verifyWebhook(req.body, signature, SECRET_KEY);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process the webhook
const { event, data } = req.body;
if (event === 'payment.success') {
console.log('Payment success:', data.txId);
}
res.json({ received: true });
});| Status | Deskripsi |
|---|---|
| PENDING | Menunggu pembayaran |
| SUCCESS | Pembayaran berhasil |
| EXPIRED | Pembayaran kedaluwarsa |
| FAILED | Pembayaran gagal |
| CANCELLED | Pembayaran dibatalkan |
Butuh bantuan integrasi?
Daftar & Mulai Integrasi