{
  "name": "otorize: fattura con approvazione",
  "nodes": [
    { "parameters": {}, "id": "a1b2c3d4-0001-4000-8000-000000000001", "name": "Avvio manuale", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [0, 0] },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.otorize.app/v1/rooms/ROOM_ID/proposals?wait=25",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"action\":\"invoice.send\",\"params\":{\"number\":\"FT-{{ $now.toFormat('HHmmss') }}\",\"customer\":\"Rossi Srl\",\"amount\":500,\"currency\":\"EUR\"}}",
        "options": { "timeout": 40000 }
      },
      "id": "a1b2c3d4-0002-4000-8000-000000000002", "name": "Proponi fattura", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [240, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [ { "id": "c0000001", "leftValue": "={{ $json.proposal.status }}", "rightValue": "approved", "operator": { "type": "string", "operation": "equals" } } ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1b2c3d4-0003-4000-8000-000000000003", "name": "Approvata?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [480, 0]
    },
    {
      "parameters": { "assignments": { "assignments": [ { "id": "s0000001", "name": "sdi", "value": "OK (finto invio)", "type": "string" } ] }, "options": {} },
      "id": "a1b2c3d4-0004-4000-8000-000000000004", "name": "Invia fattura (finto)", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [720, -100]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.otorize.app/v1/proposals/{{ $('Proponi fattura').item.json.proposal.id }}/result",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\"status\":\"executed\",\"result\":{\"sdi\":\"OK\"}}",
        "options": {}
      },
      "id": "a1b2c3d4-0005-4000-8000-000000000005", "name": "Comunica esito a otorize", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, -100]
    },
    {
      "parameters": { "assignments": { "assignments": [ { "id": "s0000002", "name": "esito", "value": "={{ 'Non eseguita: ' + $('Proponi fattura').item.json.proposal.status }}", "type": "string" } ] }, "options": {} },
      "id": "a1b2c3d4-0006-4000-8000-000000000006", "name": "Fermati", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [720, 100]
    }
  ],
  "connections": {
    "Avvio manuale": { "main": [ [ { "node": "Proponi fattura", "type": "main", "index": 0 } ] ] },
    "Proponi fattura": { "main": [ [ { "node": "Approvata?", "type": "main", "index": 0 } ] ] },
    "Approvata?": { "main": [ [ { "node": "Invia fattura (finto)", "type": "main", "index": 0 } ], [ { "node": "Fermati", "type": "main", "index": 0 } ] ] },
    "Invia fattura (finto)": { "main": [ [ { "node": "Comunica esito a otorize", "type": "main", "index": 0 } ] ] }
  },
  "settings": {},
  "pinData": {}
}
