AI tools
Composer
Pick a task and a language and get working integration code, step by step.
Tell the Composer what you're building and which language you use. Each sample calls the developer API with the field names the gateway expects.
I want to
In
Test and live use this URL. A key starting with sk_test_ is test mode. A key starting with sk_live_ is live mode, after live access is approved.
- 1
Start a payment
Create a payment and get a hosted pay page plus a one-time account number. The same reference and amount returns the same payment. A different amount for that reference is rejected.
Node.jsconst res = await fetch("https://middleware.test.nextcba.com/api/v1/pg/v1/payments/initialize", { method: "POST", headers: { Authorization: `Bearer ${process.env.CSWITCH_SECRET_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "amountKobo": 250000, "reference": "order_10023", "customerEmail": "ngozi@example.com", "customerName": "Ngozi Eze", "callbackUrl": "https://yourshop.ng/thanks", "metadata": { "orderId": "10023" } }), }); const { data } = await res.json(); - 2
Verify a payment
Read a payment by your reference. Fulfil an order only when status is paid and amountKobo is what you charged.
Node.jsconst res = await fetch("https://middleware.test.nextcba.com/api/v1/pg/v1/payments/verify/order_10023", { method: "GET", headers: { Authorization: `Bearer ${process.env.CSWITCH_SECRET_KEY}`, }, }); const { data } = await res.json(); - 3
Confirm it with a webhook
Trust the event only after checking its signature, then verify on your server.
Node.jsimport { verifyWebhook } from "@cswitch/node"; // Read the raw body before JSON.parse. The header is t=<unix>,v1=<hex>. export function isFromCSwitch(rawBody, header) { return verifyWebhook({ rawBody, header, secret: process.env.CSWITCH_WEBHOOK_SECRET, }).valid; }