{
  "info": {
    "_postman_id": "a1f2c3d4-dpago-novasis-0001",
    "name": "Dpago + Novasis Pay",
    "description": "Pruebas de integración Dpago (directo) y del gateway Novasis Pay.\n\nLa carpeta '1 · Dpago directo' ya trae el token SHA256 calculado: corré los requests tal cual.\n\ntoken = SHA256(reference + amount + publicToken)\n\nImportar en Postman: File → Import → seleccioná este archivo. Después elegí el environment 'Dpago + Novasis Pay — Base' (postman-dpago-novasis.environment.json) arriba a la derecha.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "1 · Dpago directo (para soporte)",
      "description": "Le pega DIRECTO a https://api.dpago.com.\n\nIMPORTANTE (confirmado por Dpago):\n- La TRANSACCIÓN DIRECTA (POST /transactions, con platformId) sólo opera en PRODUCCIÓN. En prod devuelve qrInformation (QR embebido) y/o redirectUrl.\n- El LINK DE PAGO (POST /links) funciona también en DEV, no usa token ni customer.\n\ntoken = SHA256(reference + amount + publicToken). withInvoice va en false por defecto.",
      "item": [
        {
          "name": "Crear transacción — QR Ueno (platformId 18)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "url": {
              "raw": "{{apiDpago}}/transactions",
              "host": ["{{apiDpago}}"],
              "path": ["transactions"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 150000,\n  \"description\": \"Prueba Postman QR Ueno\",\n  \"reference\": \"POSTMAN-QRUENO-1\",\n  \"withInvoice\": false,\n  \"customer\": {\n    \"email\": \"cliente@example.com\",\n    \"identification\": \"1234567\",\n    \"name\": \"Juan Perez\",\n    \"phone\": \"0981123456\"\n  },\n  \"token\": \"{{tokenQrUeno}}\",\n  \"platformId\": 18,\n  \"commerceId\": 829,\n  \"orderNumber\": \"POSTMAN-QRUENO-1\"\n}"
            },
            "description": "Token calculado en el pre-request script para reference=POSTMAN-QRUENO-1, amount=150000, publicToken de la env. Si cambiás monto/reference, el script recalcula solo."
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// token = SHA256(reference + amount + publicToken)",
                  "const reference = 'POSTMAN-QRUENO-1';",
                  "const amount = 150000;",
                  "const publicToken = pm.environment.get('publicToken');",
                  "const token = CryptoJS.SHA256(reference + amount + publicToken).toString();",
                  "pm.environment.set('tokenQrUeno', token);"
                ]
              }
            }
          ]
        },
        {
          "name": "Crear transacción — Pix (platformId 14)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "url": {
              "raw": "{{apiDpago}}/transactions",
              "host": ["{{apiDpago}}"],
              "path": ["transactions"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 150000,\n  \"description\": \"Prueba Postman Pix\",\n  \"reference\": \"POSTMAN-PIX-1\",\n  \"withInvoice\": false,\n  \"customer\": {\n    \"email\": \"cliente@example.com\",\n    \"identification\": \"1234567\",\n    \"name\": \"Juan Perez\",\n    \"phone\": \"0981123456\"\n  },\n  \"token\": \"{{tokenPix}}\",\n  \"platformId\": 14,\n  \"commerceId\": 829,\n  \"orderNumber\": \"POSTMAN-PIX-1\"\n}"
            },
            "description": "Token calculado en el pre-request script para reference=POSTMAN-PIX-1, amount=150000."
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const reference = 'POSTMAN-PIX-1';",
                  "const amount = 150000;",
                  "const publicToken = pm.environment.get('publicToken');",
                  "const token = CryptoJS.SHA256(reference + amount + publicToken).toString();",
                  "pm.environment.set('tokenPix', token);"
                ]
              }
            }
          ]
        },
        {
          "name": "Estado de transacción",
          "request": {
            "method": "GET",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "url": {
              "raw": "{{apiDpago}}/transactions/{{refDpago}}",
              "host": ["{{apiDpago}}"],
              "path": ["transactions", "{{refDpago}}"]
            },
            "description": "Pegá en la env var refDpago el 'reference' que devolvió Dpago al crear."
          }
        },
        {
          "name": "Crear link de pago (funciona en DEV)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "url": {
              "raw": "{{apiDpago}}/links",
              "host": ["{{apiDpago}}"],
              "path": ["links"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"commerceId\": 829,\n  \"amount\": 150000,\n  \"description\": \"Prueba Postman link de pago\",\n  \"commerceReference\": \"POSTMAN-LINK-1\",\n  \"isTest\": true\n}"
            },
            "description": "Genera un link para compartir. No requiere token ni customer. La respuesta trae 'link' (URL a compartir), 'code' y 'id'. isTest=true = ambiente de prueba. El link vence a los 30 días."
          }
        }
      ]
    },
    {
      "name": "2 · Novasis Pay gateway (flujo real)",
      "description": "Flujo completo por el gateway (que calcula el hash internamente). Orden: Login → Crear customer → Crear intent → Confirmar → (Métodos). Los scripts de test copian los IDs a las env vars automáticamente.",
      "item": [
        {
          "name": "1) Login admin → accessToken",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "url": {
              "raw": "{{gatewayBase}}/admin/auth/login",
              "host": ["{{gatewayBase}}"],
              "path": ["admin", "auth", "login"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{adminEmail}}\",\n  \"password\": \"{{adminPassword}}\"\n}"
            },
            "description": "Para el flujo de cobro alcanza con la secretKey (sk_test_) ya cargada en la env. Este login solo hace falta para crear merchant/api-keys."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "if (j.accessToken) pm.environment.set('accessToken', j.accessToken);"
                ]
              }
            }
          ]
        },
        {
          "name": "2) Crear customer → guarda customerId",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Authorization", "value": "Bearer {{secretKey}}" }
            ],
            "url": {
              "raw": "{{gatewayBase}}/customers",
              "host": ["{{gatewayBase}}"],
              "path": ["customers"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"cliente@example.com\",\n  \"name\": \"Juan Perez\",\n  \"docType\": \"ci\",\n  \"docNumber\": \"1234567\",\n  \"phone\": \"0981123456\",\n  \"country\": \"PY\"\n}"
            },
            "description": "Dpago exige customer completo. El test script copia el 'id' (cus_...) a customerId."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "if (j.id) pm.environment.set('customerId', j.id);"
                ]
              }
            }
          ]
        },
        {
          "name": "3) Crear intent (dpago + platformId) → guarda intentId",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Authorization", "value": "Bearer {{secretKey}}" }
            ],
            "url": {
              "raw": "{{gatewayBase}}/payment-intents",
              "host": ["{{gatewayBase}}"],
              "path": ["payment-intents"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 150000,\n  \"currency\": \"PYG\",\n  \"country\": \"PY\",\n  \"requestedProvider\": \"dpago\",\n  \"platformId\": \"18\",\n  \"description\": \"Prueba Postman\",\n  \"customerId\": \"{{customerId}}\"\n}"
            },
            "description": "platformId 18 = QR Ueno, 14 = Pix. El test script copia el 'id' (pi_...) a intentId."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "if (j.id) pm.environment.set('intentId', j.id);"
                ]
              }
            }
          ]
        },
        {
          "name": "4) Confirmar intent → devuelve qr/redirectUrl",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Authorization", "value": "Bearer {{secretKey}}" }
            ],
            "url": {
              "raw": "{{gatewayBase}}/payment-intents/{{intentId}}/confirm",
              "host": ["{{gatewayBase}}"],
              "path": ["payment-intents", "{{intentId}}", "confirm"]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"platformId\": \"18\"\n}"
            },
            "description": "El gateway llama a Dpago. Mirá attempt.redirectUrl (link) y attempt.qr (QR inline si viene)."
          }
        },
        {
          "name": "5) (Opcional) Métodos de una checkout session",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{gatewayBase}}/public/checkout-sessions/{{publicCheckoutToken}}/payment-methods",
              "host": ["{{gatewayBase}}"],
              "path": ["public", "checkout-sessions", "{{publicCheckoutToken}}", "payment-methods"]
            },
            "description": "Necesita una checkout session creada. Pegá su publicToken en la env var publicCheckoutToken. Sin auth."
          }
        }
      ]
    }
  ]
}
