Nexera Pay — SDK JavaScript/TypeScript officiel. npm: @nexera/pay
# nexera-pay
SDK JavaScript/TypeScript officiel pour **Nexera Pay** — API paiement Payment Facilitator RDC (Mobile Money + Carte, wrapper Moko/PayDRC/Cybersource).
## Installation
```bash
npm install nexera-pay
```
## Quickstart
```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!,
});
// Créer un paiement Mobile Money (STK)
const payment = await nexera.payments.create({
amount: 10000, // 100.00 USD en cents
currency: "USD",
method: "mobile_money",
operator: "mpesa",
phone: "243812345001",
reference: "INV-2026-0001",
description: "Facture #INV-2026-0001",
});
console.log(payment.id, payment.status); // pay_xxxx processing
```
## Créer un paiement carte (hosted checkout)
```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: "
monsite.cd",
});
// Rediriger le client :
window.location.href = payment.checkout_url!;
```
## Vérifier un webhook
```typescript
import express from "express";
import { Webhooks } from "nexera-pay";
app.post("/webhooks/nexera", express.raw({ type: "application/json" }), (req, res) => {
const signature = req.header("X-Nexera-Signature");
const bodyStr = req.body.toString();
if (!Webhooks.verifySignature(process.env.NEXERA_WEBHOOK_SECRET!, signature!, bodyStr)) {
return res.status(401).send("Invalid signature");
}
const event = JSON.parse(bodyStr);
if (event.type === "payment.succeeded") {
const tx = event.data.object;
// Marquer la facture tx.reference comme payée dans ta DB
}
res.status(200).send("ok");
});
```
## Payout B2C (marchand → client)
```typescript
const payout = await nexera.payouts.create({
amount: 100,
currency: "CDF",
method: "mobile_money",
operator: "mpesa",
phone: "24382858468 …