Your first test payment, end to end
The whole integration in the sandbox — nothing here moves money. Follow it once with a test key, then repeat with a live key after verification.
What you need
A developer account and a test key (Getting started). For the webhook steps, a public HTTPS URL that reaches your machine (a tunnelling tool works for local development).
A. Register and create test credentials
Register, keep the dashboard switch on Test, and create a key with the scopes CHARGES_READ, CHARGES_WRITE, PAYMENT_LINKS_READ, PAYMENT_LINKS_WRITE. Export it as SENDJOOR_SECRET_KEY.
B. Make a test API request
curl -X GET "https://api.developers.sendjoor.com/v1/payment-links?limit=5" \
-H "Authorization: Bearer $SENDJOOR_SECRET_KEY"C. Create a charge — the payment link comes with it
Use your own order id as the reference. No payment method or link option is needed: every charge comes back with its hosted paymentUrl.
curl -X POST "https://api.developers.sendjoor.com/v1/charges" \
-H "Authorization: Bearer $SENDJOOR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"reference": "ORDER-1001",
"amountKobo": 500000,
"customer": {
"email": "buyer@example.com"
},
"title": "Order #1001",
"successUrl": "https://shop.example.com/orders/1001/thanks",
"metadata": {
"orderId": "1001"
}
}'Store the response's id with your order (you can also always look it up by reference). If the request times out, send it again with the same reference: you get either the charge or 409 DUPLICATE_REFERENCE naming it — never a second charge. Want one reusable page for many payers instead? Create a payment link.
D. Share the link and pay in the sandbox
Send paymentUrl to the customer (email, SMS, WhatsApp) or redirect them to it. In the sandbox it shows a TEST MODE banner, your business name, your reference and the amount; the charge has already settled, so the page shows the receipt and a button back to your successUrl — with ?reference=ORDER-1001&chargeId=…&status=success appended. Treat that redirect as a hint to check, never as proof.
| To test… | Use |
|---|---|
| A successful payment | Any amount except ₦2 and ₦3 |
| A declined payment (charge.failed) | Exactly ₦2 (amountKobo: 200) |
| A payment that stays pending | Exactly ₦3 (amountKobo: 300) |
The magic amounts are your price before Sendjoor's fee.
E. Verify the final status by reference (or id)
curl -X POST "https://api.developers.sendjoor.com/v1/charges/reference/ORDER-1001/verify" \
-H "Authorization: Bearer $SENDJOOR_SECRET_KEY"This asks the bank, server to server. Release goods only when status is SUCCESS, settled is true, and reference, amountKobo and currency match your order. POST /v1/charges/{id}/verify returns exactly the same charge.
F. Receive and verify a signed webhook
In the dashboard (Test), open Webhooks, register your HTTPS URL and copy its signing secret into SENDJOOR_WEBHOOK_SECRET. Press Send test event to receive a signed webhook.test event — your verification code must accept it. Then create another test charge: you'll receive charge.settled (and charge.failed for ₦2).
G. Deduplicate and update your order
// server.js — a complete, working receiver (Node 18+, Express)
const express = require("express");
const crypto = require("crypto");
const app = express();
// 1. Verify the signature on the RAW body (before any JSON parsing).
function verify(rawBody, header, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries((header || "").split(",").map((p) => p.split("=")));
if (!/^\d+$/.test(parts.t || "") || !/^[0-9a-f]{64}$/.test(parts.v1 || "")) return false;
if (Math.abs(Date.now() / 1000 - Number(parts.t)) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
app.post("/webhooks/sendjoor", express.raw({ type: "application/json" }), async (req, res) => {
const raw = req.body.toString("utf8");
if (!verify(raw, req.get("X-Sendjoor-Signature"), process.env.SENDJOOR_WEBHOOK_SECRET)) {
return res.status(400).send("bad signature");
}
const event = JSON.parse(raw);
// 2. Deduplicate: the same event id can arrive more than once.
if (await db.processedEvents.exists(event.id)) return res.sendStatus(200);
// 3. Act on the facts in the event, keyed by YOUR reference. Check the amount
// too — never fulfil an order for less than its price.
const { reference, amountKobo, currency } = event.data;
if (event.type === "charge.settled" || event.type === "payment_link.completed") {
const order = await db.orders.findByReference(reference);
if (order && order.amountKobo === amountKobo && currency === "NGN") await db.orders.markPaid(order.id);
} else if (event.type === "charge.failed" || event.type === "charge.expired") {
await db.orders.markUnpaid(reference); // let the customer try again with a NEW reference
}
await db.processedEvents.add(event.id);
res.sendStatus(200); // acknowledge fast; do slow work in a queue
});
app.listen(3000);Webhooks can arrive more than once (automatic retries, manual replays). Every delivery of one event has the same id — store processed ids and ignore repeats. More in Webhooks.
G2. Reconcile if a webhook is late or missing
Webhooks are a notification, not the source of truth — a delivery can be delayed or your server can be down. Run a small job (every few minutes) that re-checks orders still waiting for payment:
// Every 5 minutes: confirm orders that are still unpaid.
for (const order of await db.orders.awaitingPayment({ olderThanMinutes: 5 })) {
const res = await fetch(`https://api.developers.sendjoor.com/v1/charges/reference/${encodeURIComponent(order.reference)}/verify`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.SENDJOOR_SECRET_KEY}` },
});
if (res.status === 404) continue; // never created (e.g. the create call failed) — safe to create it now
const charge = await res.json();
if (charge.settled && charge.amountKobo === order.amountKobo) await db.orders.markPaid(order.id);
else if (charge.status === "FAILED" || charge.status === "EXPIRED") await db.orders.markUnpaid(order.reference);
// PENDING: leave it — the customer may still be paying.
}Or list everything that changed: GET /v1/charges?status=SUCCESS&from=…. The dashboard's Webhooks → Deliveries shows every attempt, its response code and error, with a retry button.
H. Submit your verification and request live access
Open Verification, fill in your details (individual or registered business), upload what's asked for, and submit. A Sendjoor reviewer decides; you're emailed at each step. See Verification & live access.
I. Go live
Once approved, switch the dashboard to Live, create an sk_live_ key with the same scopes, register your live webhook endpoint (test endpoints never receive live events), and swap the key on your server. Your code doesn't change — the key decides the environment. Run through the launch checklist first.