Python

Package avepay-mcf (PyPI)

Client sync (AvePay) et async (AsyncAvePay), même API. Python 3.9+, basé sur httpx. Payload friendly (snake_case) avec échappatoire brute (clés camelCase).

Installation
pip install avepay-mcf

Certifier une facture

certify
from avepay.mcf import AvePay, AvePayError

avepay = AvePay(api_key="ak_live_…", isf="1")
mcf = avepay.mcf("EL02000015-1")

receipt = 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", "tax_group": "B", "unit_price": 15000, "quantity": 1}],
    payments=[{"method": "cash", "amount": 15000}],
)

print(receipt.sig)        # signature SECEF (codeSecef)
print(receipt.qr)         # contenu QR
print(receipt.total_ttc)  # 15000
print(receipt.counters)   # Counters(tc=…, fvc=…, frc=…)

tax_group déduit le tax_rate (A = 0 %, B = 18 %) ; method accepte cash/transfer/card/mobile/cheque/other. certify()/credit_note() acceptent un dict positionnel ou des kwargs.

Avoir (credit note)

credit_note
avoir = mcf.credit_note(
    number="FA-2026-0001",
    from_=receipt,                  # dérive credit_note_ref = f"{nim}-{fvc}"
    # ou: credit_note_ref="EL02000015-1-291",
    credit_note_nature="COR",       # COR | RAN | RAM | RRR (défaut COR)
    operator={"id": 1, "name": "Awa"},
    customer={"type": "PP"},
    items=[{"name": "Riz 25kg", "tax_group": "B", "unit_price": 15000}],
    payments=[{"method": "cash", "amount": 15000}],
)

Info · cancel-pending · me

Autres appels
info = mcf.info()             # mode, compteurs, marchand
mcf.cancel_pending()          # annule une transaction 38h pendante
me = avepay.me()              # org + NIM scopés + état des bridges

Gestion d'erreurs

AvePayError
try:
    mcf.certify(...)
except AvePayError as e:
    print(e.code, e.http_status, e.message, e.request_id)
    if e.is_bridge_offline:
        ...  # MCF hors ligne — réessayer plus tard

Retry réseau/5xx automatique (backoff + Idempotency-Key réutilisée entre tentatives).

Async

AsyncAvePay
import asyncio
from avepay.mcf import AsyncAvePay

async def main():
    avepay = AsyncAvePay(api_key="ak_live_…", isf="1")
    receipt = await avepay.mcf("EL02000015-1").certify(
        number="FV-2026-0001",
        items=[{"name": "Riz 25kg", "tax_group": "B", "unit_price": 15000}],
        payments=[{"method": "cash", "amount": 15000}],
    )
    print(receipt.sig)

asyncio.run(main())

Webhooks

webhooks.verify
event = avepay.webhooks.verify(raw_body, signature_header)
# event["type"] : "cert.issued" | "mcf.connected" | "mcf.disconnected"
© 2026 AvePay — AvePlus. Tous droits réservés.