{
  "info": {
    "_postman_id": "7308f4de-b6a1-5ca9-907d-becc6d3942d0",
    "name": "Tampa (bac à sable)",
    "description": "API Tampa de facturation normalisée e-MECeF, sur le bac à sable (serveur de test DGI, factures sans valeur fiscale).\n\n1. Collez votre clé API dans la variable apiKey de la collection.\n2. Lancez « Ajouter une entreprise » avec votre jeton e-MECeF de test : son id est gardé dans taxpayerId.\n3. Lancez « Certifier une facture ». Chaque envoi crée une nouvelle facture (clé d'idempotence aléatoire).\n\nDocumentation : https://otampa.com/docs",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://sandbox.otampa.com"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "taxpayerId",
      "value": ""
    },
    {
      "key": "invoiceId",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "1. Entreprises",
      "item": [
        {
          "name": "Ajouter une entreprise",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/taxpayers",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers"
              ]
            },
            "description": "Vérifie le jeton auprès de la DGI puis enregistre le contribuable.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"ifu\": \"0000000000000\",\n  \"name\": \"Boutique Exemple\",\n  \"emecef_token\": \"JETON_E_MECEF_DE_TEST\",\n  \"address\": \"Rue 123, Cotonou\",\n  \"city\": \"Cotonou\",\n  \"phone\": \"+229 01 00 00 00 00\",\n  \"email\": \"contact@boutique-exemple.bj\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200 || pm.response.code === 201) {",
                  "  pm.collectionVariables.set(\"taxpayerId\", pm.response.json().id);",
                  "}"
                ]
              }
            }
          ]
        },
        {
          "name": "Lister les entreprises",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/taxpayers",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers"
              ]
            },
            "description": "Liste les contribuables du compte authentifié."
          }
        },
        {
          "name": "Lire une entreprise",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/taxpayers/{{taxpayerId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers",
                "{{taxpayerId}}"
              ]
            },
            "description": "Renvoie un contribuable du compte authentifié."
          }
        },
        {
          "name": "Modifier les coordonnées",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/taxpayers/{{taxpayerId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers",
                "{{taxpayerId}}"
              ]
            },
            "description": "Met à jour les coordonnées d'un contribuable du compte.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"phone\": \"+229 01 00 00 00 02\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Supprimer une entreprise sans facture",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/taxpayers/{{taxpayerId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers",
                "{{taxpayerId}}"
              ]
            },
            "description": "Supprime un contribuable s'il ne possède aucune facture."
          }
        },
        {
          "name": "Remplacer le jeton e-MECeF",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/taxpayers/{{taxpayerId}}/token",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "taxpayers",
                "{{taxpayerId}}",
                "token"
              ]
            },
            "description": "Vérifie puis remplace le jeton e-MECeF d'un contribuable.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"emecef_token\": \"NOUVEAU_JETON_E_MECEF\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "2. Factures",
      "item": [
        {
          "name": "Certifier une facture",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "{{$guid}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/invoices",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "invoices"
              ]
            },
            "description": "Certifie une facture et garantit l'idempotence de chaque tentative.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"taxpayer_id\": \"{{taxpayerId}}\",\n  \"invoice\": {\n    \"type\": \"FV\",\n    \"operator\": {\n      \"name\": \"Caisse 1\"\n    },\n    \"client\": {\n      \"name\": \"Client Exemple\",\n      \"contact\": \"+229 01 00 00 00 01\"\n    },\n    \"items\": [\n      {\n        \"name\": \"Sac de riz 25 kg\",\n        \"price\": 11800,\n        \"quantity\": 2,\n        \"taxGroup\": \"B\"\n      },\n      {\n        \"name\": \"Livraison\",\n        \"price\": 1000,\n        \"quantity\": 1,\n        \"taxGroup\": \"B\"\n      }\n    ],\n    \"payment\": [\n      {\n        \"name\": \"MOBILEMONEY\",\n        \"amount\": 24600\n      }\n    ]\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200 || pm.response.code === 201) {",
                  "  pm.collectionVariables.set(\"invoiceId\", pm.response.json().id);",
                  "}"
                ]
              }
            }
          ]
        },
        {
          "name": "Lister les factures",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/invoices",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "invoices"
              ],
              "query": [
                {
                  "key": "taxpayer_id",
                  "value": "{{taxpayerId}}",
                  "disabled": false,
                  "description": ""
                },
                {
                  "key": "limit",
                  "value": "",
                  "disabled": true,
                  "description": ""
                },
                {
                  "key": "offset",
                  "value": "",
                  "disabled": true,
                  "description": ""
                }
              ]
            },
            "description": "Liste les factures appartenant au compte authentifié."
          }
        },
        {
          "name": "Lire une facture",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/invoices/{{invoiceId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "invoices",
                "{{invoiceId}}"
              ]
            },
            "description": "Renvoie une facture du compte authentifié."
          }
        },
        {
          "name": "Télécharger le PDF",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/invoices/{{invoiceId}}/pdf",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "invoices",
                "{{invoiceId}}",
                "pdf"
              ]
            },
            "description": "Rend à la demande le PDF d'une facture certifiée."
          }
        }
      ]
    },
    {
      "name": "3. Système",
      "item": [
        {
          "name": "État du service",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/health",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "health"
              ]
            },
            "description": "Indique que l'API tourne. Utilisé par Docker et la supervision.",
            "auth": {
              "type": "noauth"
            }
          }
        }
      ]
    }
  ]
}
