JavaScript examples
Initiate a payment (Node.js)
const res = await fetch('https://nixpay.supreonix.com/api/v1/payments/stk-push', { method: 'POST', headers: { 'Authorization': `Bearer \${process.env.NIXPAY_SECRET_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ amount: 500, phone: '254712345678', account_reference: 'INV-1042', }), }); const { ok, data, error } = await res.json(); if (!ok) throw new Error(error.message);
Verify a webhook (Express)
const crypto = require('crypto'); app.post('/nixpay/webhook', express.raw({ type: 'application/json' }), (req, res) => { const expected = 'sha256=' + crypto .createHmac('sha256', process.env.NIXPAY_WEBHOOK_SECRET) .update(req.body) .digest('hex'); if (req.get('X-NixPay-Signature') !== expected) return res.sendStatus(400); const event = JSON.parse(req.body); // fulfil the order res.sendStatus(200); });
NixPay documentation · A Supreonix product
Back to introduction