{
 "name": "otorize: invoice with approval",
 "nodes": [
  {
   "parameters": {},
   "id": "a1b2c3d4-0001-4000-8000-000000000001",
   "name": "Manual start",
   "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": "Propose invoice",
   "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": "Approved?",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2,
   "position": [
    480,
    0
   ]
  },
  {
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "s0000001",
       "name": "sdi",
       "value": "OK (mock send)",
       "type": "string"
      }
     ]
    },
    "options": {}
   },
   "id": "a1b2c3d4-0004-4000-8000-000000000004",
   "name": "Send invoice (mock)",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    720,
    -100
   ]
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=https://api.otorize.app/v1/proposals/{{ $('Propose invoice').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": "Report outcome to otorize",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    960,
    -100
   ]
  },
  {
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "s0000002",
       "name": "esito",
       "value": "={{ 'Not carried out: ' + $('Propose invoice').item.json.proposal.status }}",
       "type": "string"
      }
     ]
    },
    "options": {}
   },
   "id": "a1b2c3d4-0006-4000-8000-000000000006",
   "name": "Stop",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    720,
    100
   ]
  }
 ],
 "connections": {
  "Manual start": {
   "main": [
    [
     {
      "node": "Propose invoice",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Propose invoice": {
   "main": [
    [
     {
      "node": "Approved?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Approved?": {
   "main": [
    [
     {
      "node": "Send invoice (mock)",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Stop",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Send invoice (mock)": {
   "main": [
    [
     {
      "node": "Report outcome to otorize",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {},
 "pinData": {}
}