Guides
Accept payments
Start a payment, send your customer to checkout and confirm it before you fulfil the order.
A payment has three steps: you start it on your server, your customer pays on the CSwitch checkout, and you confirm it before releasing anything.
Start the payment
Send the amount in kobo and your customer's email. Add your own reference so you can match the payment to your order.
const res = await fetch("https://sandbox.cswitchcba.com/v1/payments", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CSWITCH_SECRET_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
amount: 4200000, // ₦42,000 in kobo
email: "ngozi@example.com",
reference: "order_2231",
callback_url: "https://yourshop.ng/thanks",
}),
});
const { data } = await res.json();
// redirect your customer to data.checkout_urlHow customers pay
The checkout shows your logo and lets your customer pay by Verve, Visa or Mastercard, or by bank transfer to a one-time account number that matches itself to the payment.
Verify before you fulfil
When your customer returns to your callback_url, or when the payment.successful webhook arrives, verify the payment on your server. Only fulfil the order when the status is successful and the amount is what you expected.
const res = await fetch("https://sandbox.cswitchcba.com/v1/payments/order_2231", {
headers: { Authorization: `Bearer ${process.env.CSWITCH_SECRET_KEY}` },
});
const { data } = await res.json();
if (data.status === "successful" && data.amount === 4200000) {
// safe to fulfil the order
}Payment statuses
| Status | Meaning |
|---|---|
pending | Started, not paid yet. |
successful | Paid. Verify the amount, then fulfil. |
failed | The attempt failed. The customer can try again. |