async function collectKenyaPayment(localPhone: string, amountKES: number) {
const digits = localPhone.replace(/\D/g, "");
const phone = digits.startsWith("254") ? digits
: digits.startsWith("0") ? "254" + digits.slice(1)
: "254" + digits;
if (!/^254[0-9]{9}$/.test(phone)) {
throw new Error("Invalid Kenya phone number");
}
return fetch("https://api.rohopay.com/api/v1/collect", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.ROHOPAY_API_KEY}`,
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
phone,
amount: amountKES,
currency: "KES",
callback_url: "https://your-app.com/webhooks/rohopay",
}),
}).then(r => r.json());
}