JavaScript / TypeScript
Package @avepay/mcf (npm)
Client typé ESM + CJS, Node 18+ (fetch natif). Payload friendly (calculs auto) avec échappatoire brute.
npm install @avepay/mcfCertifier une facture
import { AvePay } from "@avepay/mcf";
const avepay = new AvePay({ apiKey: process.env.AVEPAY_API_KEY!, isf: "1" });
const mcf = avepay.mcf("EL02000015-1");
const receipt = await mcf.certify({
number: "FV-2026-0001",
type: "FV", // FV | FT | EV | ET (défaut FV)
operator: { id: 1, name: "Awa" },
customer: { type: "PP", name: "Client Comptant" },
items: [{ name: "Riz 25kg", taxGroup: "B", unitPrice: 15000, quantity: 1 }],
payments: [{ method: "cash", amount: 15000 }],
});
console.log(receipt.sig); // signature SECEF (codeSecef)
console.log(receipt.qr); // contenu QR
console.log(receipt.totalTtc); // 15000
console.log(receipt.counters); // { tc, fvc, frc }taxGroup déduit le taxRate (A = 0 %, B = 18 %) ; method accepte cash/transfer/card/mobile/cheque/other (ou les codes bruts E/V/C/M/B/A). Tout champ brut fourni prime sur l'alias friendly.
Avoir (credit note)
const avoir = await mcf.creditNote({
number: "FA-2026-0001",
from: receipt, // dérive creditNoteRef = `${nim}-${fvc}`
// ou: creditNoteRef: "EL02000015-1-291",
creditNoteNature: "COR", // COR | RAN | RAM | RRR (défaut COR)
operator: { id: 1, name: "Awa" },
customer: { type: "PP" },
items: [{ name: "Riz 25kg", taxGroup: "B", unitPrice: 15000 }],
payments: [{ method: "cash", amount: 15000 }],
});Info · cancel-pending · me
const info = await mcf.info(); // mode, compteurs, marchand
await mcf.cancelPending(); // annule une transaction 38h pendante
const me = await avepay.me(); // org + NIM scopés + état des bridgesGestion d'erreurs
import { AvePayError } from "@avepay/mcf";
try {
await mcf.certify(invoice);
} catch (e) {
if (e instanceof AvePayError) {
console.error(e.code, e.httpStatus, e.message, e.requestId);
if (e.isBridgeOffline) {/* MCF hors ligne — réessayer plus tard */}
}
}Retry réseau/5xx automatique (backoff + Idempotency-Key réutilisée entre tentatives).
Webhooks
const event = avepay.webhooks.verify(rawBody, headers["x-avepay-signature"]);
// event.type : "cert.issued" | "mcf.connected" | "mcf.disconnected"