Lewati ke konten

Webhook Handling

Beberapa transaksi SNAP bersifat asinkron — hasilnya dikirim via webhook (HTTP POST) ke URL yang kamu konfigurasi.

Service CodeEventKeterangan
24-35VA PaymentPembayaran virtual account
52QR MPM NotifyNotifikasi pembayaran QRIS
41Bulk Cashin NotifyBulk top-up e-money
21Interbank Bulk NotifyBulk transfer interbank
56Direct Debit NotifyNotifikasi direct debit

Di dashboard, buka Webhooks dan tambahkan URL callback:

  • Provider: Pilih provider (BCA, BRI, dll)
  • Service Code: Pilih jenis notifikasi
  • Notify URL: URL endpoint kamu (harus HTTPS di production)

Setiap webhook menyertakan header X-SIGNATURE yang ditandatangani dengan RSA server key.

import crypto from 'crypto';
app.post('/webhook/snap', (req, res) => {
const signature = req.headers['x-signature'];
const timestamp = req.headers['x-timestamp'];
// String to sign = method + ":" + path + ":" + body + ":" + timestamp
const body = JSON.stringify(req.body);
const stringToSign = `POST:${req.path}:${body}:${timestamp}`;
// Verify with server's public key
const isValid = crypto.verify(
'sha256',
Buffer.from(stringToSign),
serverPublicKey,
Buffer.from(signature, 'base64')
);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process webhook
console.log('Webhook received:', req.body);
res.json({ responseCode: '00', responseMessage: 'Success' });
});

Gunakan Testing Console di admin panel untuk mengirim webhook manual dengan berbagai outcome (success, pending, failed, expired).