{
  "info": {
    "_postman_id": "9b47a29d-c3ff-4d52-a652-d3013abf9fb1",
    "name": "Levfone Connect — Retail Financing API v1.0",
    "description": "Colecao oficial do Levfone Connect.\n\nDuas APIs, duas direcoes:\n- Partner PDV API: implementada pelo PDV Parceiro, consumida pela Levfone.\n- Sales Authorization API: implementada pela Levfone, consumida pelo PDV.\n\nNunca preencha clientSecret com credencial de producao.\nhttps://developer.levfone.com",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const uuid = () => require('uuid').v4();",
          "pm.request.headers.upsert({ key: 'X-Request-Id', value: uuid() });",
          "if (pm.request.method !== 'GET') {",
          "  pm.request.headers.upsert({ key: 'Idempotency-Key', value: uuid() });",
          "}",
          "if (!pm.environment.get('correlationId')) {",
          "  pm.environment.set('correlationId', uuid());",
          "}",
          "pm.request.headers.upsert({",
          "  key: 'X-Correlation-Id',",
          "  value: pm.environment.get('correlationId'),",
          "});"
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test('Envelope padrao presente', () => {",
          "  const b = pm.response.json();",
          "  pm.expect(b).to.have.property('success');",
          "  pm.expect(b).to.have.property('timestamp');",
          "});"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "levfoneUrl",
      "value": "https://api.sandbox.levfone.com/v1"
    },
    {
      "key": "partnerUrl",
      "value": "https://sandbox.pdv-parceiro.example.com/v1"
    }
  ],
  "item": [
    {
      "name": "01 Auth",
      "item": [
        {
          "name": "Get Token — Levfone",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/x-www-form-urlencoded"
              }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "client_credentials"
                },
                {
                  "key": "client_id",
                  "value": "{{clientId}}"
                },
                {
                  "key": "client_secret",
                  "value": "{{clientSecret}}"
                },
                {
                  "key": "scope",
                  "value": "sales:authorize"
                }
              ]
            },
            "url": {
              "raw": "{{levfoneUrl}}/oauth/token",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "oauth",
                "token"
              ]
            },
            "description": "Token de sistema para a Sales Authorization API."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "pm.test('Token emitido', () => pm.response.to.have.status(200));",
                  "pm.environment.set('accessToken', body.access_token);",
                  "pm.environment.set('tokenExpiresAt', Date.now() + body.expires_in * 1000);"
                ]
              }
            }
          ],
          "response": []
        },
        {
          "name": "Get Token — PDV Parceiro",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/x-www-form-urlencoded"
              }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "client_credentials"
                },
                {
                  "key": "client_id",
                  "value": "{{clientId}}"
                },
                {
                  "key": "client_secret",
                  "value": "{{clientSecret}}"
                },
                {
                  "key": "scope",
                  "value": "catalog:read inventory:read sales:read"
                }
              ]
            },
            "url": {
              "raw": "{{partnerUrl}}/oauth/token",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "oauth",
                "token"
              ]
            },
            "description": "Token de sistema para a Partner PDV API."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "pm.test('Token emitido', () => pm.response.to.have.status(200));",
                  "pm.environment.set('accessToken', body.access_token);",
                  "pm.environment.set('tokenExpiresAt', Date.now() + body.expires_in * 1000);"
                ]
              }
            }
          ],
          "response": []
        },
        {
          "name": "Seller Session",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/sellers/session",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "sellers",
                "session"
              ]
            },
            "description": "Retorna o storeId, obrigatorio em todas as chamadas seguintes.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"username\": \"{{sellerUsername}}\",\n  \"password\": \"{{sellerPassword}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const b = pm.response.json();",
                  "pm.test('Sessao criada', () => pm.response.to.have.status(200));",
                  "if (b.data) {",
                  "  pm.environment.set('storeId', b.data.storeId);",
                  "  pm.environment.set('sellerId', b.data.sellerId);",
                  "}"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "02 Catalog",
      "item": [
        {
          "name": "List Plans",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/plans?storeId={{storeId}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "plans"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                }
              ]
            },
            "description": ""
          },
          "response": []
        },
        {
          "name": "List Products",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/products?storeId={{storeId}}&planId={{planId}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "products"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                },
                {
                  "key": "planId",
                  "value": "{{planId}}"
                },
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "pageSize",
                  "value": "50"
                }
              ]
            },
            "description": ""
          },
          "response": []
        },
        {
          "name": "Get Product by Barcode",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/products/barcode?storeId={{storeId}}&barcode={{barcode}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "products",
                "barcode"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                },
                {
                  "key": "barcode",
                  "value": "{{barcode}}"
                }
              ]
            },
            "description": "Serve para smartphones e qualquer acessorio. Garantias e seguros nao."
          },
          "response": []
        },
        {
          "name": "List Services",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/services?storeId={{storeId}}&sku={{sku}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "services"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                },
                {
                  "key": "sku",
                  "value": "{{sku}}"
                }
              ]
            },
            "description": ""
          },
          "response": []
        }
      ]
    },
    {
      "name": "03 Inventory",
      "item": [
        {
          "name": "Validate IMEI",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/imei/validate?storeId={{storeId}}&imei={{imei}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "imei",
                "validate"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                },
                {
                  "key": "imei",
                  "value": "{{imei}}"
                }
              ]
            },
            "description": "Resolucao de IMEI para produto. Nao reserva e nao decide."
          },
          "response": []
        }
      ]
    },
    {
      "name": "04 Authorization",
      "item": [
        {
          "name": "Authorize Sale — aprovada",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/authorize",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "authorize"
              ]
            },
            "description": "O PDV so pode faturar apos authorized: true.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"taxId\": \"{{taxId}}\",\n  \"storeId\": \"{{storeId}}\",\n  \"sellerId\": \"{{sellerId}}\",\n  \"planId\": \"{{planId}}\",\n  \"imei\": \"{{imei}}\",\n  \"items\": [\n    {\n      \"sku\": \"{{sku}}\",\n      \"productType\": \"SMARTPHONE\",\n      \"name\": \"Smartphone 128GB\",\n      \"quantity\": 1,\n      \"unitPrice\": {\n        \"amount\": 129900,\n        \"currency\": \"BRL\"\n      },\n      \"totalPrice\": {\n        \"amount\": 129900,\n        \"currency\": \"BRL\"\n      }\n    }\n  ],\n  \"services\": [\n    {\n      \"serviceId\": \"{{serviceId}}\",\n      \"name\": \"Garantia Estendida 12 meses\",\n      \"type\": \"EXTENDED_WARRANTY\",\n      \"price\": {\n        \"amount\": 19900,\n        \"currency\": \"BRL\"\n      }\n    }\n  ],\n  \"totals\": {\n    \"productsTotal\": {\n      \"amount\": 129900,\n      \"currency\": \"BRL\"\n    },\n    \"servicesTotal\": {\n      \"amount\": 19900,\n      \"currency\": \"BRL\"\n    },\n    \"grandTotal\": {\n      \"amount\": 149800,\n      \"currency\": \"BRL\"\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const b = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "if (b.data && b.data.authorized) {",
                  "  pm.environment.set('authorizationId', b.data.authorizationId);",
                  "  pm.test('Autorizacao tem TTL', () => pm.expect(b.data.expiresAt).to.be.a('string'));",
                  "} else {",
                  "  console.log('Recusa:', b.data && b.data.declineReason);",
                  "}"
                ]
              }
            }
          ]
        },
        {
          "name": "Authorize Sale — total divergente",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/authorize",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "authorize"
              ]
            },
            "description": "grandTotal nao bate com a soma dos itens. A Levfone nao arredonda.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"taxId\": \"{{taxId}}\",\n  \"storeId\": \"{{storeId}}\",\n  \"sellerId\": \"{{sellerId}}\",\n  \"planId\": \"{{planId}}\",\n  \"imei\": \"{{imei}}\",\n  \"items\": [\n    {\n      \"sku\": \"{{sku}}\",\n      \"productType\": \"SMARTPHONE\",\n      \"name\": \"Smartphone 128GB\",\n      \"quantity\": 1,\n      \"unitPrice\": {\n        \"amount\": 129900,\n        \"currency\": \"BRL\"\n      },\n      \"totalPrice\": {\n        \"amount\": 129900,\n        \"currency\": \"BRL\"\n      }\n    }\n  ],\n  \"services\": [\n    {\n      \"serviceId\": \"{{serviceId}}\",\n      \"name\": \"Garantia Estendida 12 meses\",\n      \"type\": \"EXTENDED_WARRANTY\",\n      \"price\": {\n        \"amount\": 19900,\n        \"currency\": \"BRL\"\n      }\n    }\n  ],\n  \"totals\": {\n    \"productsTotal\": {\n      \"amount\": 129900,\n      \"currency\": \"BRL\"\n    },\n    \"servicesTotal\": {\n      \"amount\": 19900,\n      \"currency\": \"BRL\"\n    },\n    \"grandTotal\": {\n      \"amount\": 140000,\n      \"currency\": \"BRL\"\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const b = pm.response.json();",
                  "pm.test('Total inconsistente e rejeitado', () => {",
                  "  pm.expect([200, 422]).to.include(pm.response.code);",
                  "  const code = (b.error && b.error.code) || (b.data && b.data.declineReason);",
                  "  pm.expect(['total_inconsistent', 'total_mismatch']).to.include(code);",
                  "});"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "05 Fulfillment",
      "item": [
        {
          "name": "Confirm Sale",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/{{authorizationId}}/confirm",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "{{authorizationId}}",
                "confirm"
              ]
            },
            "description": "Encerra o ciclo da autorizacao. Recomendado, nao obrigatorio.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"saleNumber\": \"V-100234\",\n  \"orderNumber\": \"P-556677\",\n  \"invoiceNumber\": \"000123456\",\n  \"nfeAccessKey\": \"35260712345678000199550010000123451234567890\",\n  \"invoicedAt\": \"2026-07-23T14:40:00.000Z\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Search Sale by IMEI",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/sales/search",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "sales",
                "search"
              ]
            },
            "description": "",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"imei\": \"{{imei}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Search Sale by CPF",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/sales/search",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "sales",
                "search"
              ]
            },
            "description": "POST e nao GET: CPF nunca trafega em query string.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"taxId\": \"{{taxId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "06 Cancellation",
      "item": [
        {
          "name": "Cancel Sale",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/{{authorizationId}}/cancel",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "{{authorizationId}}",
                "cancel"
              ]
            },
            "description": "A Levfone nunca inicia cancelamento. Isto apenas notifica.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"cancelledAt\": \"2026-07-23T15:10:00.000Z\",\n  \"reason\": \"CUSTOMER_REQUEST\",\n  \"notes\": \"Desistencia do cliente.\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Cancel Sale — troca",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/{{authorizationId}}/cancel",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "{{authorizationId}}",
                "cancel"
              ]
            },
            "description": "reason EXCHANGE e o gatilho do reaproveitamento da proposta.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"cancelledAt\": \"2026-07-23T15:10:00.000Z\",\n  \"reason\": \"EXCHANGE\",\n  \"notes\": \"Troca por defeito de fabricacao.\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "07 Errors",
      "item": [
        {
          "name": "401 — sem token",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{partnerUrl}}/plans?storeId={{storeId}}",
              "host": [
                "{{partnerUrl}}"
              ],
              "path": [
                "plans"
              ],
              "query": [
                {
                  "key": "storeId",
                  "value": "{{storeId}}"
                }
              ]
            },
            "description": ""
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('401', () => pm.response.to.have.status(401));"
                ]
              }
            }
          ]
        },
        {
          "name": "409 — autorizacao expirada",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{accessToken}}"
              }
            ],
            "url": {
              "raw": "{{levfoneUrl}}/sales/{{expiredAuthorizationId}}/confirm",
              "host": [
                "{{levfoneUrl}}"
              ],
              "path": [
                "sales",
                "{{expiredAuthorizationId}}",
                "confirm"
              ]
            },
            "description": "",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"saleNumber\": \"V-1\",\n  \"invoiceNumber\": \"1\",\n  \"nfeAccessKey\": \"35260712345678000199550010000123451234567890\",\n  \"invoicedAt\": \"2026-07-23T18:00:00.000Z\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('409', () => pm.response.to.have.status(409));"
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}