Guides
Accept payments
Start a payment, send your customer to the pay page, and confirm it before you fulfil.
A payment has three steps: you start it on your server, your customer pays on the CSwitch pay page, and you confirm the amount before you release anything.
Start the payment
Send amountKobo and your own reference. Email and name are optional. Add callbackUrl if the pay page should send the customer back to you.
const 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, // ₦2,500
reference: "order_10023",
customerEmail: "ngozi@example.com",
customerName: "Ngozi Eze",
callbackUrl: "https://yourshop.ng/thanks",
}),
});
const { data } = await res.json();
// redirect your customer to data.payUrlSending the same reference and amountKobo again returns the same payment. A different amount for that reference is 409 REFERENCE_IN_USE.
How customers pay
The pay page shows your name and the amount. In test mode the transfer account is simulated. In live mode the customer can pay by the methods enabled on your account, including transfer to the one-time account on the payment (accountNumber, accountName, bankName).
Verify before you fulfil
When your customer returns to callbackUrl, or when payment.success arrives, verify the payment on your server. Fulfil only when status is paid and amountKobo is what you expected.
const res = await fetch("https://middleware.test.nextcba.com/api/v1/pg/v1/payments/verify/order_10023", {
headers: { Authorization: `Bearer ${process.env.CSWITCH_SECRET_KEY}` },
});
const { data } = await res.json();
if (data.status === "paid" && data.amountKobo === 250000) {
// safe to fulfil the order
}Payment statuses
| Status | Meaning |
|---|---|
pending | Started, not paid yet. |
paid | Paid. Verify the amount, then fulfil. |
expired | The pay window closed before payment. |
failed | The payment could not be set up. |