async function chargePlan(customer: { id: string; email: string }, planNgn: number) {
const res = await fetch("https://pesarc.xyz/api/v1/payments", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PESARC_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: planNgn,
currency: "NGN",
reference: `sub_${customer.id}`,
merchant_name: "Your SaaS",
description: "Pro plan, monthly",
redirect_url: `https://app.your-saas.com/billing/return`,
webhook_url: `https://app.your-saas.com/api/pesarc/webhook`,
metadata: { customerId: customer.id, plan: "pro" },
}),
});
const { checkout_url } = await res.json();
return checkout_url; // redirect the customer here
}