API Documentation

Panduan lengkap untuk mengintegrasikan PayGate payment gateway.

Authentication

Semua request API memerlukan header X-API-Key dan X-Signature.

Signature dibuat dengan HMAC-SHA256 dari request body menggunakan secret key:

Node.js - Generate Signature
const crypto = require('crypto');

function generateSignature(body, secretKey) {
  return crypto
    .createHmac('sha256', secretKey)
    .update(JSON.stringify(body))
    .digest('hex');
}

Create Payment

POST/api/v1/payment/create

Buat pembayaran baru via QRIS atau Binance Pay.

Request Body
{
  "amount": 50000,
  "method": "QRIS",
  "reference": "ORDER-001",
  "description": "Pembelian produk"
}
curl
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"
  }'
Node.js
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);
Response (QRIS)
{
  "success": true,
  "data": {
    "txId": "tx_abc123def456",
    "method": "QRIS",
    "amount": 50000,
    "qrImageUrl": "https://...",
    "qrString": "00020101...",
    "expiresAt": "2025-01-01T01:00:00.000Z",
    "status": "PENDING"
  }
}
Response (Binance)
{
  "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"
  }
}

Check Payment Status

GET/api/v1/payment/status?txId=tx_abc123

Cek status pembayaran berdasarkan TX ID.

curl
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"
Response
{
  "success": true,
  "data": {
    "txId": "tx_abc123",
    "status": "SUCCESS",
    "amount": 50000,
    "method": "QRIS",
    "paidAt": "2025-01-01T00:30:00.000Z"
  }
}

Cancel Payment

POST/api/v1/payment/cancel

Batalkan pembayaran yang masih PENDING.

curl
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" }'

Verify Binance Payment

POST/api/v1/payment/verify-binance

Verifikasi manual pembayaran Binance Pay.

curl
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" }'

Webhook

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.

Webhook Payload
{
  "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"
  }
}
Node.js - Verify Webhook
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 Codes

StatusDeskripsi
PENDINGMenunggu pembayaran
SUCCESSPembayaran berhasil
EXPIREDPembayaran kedaluwarsa
FAILEDPembayaran gagal
CANCELLEDPembayaran dibatalkan

Butuh bantuan integrasi?

Daftar & Mulai Integrasi