💡 Exemples

Exemples pratiques d'utilisation de l'API e-MECeF Integrator

📄

Facture de Vente Simple

Exemple basique d'une facture de vente avec plusieurs articles

Requête

curl -X POST http://emecef.waouhmonde.com/api/emecef/normalize \
  -H "Content-Type: application/json" \
  -d '{
    "credentials": {
      "nim": "TS01000001",
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "ifu": "1234567890123",
      "environment": "test"
    },
    "invoice": {
      "type": "FV",
      "items": [
        {
          "name": "Riz parfumé 25kg",
          "price": 15000,
          "quantity": 2,
          "taxGroup": "B"
        },
        {
          "name": "Huile végétale 5L",
          "price": 3500,
          "quantity": 3,
          "taxGroup": "B"
        }
      ],
      "client": {
        "ifu": "9876543210987",
        "name": "SUPERMARCHE MODERNE SARL",
        "contact": "97123456",
        "address": "Boulevard Steinmetz, Cotonou"
      },
      "operator": {
        "id": "001",
        "name": "Marie ADJOVI"
      },
      "payment": [
        {
          "name": "ESPECES",
          "amount": 40500
        }
      ]
    }
  }'

Réponse

{
  "success": true,
  "data": {
    "mecef_code": "A123-B456-C789-D012-E345-F678",
    "qr_code": "F;TS01000001;A123B456C789D012E345F678;1234567890123;20241223143055",
    "date_time": "23/12/2024 14:30:55",
    "counters": "1/1000 FV",
    "nim": "TS01000001",
    "totals": {
      "total": 40500,
      "ht": 34322,
      "tva": 6178,
      "aib": 0,
      "ts": 0
    }
  }
}
↩️

Facture d'Avoir

Remboursement ou annulation partielle d'une facture précédente

⚠️

Important

Une facture d'avoir nécessite obligatoirement la référence (code MECeF) de la facture originale.

Requête

{
  "credentials": {
    "nim": "TS01000001",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "ifu": "1234567890123",
    "environment": "test"
  },
  "invoice": {
    "type": "FA",
    "reference": "A123B456C789D012E345F678",
    "items": [
      {
        "name": "Riz parfumé 25kg - Remboursement",
        "price": -15000,
        "quantity": 1,
        "taxGroup": "B"
      }
    ],
    "client": {
      "ifu": "9876543210987",
      "name": "SUPERMARCHE MODERNE SARL",
      "contact": "97123456",
      "address": "Boulevard Steinmetz, Cotonou"
    },
    "operator": {
      "id": "001",
      "name": "Marie ADJOVI"
    },
    "payment": [
      {
        "name": "ESPECES",
        "amount": -15000
      }
    ]
  }
}

Réponse

{
  "success": true,
  "data": {
    "mecef_code": "Z987-Y654-X321-W098-V765-U432",
    "qr_code": "F;TS01000001;Z987Y654X321W098V765U432;1234567890123;20241223144512",
    "date_time": "23/12/2024 14:45:12",
    "counters": "1/1000 FA",
    "nim": "TS01000001",
    "totals": {
      "total": -15000,
      "ht": -12711,
      "tva": -2289,
      "aib": 0,
      "ts": 0
    }
  }
}
🌍

Facture d'Export

Facture pour les ventes à l'exportation (hors du Bénin)

Requête

{
  "credentials": {
    "nim": "TS01000001",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "ifu": "1234567890123",
    "environment": "test"
  },
  "invoice": {
    "type": "EV",
    "items": [
      {
        "name": "Karité brut - Export",
        "price": 500000,
        "quantity": 10,
        "taxGroup": "C"
      },
      {
        "name": "Frais de transport international",
        "price": 150000,
        "quantity": 1,
        "taxGroup": "C"
      }
    ],
    "client": {
      "name": "AFRICAN TRADE COMPANY",
      "contact": "+233244123456",
      "address": "Accra, Ghana"
    },
    "operator": {
      "id": "002",
      "name": "Jean KPONOU"
    },
    "payment": [
      {
        "name": "VIREMENT",
        "amount": 5150000
      }
    ]
  }
}
💰

Facture avec AIB

Facture incluant l'Acompte sur Impôt sur les Bénéfices

ℹ️

Types d'AIB

  • A : AIB 1% (clients avec IFU enregistré)
  • B : AIB 5% (clients sans IFU ou non enregistré)

Requête

{
  "credentials": {
    "nim": "TS01000001",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "ifu": "1234567890123",
    "environment": "test"
  },
  "invoice": {
    "type": "FV",
    "aib": "A",
    "items": [
      {
        "name": "Prestation de service IT",
        "price": 1000000,
        "quantity": 1,
        "taxGroup": "B"
      }
    ],
    "client": {
      "ifu": "1111222233334",
      "name": "TECH SOLUTIONS SARL",
      "contact": "97887766",
      "address": "Akpakpa, Cotonou"
    },
    "operator": {
      "id": "003",
      "name": "Paul DOSSOU"
    },
    "payment": [
      {
        "name": "VIREMENT",
        "amount": 1000000
      }
    ]
  }
}

Réponse

{
  "success": true,
  "data": {
    "mecef_code": "M111-N222-O333-P444-Q555-R666",
    "qr_code": "F;TS01000001;M111N222O333P444Q555R666;1234567890123;20241223151234",
    "date_time": "23/12/2024 15:12:34",
    "counters": "3/1000 FV",
    "nim": "TS01000001",
    "totals": {
      "total": 1000000,
      "ht": 847458,
      "tva": 152542,
      "aib": 8475,
      "ts": 0
    }
  }
}
🏷️

Facture avec Taxe Spécifique

Articles soumis à une taxe spécifique (tabac, alcool, etc.)

Requête

{
  "credentials": {
    "nim": "TS01000001",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "ifu": "1234567890123",
    "environment": "test"
  },
  "invoice": {
    "type": "FV",
    "items": [
      {
        "name": "Bière Flag 65cl",
        "price": 650,
        "quantity": 24,
        "taxGroup": "B",
        "taxSpecific": 2400
      },
      {
        "name": "Cigarettes",
        "price": 500,
        "quantity": 10,
        "taxGroup": "B",
        "taxSpecific": 1500
      }
    ],
    "operator": {
      "id": "004",
      "name": "Sandra HOUNKPE"
    },
    "payment": [
      {
        "name": "ESPECES",
        "amount": 20500
      }
    ]
  }
}
🔧

Exemples d'Intégration

🐘 PHP / Laravel

<?php

use Illuminate\Support\Facades\Http;

class EmecefIntegration
{
    private $baseUrl = 'http://emecef.waouhmonde.com/api/emecef';

    public function normalizeInvoice($credentials, $invoiceData)
    {
        $response = Http::timeout(30)
            ->post($this->baseUrl . '/normalize', [
                'credentials' => $credentials,
                'invoice' => $invoiceData
            ]);

        if ($response->successful()) {
            $result = $response->json();
            return $result['data'];
        }

        throw new Exception($response->json()['error'] ?? 'Erreur API');
    }
}

// Usage
$credentials = [
    'nim' => 'TS01000001',
    'token' => 'votre-token-jwt',
    'ifu' => '1234567890123',
    'environment' => 'test'
];

$invoice = [
    'type' => 'FV',
    'items' => [
        [
            'name' => 'Produit Test',
            'price' => 1000,
            'quantity' => 1,
            'taxGroup' => 'B'
        ]
    ]
];

$emecef = new EmecefIntegration();
$result = $emecef->normalizeInvoice($credentials, $invoice);

echo "Code MECeF: " . $result['mecef_code'];
echo "QR Code: " . $result['qr_code'];

🟨 JavaScript / Node.js

const axios = require('axios');

class EmecefIntegrator {
    constructor() {
        this.baseUrl = 'http://emecef.waouhmonde.com/api/emecef';
    }

    async normalizeInvoice(credentials, invoiceData) {
        try {
            const response = await axios.post(`${this.baseUrl}/normalize`, {
                credentials,
                invoice: invoiceData
            }, {
                timeout: 30000
            });

            return response.data.data;
        } catch (error) {
            throw new Error(error.response?.data?.error || 'Erreur API');
        }
    }
}

// Usage
const emecef = new EmecefIntegrator();

const credentials = {
    nim: 'TS01000001',
    token: 'votre-token-jwt',
    ifu: '1234567890123',
    environment: 'test'
};

const invoice = {
    type: 'FV',
    items: [{
        name: 'Produit Test',
        price: 1000,
        quantity: 1,
        taxGroup: 'B'
    }]
};

emecef.normalizeInvoice(credentials, invoice)
    .then(result => {
        console.log('Code MECeF:', result.mecef_code);
        console.log('QR Code:', result.qr_code);
    })
    .catch(error => {
        console.error('Erreur:', error.message);
    });

🐍 Python

import requests
import json

class EmecefIntegrator:
    def __init__(self):
        self.base_url = 'http://emecef.waouhmonde.com/api/emecef'

    def normalize_invoice(self, credentials, invoice_data):
        url = f"{self.base_url}/normalize"

        payload = {
            'credentials': credentials,
            'invoice': invoice_data
        }

        response = requests.post(
            url,
            json=payload,
            timeout=30
        )

        if response.status_code == 200:
            return response.json()['data']
        else:
            error_msg = response.json().get('error', 'Erreur API')
            raise Exception(error_msg)

# Usage
emecef = EmecefIntegrator()

credentials = {
    'nim': 'TS01000001',
    'token': 'votre-token-jwt',
    'ifu': '1234567890123',
    'environment': 'test'
}

invoice = {
    'type': 'FV',
    'items': [{
        'name': 'Produit Test',
        'price': 1000,
        'quantity': 1,
        'taxGroup': 'B'
    }]
}

try:
    result = emecef.normalize_invoice(credentials, invoice)
    print(f"Code MECeF: {result['mecef_code']}")
    print(f"QR Code: {result['qr_code']}")
except Exception as e:
    print(f"Erreur: {e}")

🧪 Identifiants de Test

Utilisez ces identifiants pour tester l'intégrateur :

Identifiants e-MECeF Test

NIM: TS01001944
IFU: 3201911071876
Environment: test

⚠️ Important

• Le TOKEN doit être obtenu auprès de la DGI

• Ces identifiants ne fonctionnent qu'en test

• En production, utilisez vos vrais identifiants