Contoh memakai domain
https://pay.tokomu.id. Ganti dengan domain Pages milikmu.Node.js (fetch)
async function createInvoice(amount, orderId) {
const r = await fetch('https://pay.tokomu.id/api/invoices', {
method: 'POST',
headers: { 'X-API-Key': process.env.NIGANA_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ amount, order_id: orderId, description: 'Pesanan ' + orderId })
});
const data = await r.json();
if (!r.ok) throw new Error(data.error); // 409 bila nominal sedang dipakai
return data; // { id, pay_url, expires_at, ... }
}
PHP
<?php
$ch = curl_init('https://pay.tokomu.id/api/invoices');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('NIGANA_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['amount' => 25000, 'order_id' => 'INV-1001']),
]);
$res = json_decode(curl_exec($ch), true);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code !== 201) { throw new Exception($res['error'] ?? 'Gagal'); }
header('Location: ' . $res['pay_url']);
// Verifikasi webhook
$raw = file_get_contents('php://input');
$mine = hash_hmac('sha256', $raw, getenv('NIGANA_WEBHOOK_SECRET'));
if (!hash_equals($mine, $_SERVER['HTTP_X_SIGNATURE'] ?? '')) { http_response_code(401); exit; }
Python (requests)
import os, hmac, hashlib, requests
r = requests.post(
"https://pay.tokomu.id/api/invoices",
headers={"X-API-Key": os.environ["NIGANA_API_KEY"]},
json={"amount": 25000, "order_id": "INV-1001", "description": "Kopi susu"},
timeout=15,
)
r.raise_for_status()
print(r.json()["pay_url"])
# Verifikasi webhook (Flask)
def verify(raw: bytes, signature: str) -> bool:
mine = hmac.new(os.environ["NIGANA_WEBHOOK_SECRET"].encode(), raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(mine, signature or "")
cURL: daftar invoice lunas
curl "https://pay.tokomu.id/api/invoices?status=paid&limit=20" -H "X-API-Key: $NIGANA_API_KEY"
Simpan API key dan secret webhook di variabel lingkungan atau secret manager, bukan di dalam kode.