Accept a payment
The complete walkthrough for collecting a Mobile Money payment, from the customer click to webhook confirmation.
8 min read
This guide covers the end-to-end payment collection flow: initialize server-side, redirect the customer, verify, then confirm via webhook.
Flow overview
- The customer clicks "Pay" → your server initializes the payment.
- You redirect to the hosted
authorization_url. - The customer pays (MTN MoMo, Orange Money, Wave…).
- Wajub sends you back to your
callback, and sends apayment.succeededwebhook. - You verify server-side before fulfilling.
1. Initialize (server)
Server route
app.post('/checkout', async (req, res) => {
const { transaction, authorization_url } = await wajub.payments.initialize({
amount: req.body.amount,
currency: 'XAF',
customer: { email: req.body.email },
reference: req.body.orderId, // your order reference
callback: 'https://example.com/payment/return',
});
await orders.update(req.body.orderId, { trx: transaction.reference });
res.redirect(authorization_url);
});2. Confirm via webhook (source of truth)
app.post('/webhooks/wajub', express.raw({ type: '*/*' }), (req, res) => {
const event = wajub.webhooks.constructEvent(req.body, req.headers['x-wajub-signature'], SECRET);
res.sendStatus(200); // acknowledge quickly
if (event.type === 'payment.succeeded') {
const order = orders.findByTrx(event.data.reference);
if (order && order.status !== 'fulfilled') fulfill(order); // idempotent
}
});3. Verify on return (safety net)
The browser return is not reliable (the user can close the tab). Verify server-side:
app.get('/payment/return', async (req, res) => {
const { transaction } = await wajub.payments.verify(req.query.reference);
res.render(transaction.status === 'succeeded' ? 'success' : 'pending');
});Never fulfill based on client return alone
Always confirm via webhook or server-side verification. A browser return can be forged
or missing. The golden rule: fulfill only on a verified succeeded status
server-side.
Follow the flow in Konsole
Make a test payment and watch the sequence in Konsole → Event Stream: initialization, provider selection, completion, webhook sent.