Skip to content

SDK JavaScript / TypeScript ​

Le SDK officiel nexera-pay couvre l'ensemble de l'API en TypeScript strict, avec support Node.js 18+ et navigateur (côté serveur uniquement — les clés secrètes ne doivent jamais tourner dans un bundle client).

npmdownloadsbundle

Installation ​

bash
npm install nexera-pay
# ou
pnpm add nexera-pay
# ou
yarn add nexera-pay

Initialisation ​

typescript
import { NexeraPay } from "nexera-pay";

const nexera = new NexeraPay({
  apiKey: process.env.NEXERA_PAY_API_KEY!,   // nex_test_... ou nex_live_...
  secret: process.env.NEXERA_PAY_SECRET!,
});

Les clés sont disponibles dans votre dashboard marchand : merchants.nexera.africa.

Paiement Mobile Money (STK Push) ​

typescript
const payment = await nexera.payments.create({
  amount: 10000,           // 100.00 USD en cents
  currency: "USD",
  method: "mobile_money",
  operator: "mpesa",       // mpesa | airtel | orange | africell
  phone: "243812345001",
  reference: "INV-2026-0001",
  description: "Facture #INV-2026-0001",
});

console.log(payment.id, payment.status);
// → pay_xxxx  processing

Le client reçoit un push USSD sur son téléphone. Le statut final vous parvient via webhook (payment.succeeded ou payment.failed).

Paiement carte (checkout Nexera-branded) ​

typescript
const payment = await nexera.payments.create({
  amount: 50000,
  currency: "USD",
  method: "card",
  reference: "INV-002",
  customer_email: "client@example.com",
  customer_name: "Jean Kabala",
  return_url: "https://monsite.cd/facture/002",
});

// Rediriger le client vers la page checkout Nexera-branded
// (pay.nexera.africa/checkout/{id} — Cybersource Microform, PCI DSS SAQ-A) :
window.location.href = payment.checkout_url!;

Vérification de webhook ​

typescript
import express from "express";

const app = express();

app.post("/webhooks/nexera",
  express.raw({ type: "application/json" }),
  (req, res) => {
    try {
      const event = nexera.webhooks.verify(
        req.body,                              // Buffer brut
        req.header("X-Nexera-Signature")!,
        process.env.NEXERA_WEBHOOK_SECRET!,
      );

      switch (event.type) {
        case "payment.succeeded":
          console.log("Paiement OK :", event.data.id);
          break;
        case "payment.failed":
          console.log("Échec :", event.data.failure_reason);
          break;
      }

      res.status(200).send("ok");
    } catch (err) {
      res.status(400).send("bad signature");
    }
  },
);

TypeScript ​

Le SDK est écrit en TypeScript strict. Tous les types sont inclus, aucun @types/* supplémentaire n'est requis. Autocomplétion IDE complète sur les payloads, réponses, événements webhook et codes d'erreur RFC 7807.

typescript
import type { Payment, WebhookEvent, PaymentMethod } from "nexera-pay";

function handleEvent(event: WebhookEvent) {
  if (event.type === "payment.succeeded") {
    const payment: Payment = event.data;
    // ...
  }
}

Frameworks ​

Le SDK est agnostique : il fonctionne dans Express, Fastify, Next.js (API routes + Server Actions), Nuxt (server routes), Remix, NestJS, ou n'importe quel runtime Node.js 18+ / Bun / Deno (via l'entrée ESM).

Pour Next.js, un exemple d'API route est disponible dans le README GitHub.

Ressources ​

Nexera Pay · Fais-le tourner.