async function collectRwandaPayment(localPhone: string, amountRWF: number) {
const digits = localPhone.replace(/\D/g, "");
const phone = digits.startsWith("250") ? digits
: digits.startsWith("0") ? "250" + digits.slice(1)
: "250" + digits;
if (!/^250[0-9]{9}$/.test(phone)) {
throw new Error("Invalid Rwanda 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: amountRWF,
currency: "RWF",
callback_url: "https://your-app.com/webhooks/rohopay",
}),
}).then(r => r.json());
}