Skip to content

Module 02 · Lesson 03

Initialize a transaction

Amounts are in pesewas: GHS 250 is 25000.

Build it8 min
// server only
const res = await fetch("https://api.paystack.co/transaction/initialize", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAYSTACK_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    email: customer.email,
    amount: order.totalPesewas,      // integer, e.g. 25000 = GHS 250.00
    currency: "GHS",
    reference: order.paymentRef,      // unique per attempt
    callback_url: "https://your-site.com/pay/return",
    channels: ["mobile_money", "card"],
  }),
});
const { data } = await res.json();
// send the customer to data.authorization_url