// 1. Get access token (cache for 1 hour)
const tokenRes = await fetch("https://api.acountpay.com/oauth/token", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "grant_type=client_credentials&client_id=YOUR_ID&client_secret=YOUR_SECRET"
});
const { access_token } = await tokenRes.json();
// 2. Create payment
const paymentRes = await fetch("https://api.acountpay.com/v1/partner/payments", {
method: "POST",
headers: {
"Authorization": `Bearer ${access_token}`,
"X-Merchant-Client-Id": "merchant_abc123",
"Content-Type": "application/json"
},
body: JSON.stringify({
amount: 149.99,
referenceNumber: "ORDER-12345",
webhookUrl: "https://your-pos.com/webhooks"
})
});
const { qrCodeUrl } = await paymentRes.json();
// 3. Display QR code
displayQRCode(qrCodeUrl);
// 4. Handle webhook when payment completes
app.post("/webhooks", (req, res) => {
if (req.body.event === "payment.completed") {
markOrderPaid(req.body.data.referenceNumber);
}
res.sendStatus(200);
});