NyukiAIPayment

Documentation

Take your first payment.

Everything below is the real contract: the routes, the statuses, the failure codes, and the rules a correct integration follows.

Create a payment

The amount is a decimal string of minor units — "500000" in XAF is five hundred thousand francs, because XAF has no minor unit. The country decides the corridor, and therefore which providers are even eligible.

const response = await fetch(
  'https://secure.nyukiai.com/v1/payment_intents',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.NYUKIAI_SECRET_KEY}`,
      'Idempotency-Key': crypto.randomUUID(),
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      amount: '500000',        // minor units, as a string
      currency: 'XAF',
      country: 'CM',           // decides the corridor and the route
      methodType: 'MOBILE_MONEY',
      reference: 'order-4471',
      providerParams: { msisdn: '237699000000' },
    }),
  },
);

const intent = await response.json();
// REQUIRES_CONFIRMATION. Nothing has been charged yet — confirm to start it.
console.log(intent.id, intent.status);

Confirm it

Creating a payment records the instruction. Confirming it routes to a provider, creates a charge and asks that provider to start. The response carries the resolved provider, the flow kind, and a next action when the customer has something to do.

Listen for the outcome

Register your endpoint under Developers → Webhooks. Delivery is at-least-once, retried eight times over roughly three days, and signed with a rotating secret.

import { createHmac, timingSafeEqual } from 'node:crypto';

// The raw bytes, not the parsed body. Express's JSON parser re-serialises,
// and the re-serialised bytes will not match the HMAC we computed.
app.post('/webhooks/nyukiai', express.raw({ type: 'application/json' }),
  (req, res) => {
    if (!verify(req.body, req.get('NyukiAI-Signature'))) {
      return res.sendStatus(400);
    }

    const event = JSON.parse(req.body.toString('utf8'));

    // Delivery is at-least-once and can arrive out of order. Deduplicate on
    // the id, and compare against your own state rather than assuming order.
    if (alreadyProcessed(event.id)) return res.sendStatus(200);

    if (event.type === 'payment_intent.succeeded') {
      fulfil(event.data.object.reference);   // <- fulfil HERE
    }

    res.sendStatus(200);
  });