{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "E3EEBEB4-ED23-4B64-88D4-6741DBD97577",
    "name": "sevdesk: Shopify orders invoiced and booked"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": 36.03045976610747,
        "y": -26.424949765726296,
        "zoom": 0.5
      },
      "autoSave": true,
      "descriptions": {
        "flow": "When a Shopify order comes in, finds or creates the buyer in sevdesk by their Shopify customer ID, creates the invoice from the order lines and emails it, then finds the matching Stripe payment and books it against the invoice. Without a payment the invoice stays open.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "When a Shopify order comes in, finds or creates the buyer in sevdesk by their Shopify customer ID, creates the invoice from the order lines and emails it, then finds the matching Stripe payment and books it against the invoice. Without a payment the invoice stays open.",
    "elements": [
      {
        "clientMetadata": {
          "notes": "Lists the sevdesk check accounts, which are the bank accounts, cash boxes and clearing accounts every booking has to name.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::listCheckAccounts",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the check accounts Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::listCheckAccounts",
          "legacyElementId": "JS###v1###SevdeskService###listCheckAccounts",
          "methodName": "listCheckAccounts",
          "position": {
            "x": 110,
            "y": 40
          }
        },
        "flowElementId": "3D8AD7E1-9517-407A-B23E-98EFACA9705D",
        "groupId": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "id": "21264EE2-B164-45DB-8155-BA50ED8BC353",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 1000
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "countAll",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "embed",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listCheckAccounts",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Check accounts",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the check accounts",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Lists the sevdesk contact custom field definitions, which is where the ids for setting a contact's values come from.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::listContactCustomFieldSettings",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the contact custom fields Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::listContactCustomFieldSettings",
          "legacyElementId": "JS###v1###SevdeskService###listContactCustomFieldSettings",
          "methodName": "listContactCustomFieldSettings",
          "position": {
            "x": 106.98950650517787,
            "y": 141.72716913462446
          }
        },
        "flowElementId": "3B9089B1-7F25-49EB-82E8-8346991299B9",
        "groupId": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "id": "84001583-94E9-40BC-9D21-72940F2EFB78",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "countAll",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listContactCustomFieldSettings",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Custom fields",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the contact custom fields",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Triggers when a new order is created in your Shopify store. Polling interval can be customized (minimum 30 seconds). Each cycle inspects the 50 most recent orders, so bursts of more than 50 new orders between polls may be missed.",
          "elementId": "EXTENSION:::SHARED:::default:::shopify:::onNewOrder",
          "isFirstElement": true,
          "blockDefinitionId": "EXTENSION:::SHARED:::default:::shopify:::onNewOrder",
          "newElementId": "EXTENSION:::SHARED:::default:::shopify:::onNewOrder",
          "legacyElementId": "JS###v1###Shopify###onNewOrder",
          "methodName": "onNewOrder",
          "position": {
            "x": 110,
            "y": 400
          }
        },
        "flowElementId": "DF85B8A2-A439-4E92-9FE5-93B28EC07DCF",
        "groupId": null,
        "id": "66941658-FDAF-459C-9B46-FEC8825FC5B4",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": "Block: 'New Shopify order', Error: OAuth Connection is required",
            "valid": false
          },
          "condition": null,
          "connectionId": null,
          "dynamicData": [],
          "eventName": "onNewOrder",
          "frequency": {
            "repeat": {
              "every": 300
            },
            "schedule": "custom"
          },
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "New order",
          "serviceId": "shopify",
          "slaConditions": [],
          "staticData": {},
          "storeResult": true,
          "subtype": "POLLING",
          "type": "CUSTOM"
        },
        "name": "New Shopify order",
        "nextElementIds": [
          "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "notes": "Retrieves a single order by its ID with full details including line items, customer, and addresses.",
          "elementId": "EXTENSION:::SHARED:::default:::shopify:::getOrder",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the order details Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::shopify:::getOrder",
          "legacyElementId": "JS###v1###Shopify###getOrder",
          "methodName": "getOrder",
          "position": {
            "x": 400,
            "y": 400
          }
        },
        "flowElementId": "C23914DD-5950-4186-A485-5EDFA20EC681",
        "groupId": null,
        "id": "DEC544F4-6917-45C4-AABE-A7F31794FF8B",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "orderId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "RESULT",
                    "label": "New order",
                    "subPathSegments": [
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "TRIGGER_DATA",
                    "value": "66941658-FDAF-459C-9B46-FEC8825FC5B4"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Get the order details', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getOrder",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Order",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "shopify",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the order details",
        "nextElementIds": [],
        "nextGroupIds": [
          "A60A2737-C210-4D30-9BCF-B0DD2F129599"
        ],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Lists a sevdesk reference resource such as categories, countries, units, users or booking accounts, whose ids the create operations require.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::listReferenceObjects",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "model": {
              "SevUser": "User"
            }
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the sevdesk users Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::listReferenceObjects",
          "legacyElementId": "JS###v1###SevdeskService###listReferenceObjects",
          "methodName": "listReferenceObjects",
          "position": {
            "x": 105.48425975776681,
            "y": 250.35096231697617
          }
        },
        "flowElementId": "DEE8787F-A11B-422E-AF29-566900F517EC",
        "groupId": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "id": "4C936E2A-C649-41A8-A8F1-A97F347E7C31",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "model",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "SevUser"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "objectType",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 100
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "countAll",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "embed",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listReferenceObjects",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Users",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the sevdesk users",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Reads which sevdesk bookkeeping version the account runs, which decides whether documents carry a tax rule or a tax type and tax set.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::getBookkeepingSystemVersion",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the bookkeeping version Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::getBookkeepingSystemVersion",
          "legacyElementId": "JS###v1###SevdeskService###getBookkeepingSystemVersion",
          "methodName": "getBookkeepingSystemVersion",
          "position": {
            "x": 102.47376626294465,
            "y": 353.58337819901163
          }
        },
        "flowElementId": "10E861A9-0CE0-4944-BB80-61A4D318978B",
        "groupId": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "id": "00E4FB41-59A7-434F-9874-6736D07522E0",
        "metaInfo": {
          "bodyParams": [],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getBookkeepingSystemVersion",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Version",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the bookkeeping version",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Lists a sevdesk reference resource such as categories, countries, units, users or booking accounts, whose ids the create operations require.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::listReferenceObjects",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "model": {
              "StaticCountry": "Country"
            }
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the countries Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::listReferenceObjects",
          "legacyElementId": "JS###v1###SevdeskService###listReferenceObjects",
          "methodName": "listReferenceObjects",
          "position": {
            "x": 106.98950650517787,
            "y": 464.34202781810257
          }
        },
        "flowElementId": "0B184D3F-456B-4A57-81DF-17006F9C78A8",
        "groupId": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "id": "C1A7F931-B262-48CF-AC16-DF95E960F3C1",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "model",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "StaticCountry"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "objectType",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 1000
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "countAll",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "embed",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "listReferenceObjects",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Countries",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the countries",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Prepare the invoice Result"
          },
          "position": {
            "x": 1025.6311686852769,
            "y": 398
          }
        },
        "flowElementId": "21DC75CA-7E32-4578-B528-C6818A01DCD5",
        "groupId": null,
        "id": "A04C0042-3CC3-44CD-A631-985D2F38CC99",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "order",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Order",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "version",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Version",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "version",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "00E4FB41-59A7-434F-9874-6736D07522E0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "users",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Users",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "4C936E2A-C649-41A8-A8F1-A97F347E7C31"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "countries",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Countries",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "C1A7F931-B262-48CF-AC16-DF95E960F3C1"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customFields",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Custom fields",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "84001583-94E9-40BC-9D21-72940F2EFB78"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "fieldName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Shopify ID field in sevdesk",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Shopify ID field in sevdesk"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxRule",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "sevdesk tax rule",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "sevdesk tax rule"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const num = v => { const n = parseFloat(v); return Number.isFinite(n) ? n : 0; };\nconst r2 = n => Math.round(n * 100) / 100;\nconst r4 = n => Math.round(n * 10000) / 10000;\nconst o = order || {};\nconst total = num(o.totalPrice);\nconst tax = num(o.totalTax);\nconst shipping = num(o.totalShipping);\nconst items = (o.lineItems || []).filter(i => num(i.quantity) > 0);\nconst lineSum = items.reduce((s, i) => s + num(i.discountedPrice ?? i.totalPrice), 0);\n// Shopify line prices include VAT when lines plus shipping add up to the order total.\nconst taxIncluded = Math.abs(lineSum + shipping - total) <= Math.abs(lineSum + shipping + tax - total);\n// Each line carries the VAT Shopify charged on it. The order-wide rate is only a fallback for a line without tax lines.\nconst netTotal = total - tax;\nconst rawRate = netTotal > 0 ? tax / netTotal * 100 : 0;\nconst fallbackRate = [0, 7, 10, 13, 19, 20].reduce((b, r) => Math.abs(r - rawRate) < Math.abs(b - rawRate) ? r : b, 0);\nconst rateOf = i => {\n  const lines = Array.isArray(i.taxLines) ? i.taxLines : [];\n  if (!lines.length) return fallbackRate;\n  return r2(lines.reduce((s, t) => s + (t.ratePercentage != null ? num(t.ratePercentage) : num(t.rate) * 100), 0));\n};\n// Shipping takes the rate of the goods, the highest when the lines differ.\nconst shippingRate = items.length ? Math.max(...items.map(rateOf)) : fallbackRate;\nconst position = (name, quantity, lineAmount, rate, text) => {\n  const gross = r4((taxIncluded ? lineAmount : lineAmount * (1 + rate / 100)) / quantity);\n  return { name, text, quantity, unityId: '1', taxRate: rate, priceGross: gross, priceNet: r4(gross / (1 + rate / 100)) };\n};\nconst positions = items.map(i => position(\n  i.variantTitle && i.variantTitle !== 'Default Title' ? `${i.title} (${i.variantTitle})` : i.title,\n  num(i.quantity),\n  num(i.discountedPrice ?? i.totalPrice),\n  rateOf(i),\n  i.sku ? `SKU ${i.sku}` : undefined,\n));\nif (shipping > 0) positions.push(position('Shipping', 1, shipping, shippingRate));\nconst diff = r2(total - positions.reduce((s, p) => s + p.priceGross * p.quantity, 0));\nif (Math.abs(diff) >= 0.01) {\n  positions.push({ name: diff < 0 ? 'Order discount' : 'Other charges', quantity: 1, unityId: '1', taxRate: shippingRate, priceGross: diff, priceNet: r4(diff / (1 + shippingRate / 100)) });\n}\n\nconst customer = o.customer || {};\nconst addr = o.billingAddress || o.shippingAddress || {};\nconst email = String(customer.email || o.email || '').trim();\nif (!email) throw new Error(`Order ${o.name} has no email address to send the invoice to.`);\nconst shopifyId = customer.id ? String(customer.id).split('/').pop() : '';\nconst buyerKey = shopifyId || email.toLowerCase();\nconst parts = String(customer.displayName || '').trim().split(/\\s+/);\nconst firstName = addr.firstName || parts[0] || '';\nconst lastName = addr.lastName || parts.slice(1).join(' ') || email;\n\nconst code = String(addr.countryCode || 'DE').toLowerCase();\nconst country = (countries || []).find(c => String(c.code || '').toLowerCase() === code);\nif (!country) throw new Error(`sevdesk has no country with the code ${code.toUpperCase()}.`);\nconst user = (users || [])[0];\nif (!user) throw new Error('The sevdesk account has no user to name as the contact person on the invoice.');\nconst wanted = String(fieldName || '').trim().toLowerCase();\nconst field = (customFields || []).find(f => String(f.name || '').trim().toLowerCase() === wanted);\nif (!field) throw new Error(`Create a contact custom field named \"${fieldName}\" in sevdesk. The flow keeps each buyer's Shopify customer ID there.`);\n\nconst v2 = String(version || '').startsWith('2');\nconst created = o.createdAt || new Date().toISOString();\nreturn {\n  buyerKey,\n  customFieldId: String(field.id),\n  firstName,\n  lastName,\n  email,\n  countryId: String(country.id),\n  contactPersonId: String(user.id),\n  address: [\n    addr.company,\n    [addr.firstName, addr.lastName].filter(Boolean).join(' ') || customer.displayName,\n    addr.address1,\n    addr.address2,\n    [addr.zip, addr.city].filter(Boolean).join(' '),\n    addr.country,\n  ].filter(Boolean).join('\\n'),\n  invoiceDate: created.slice(0, 10),\n  currency: o.currency || 'EUR',\n  total: r2(total),\n  // Update 2.0 accounts take a tax rule, Update 1.0 accounts a tax type.\n  invoiceTax: v2 ? { taxRule: { id: String(taxRule || '1'), objectName: 'TaxRule' } } : { taxType: 'default' },\n  showNet: !taxIncluded,\n  positions,\n  orderName: o.name,\n  orderCreated: created,\n  stripeQuery: { created: { gte: Math.floor(Date.parse(created) / 1000) - 3600 }, limit: 100 },\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Prepared",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Prepare the invoice",
        "nextElementIds": [
          "549D558D-A385-4074-9E64-4EDA746D0B87"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "data-bucket",
          "isFirstElement": false,
          "blockDefinitionId": "data-bucket",
          "fieldKeys": {
            "contactId": "e499bb91-5165-4477-b5dc-d4c5ce13acb4"
          },
          "position": {
            "x": 936,
            "y": 702
          }
        },
        "flowElementId": "458FF015-3967-4AF0-B30A-F8B787FC69C7",
        "groupId": null,
        "id": "07D82168-B93F-4AAF-9297-67C805654F96",
        "metaInfo": {
          "bucketName": "Buyer",
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "fields": [
            {
              "name": "contactId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Found buyer",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "index": 0,
                        "last": false
                      },
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "549D558D-A385-4074-9E64-4EDA746D0B87"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "useOld",
          "storeResult": true
        },
        "name": "Use the existing buyer",
        "nextElementIds": [
          "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
        ],
        "nextGroupIds": [],
        "type": "DATA_BUCKET"
      },
      {
        "clientMetadata": {
          "notes": "Sets a sevdesk contact's value for a custom field setting, which is how an external identifier is stored on a contact.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::createContactCustomField",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Save the Shopify ID on the buyer Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::createContactCustomField",
          "legacyElementId": "JS###v1###SevdeskService###createContactCustomField",
          "methodName": "createContactCustomField",
          "position": {
            "x": 374,
            "y": 1038
          }
        },
        "flowElementId": "C4691E8A-3628-4B26-AC7C-E9D30002B2EB",
        "groupId": null,
        "id": "98FA7B0D-FD57-4EC3-9068-5D795242B3FE",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "contactId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New buyer",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "6A4B3C15-B83C-4B46-BA17-D6B52DBB32BD"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "contactCustomFieldSettingId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "customFieldId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "value",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "buyerKey",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "createContactCustomField",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Saved Shopify ID",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Save the Shopify ID on the buyer",
        "nextElementIds": [
          "C7B58726-6549-4823-A2F3-FD28EFECEEF7"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "data-bucket",
          "isFirstElement": false,
          "blockDefinitionId": "data-bucket",
          "fieldKeys": {
            "contactId": "9ca73ffa-8637-4f55-9b51-cc7ccf413142"
          },
          "position": {
            "x": 940,
            "y": 1046
          }
        },
        "flowElementId": "C64D5E04-3160-4D43-B120-113ABAD298CB",
        "groupId": null,
        "id": "C7B58726-6549-4823-A2F3-FD28EFECEEF7",
        "metaInfo": {
          "bucketName": "Buyer",
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "fields": [
            {
              "name": "contactId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "New buyer",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "6A4B3C15-B83C-4B46-BA17-D6B52DBB32BD"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "useNew",
          "storeResult": true
        },
        "name": "Use the new buyer",
        "nextElementIds": [
          "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
        ],
        "nextGroupIds": [],
        "type": "DATA_BUCKET"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 704,
            "y": 558
          }
        },
        "flowElementId": "C048FE3F-9409-4970-9079-2B170E961493",
        "groupId": null,
        "id": "42B6C607-4DD0-4CD3-A999-2CAE6AFFC251",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "ed4089a3-2b74-427f-8c05-52e240c1a240",
                "nestedOperation": null,
                "operation": "arrayIsNotEmpty",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Found buyer",
                      "subPathSegments": [
                        {
                          "key": "objects",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "549D558D-A385-4074-9E64-4EDA746D0B87"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "ARRAY",
                "values": []
              }
            ],
            "grouping": [
              "ed4089a3-2b74-427f-8c05-52e240c1a240"
            ]
          },
          "elseComponent": {
            "componentId": "ECA17CD0-1867-41FC-A363-17A7FB23494F",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Buyer known",
          "storeResult": false,
          "thenComponent": {
            "componentId": "07D82168-B93F-4AAF-9297-67C805654F96",
            "componentType": "ELEMENT"
          }
        },
        "name": "Buyer already in sevdesk?",
        "nextElementIds": [
          "ECA17CD0-1867-41FC-A363-17A7FB23494F",
          "07D82168-B93F-4AAF-9297-67C805654F96"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "notes": "Returns the next free sevdesk customer number, which is how a flow avoids creating a contact with a duplicate one.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::getNextCustomerNumber",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the next customer number Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::getNextCustomerNumber",
          "legacyElementId": "JS###v1###SevdeskService###getNextCustomerNumber",
          "methodName": "getNextCustomerNumber",
          "position": {
            "x": 390,
            "y": 710
          }
        },
        "flowElementId": "9AEECA1A-275C-4894-910A-B3466B215147",
        "groupId": null,
        "id": "ECA17CD0-1867-41FC-A363-17A7FB23494F",
        "metaInfo": {
          "bodyParams": [],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getNextCustomerNumber",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Next number",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the next customer number",
        "nextElementIds": [
          "6A4B3C15-B83C-4B46-BA17-D6B52DBB32BD"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Creates a contact in sevdesk. Addresses and phone numbers are separate resources added afterwards.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::createContact",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "categoryId": {
              "3": "Kunde"
            }
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Create the buyer Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::createContact",
          "legacyElementId": "JS###v1###SevdeskService###createContact",
          "methodName": "createContact",
          "position": {
            "x": 422,
            "y": 874
          }
        },
        "flowElementId": "D04D6B52-9D04-47CA-9450-12CCDFBEF373",
        "groupId": null,
        "id": "6A4B3C15-B83C-4B46-BA17-D6B52DBB32BD",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "name",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "firstName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "firstName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "lastName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "lastName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "categoryId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "3"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customerNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Next number",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "ECA17CD0-1867-41FC-A363-17A7FB23494F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "status",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "1000"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "parentContactId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "name2",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "academicTitle",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "title",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "gender",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "birthday",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "description",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Shopify buyer "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "email",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "vatNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxOffice",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "bankAccount",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "bankNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "exemptVat",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "defaultTimeToPay",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "defaultCashbackTime",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "defaultCashbackPercent",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "defaultDiscountAmount",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "defaultDiscountPercentage",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "buyerReference",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "governmentAgency",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "createContact",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "New buyer",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Create the buyer",
        "nextElementIds": [
          "98FA7B0D-FD57-4EC3-9068-5D795242B3FE"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Finds sevdesk contacts whose custom field holds a given value, which is how an external identifier can be used to look a contact up.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::findContactsByCustomFieldValue",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Find the buyer in sevdesk Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::findContactsByCustomFieldValue",
          "legacyElementId": "JS###v1###SevdeskService###findContactsByCustomFieldValue",
          "methodName": "findContactsByCustomFieldValue",
          "position": {
            "x": 1011.0975594452962,
            "y": 535.4722072669961
          }
        },
        "flowElementId": "DFA52A90-0D5B-4ED2-A5AC-10102586B31D",
        "groupId": null,
        "id": "549D558D-A385-4074-9E64-4EDA746D0B87",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "value",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "buyerKey",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customFieldSettingId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "customFieldId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customFieldName",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "limit",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 1
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "offset",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "findContactsByCustomFieldValue",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Found buyer",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Find the buyer in sevdesk",
        "nextElementIds": [
          "42B6C607-4DD0-4CD3-A999-2CAE6AFFC251"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Lists all Payment Intents. You can provide various options to filter the list.",
          "elementId": "EXTENSION:::SHARED:::default:::stripe:::getPaymentIntentsList",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get recent Stripe payments Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::stripe:::getPaymentIntentsList",
          "legacyElementId": "JS###v1###Stripe###getPaymentIntentsList",
          "methodName": "getPaymentIntentsList",
          "position": {
            "x": 1480,
            "y": 866
          }
        },
        "flowElementId": "5F9B90B4-4F86-4E4C-81A8-70A291FADA7F",
        "groupId": null,
        "id": "1929212F-B869-4E46-9B26-F3E7D4D83D1B",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "options",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "stripeQuery",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Get recent Stripe payments', Error: OAuth Connection is required",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getPaymentIntentsList",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Stripe payments",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "stripe",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get recent Stripe payments",
        "nextElementIds": [
          "D1292B06-0436-4173-AE42-D28B92AB3BE2"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Match the Stripe payment Result"
          },
          "position": {
            "x": 1484,
            "y": 1022
          }
        },
        "flowElementId": "79E0EBD4-9F3D-4BCE-8C30-2EFA7AB8C3E4",
        "groupId": null,
        "id": "D1292B06-0436-4173-AE42-D28B92AB3BE2",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "payments",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Stripe payments",
                    "subPathSegments": [
                      {
                        "key": "data",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "1929212F-B869-4E46-9B26-F3E7D4D83D1B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "checkAccounts",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Check accounts",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "21264EE2-B164-45DB-8155-BA50ED8BC353"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "accountName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Stripe account in sevdesk",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Stripe account in sevdesk"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "total",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "total",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "currency",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "currency",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "email",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "email",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "orderName",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "orderName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "orderCreated",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "orderCreated",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const zeroDecimal = ['bif', 'clp', 'djf', 'gnf', 'jpy', 'kmf', 'krw', 'mga', 'pyg', 'rwf', 'ugx', 'vnd', 'vuv', 'xaf', 'xof', 'xpf'];\nconst cur = String(currency || '').toLowerCase();\nconst factor = zeroDecimal.includes(cur) ? 1 : 100;\nconst expected = Math.round(Number(total) * factor);\nconst name = String(orderName || '');\nconst digits = name.replace(/\\D/g, '');\nconst mail = String(email || '').toLowerCase();\nconst orderTime = Date.parse(orderCreated) / 1000;\n\n// Same amount and currency, already succeeded, and tied to this order by its number or the buyer's email.\nconst mentionsOrder = p => {\n  const hay = `${p.description || ''} ${JSON.stringify(p.metadata || {})}`;\n  return (name && hay.includes(name)) || (digits && new RegExp(`\\\\b${digits}\\\\b`).test(hay));\n};\nconst sameBuyer = p => mail && String(p.receipt_email || '').toLowerCase() === mail;\nconst matches = (payments || [])\n  .filter(p => p && p.status === 'succeeded' && String(p.currency).toLowerCase() === cur && Number(p.amount_received) === expected)\n  .filter(p => mentionsOrder(p) || sameBuyer(p))\n  .sort((a, b) => Math.abs(a.created - orderTime) - Math.abs(b.created - orderTime));\nconst payment = matches[0];\nif (!payment) {\n  return { found: false, reason: `No succeeded Stripe payment of ${total} ${cur.toUpperCase()} for order ${name} yet. The invoice stays open.` };\n}\n\nconst wanted = String(accountName || '').trim().toLowerCase();\nconst account = (checkAccounts || []).find(a => String(a.name || '').toLowerCase().includes(wanted));\nif (!account) {\n  throw new Error(`Stripe payment ${payment.id} matches order ${name}, but sevdesk has no check account named like \"${accountName}\". Create one for Stripe or change the flow setting Stripe account in sevdesk.`);\n}\nreturn {\n  found: true,\n  paymentId: payment.id,\n  amount: payment.amount_received / factor,\n  date: new Date(payment.created * 1000).toISOString().slice(0, 10),\n  checkAccountId: String(account.id),\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Payment match",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Match the Stripe payment",
        "nextElementIds": [
          "E20285E8-D7A8-4454-9D4D-045185D2A412"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Books a payment against a sevdesk invoice by linking an amount, a date and a check account to it, which is what marks it paid in the books.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::bookInvoice",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "type": {
              "N": "Normal Booking"
            }
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Book the payment Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::bookInvoice",
          "legacyElementId": "JS###v1###SevdeskService###bookInvoice",
          "methodName": "bookInvoice",
          "position": {
            "x": 1498,
            "y": 1288
          }
        },
        "flowElementId": "5F7B37CE-067A-4690-9F6A-B2699C9E0080",
        "groupId": null,
        "id": "2F9AFAFA-5FF3-4BEE-BC7B-CAB6C25F60CF",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "invoiceId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "invoice",
                        "optional": false
                      },
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "amount",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Payment match",
                    "subPathSegments": [
                      {
                        "key": "amount",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D1292B06-0436-4173-AE42-D28B92AB3BE2"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "date",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Payment match",
                    "subPathSegments": [
                      {
                        "key": "date",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D1292B06-0436-4173-AE42-D28B92AB3BE2"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "type",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "N"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "checkAccountId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Payment match",
                    "subPathSegments": [
                      {
                        "key": "checkAccountId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D1292B06-0436-4173-AE42-D28B92AB3BE2"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "checkAccountTransactionId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "createFeed",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "bookInvoice",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Booked payment",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Book the payment",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Emails a sevdesk invoice to the customer, which also marks it as sent. A sent invoice may no longer be changed.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::sendInvoiceViaEmail",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Email the invoice Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::sendInvoiceViaEmail",
          "legacyElementId": "JS###v1###SevdeskService###sendInvoiceViaEmail",
          "methodName": "sendInvoiceViaEmail",
          "position": {
            "x": 1228,
            "y": 866
          }
        },
        "flowElementId": "BB17CF18-DAD9-4DA4-AA59-08D54C75BA35",
        "groupId": null,
        "id": "6A926E73-0402-4C41-A745-9FA405434932",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "invoiceId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "invoice",
                        "optional": false
                      },
                      {
                        "key": "id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "toEmail",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "email",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "subject",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Invoice "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "invoice",
                        "optional": false
                      },
                      {
                        "key": "invoiceNumber",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": " for your order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "text",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Hello "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "firstName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ",<br><br>thank you for your order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ". Your invoice "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Invoice",
                    "subPathSegments": [
                      {
                        "key": "objects",
                        "optional": false
                      },
                      {
                        "key": "invoice",
                        "optional": false
                      },
                      {
                        "key": "invoiceNumber",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": " is attached.<br><br>Kind regards"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "copy",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "ccEmail",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "bccEmail",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "additionalAttachments",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendXml",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendInvoiceViaEmail",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Sent invoice",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Email the invoice",
        "nextElementIds": [
          "1929212F-B869-4E46-9B26-F3E7D4D83D1B"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 1494,
            "y": 1138
          }
        },
        "flowElementId": "C59403AD-0C0C-4AAA-BC6D-A0BD05B6AAAC",
        "groupId": null,
        "id": "E20285E8-D7A8-4454-9D4D-045185D2A412",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "3c751b5b-dca2-4b9f-90fb-e2b7f7619a62",
                "nestedOperation": null,
                "operation": "isTrue",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Payment match",
                      "subPathSegments": [
                        {
                          "key": "found",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "D1292B06-0436-4173-AE42-D28B92AB3BE2"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "3c751b5b-dca2-4b9f-90fb-e2b7f7619a62"
            ]
          },
          "elseComponent": null,
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Payment found",
          "storeResult": false,
          "thenComponent": {
            "componentId": "2F9AFAFA-5FF3-4BEE-BC7B-CAB6C25F60CF",
            "componentType": "ELEMENT"
          }
        },
        "name": "Stripe payment found?",
        "nextElementIds": [
          "2F9AFAFA-5FF3-4BEE-BC7B-CAB6C25F60CF"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "notes": "Creates a sevdesk invoice together with its positions and discounts, or updates an existing one when an invoice ID is given.",
          "elementId": "EXTENSION:::SHARED:::default:::sevdesk:::createInvoice",
          "isFirstElement": false,
          "dynamicOptionLabels": {
            "status": {
              "100": "Draft"
            },
            "invoiceType": {
              "RE": "Invoice"
            }
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Create the invoice Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::sevdesk:::createInvoice",
          "legacyElementId": "JS###v1###SevdeskService###createInvoice",
          "methodName": "createInvoice",
          "position": {
            "x": 946,
            "y": 870
          }
        },
        "flowElementId": "892CB1FA-D8AB-4C42-A652-FF10ABF4E135",
        "groupId": null,
        "id": "3E3004DE-1AEE-4BDA-ABC5-93AAFC1C8B1B",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "contactId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "EXECUTION_CONTEXT_DATA_BUCKET_VARIABLE",
                    "label": "Buyer - contactId",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_PATH",
                    "value": "executionContext.dataBuckets.Buyer.contactId",
                    "valueSegments": [
                      {
                        "key": "executionContext",
                        "optional": false
                      },
                      {
                        "key": "dataBuckets",
                        "optional": false
                      },
                      {
                        "key": "Buyer",
                        "optional": false
                      },
                      {
                        "key": "contactId",
                        "optional": false
                      }
                    ]
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "contactPersonId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "contactPersonId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "addressCountryId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "countryId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceDate",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "invoiceDate",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "currency",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "currency",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "positions",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "positions",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "status",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "100"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "invoiceType",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "RE"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxRuleId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxType",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxSetId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxText",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taxRate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "discount",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 0
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "header",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "headText",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Thank you for your order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "."
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "footText",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "address",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "address",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "timeToPay",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "deliveryDate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "deliveryDateUntil",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "payDate",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "paymentMethodId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "smallSettlement",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "showNet",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "showNet",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customerInternalNote",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Shopify order "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Order",
                    "subPathSegments": [
                      {
                        "key": "name",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "DEC544F4-6917-45C4-AABE-A7F31794FF8B"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "propertyIsEInvoice",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "accountIntervall",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "discounts",
              "type": "COMPLEX_LIST",
              "value": []
            },
            {
              "name": "positionsToDelete",
              "type": "COMPLEX_LIST",
              "value": []
            },
            {
              "name": "discountsToDelete",
              "type": "COMPLEX_LIST",
              "value": []
            },
            {
              "name": "filename",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "properties",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Prepared",
                    "subPathSegments": [
                      {
                        "key": "invoiceTax",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "A04C0042-3CC3-44CD-A631-985D2F38CC99"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "createInvoice",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Invoice",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "sevdesk",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Create the invoice",
        "nextElementIds": [
          "6A926E73-0402-4C41-A745-9FA405434932"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      }
    ],
    "firstElementId": "66941658-FDAF-459C-9B46-FEC8825FC5B4",
    "groups": [
      {
        "clientMetadata": {
          "elementId": "actions-group",
          "isFirstElement": false,
          "blockDefinitionId": "actions-group",
          "viewport": {
            "x": 384.72204521546695,
            "y": 57.72694507852111,
            "zoom": 0.6643429070482555
          },
          "position": {
            "x": 690,
            "y": 400
          }
        },
        "flowElementId": "CAD42890-6450-459C-BB1B-4B892D281ED2",
        "groupId": null,
        "id": "A60A2737-C210-4D30-9BCF-B0DD2F129599",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "onFailElemId": null,
          "resultAlias": "grp",
          "storeResult": true,
          "transitionMode": "ON_COMPLETION"
        },
        "name": "Read the sevdesk setup",
        "nextElementIds": [
          "A04C0042-3CC3-44CD-A631-985D2F38CC99"
        ],
        "nextGroupIds": [],
        "type": "ACTIONS"
      }
    ],
    "id": "4D7D8FF8-5F4D-4388-86EB-FB35BF7403D0",
    "metaInfo": {
      "clientValidationState": {
        "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
        "valid": false
      },
      "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
      "executionStaticData": [
        {
          "description": "The sevdesk tax rule the invoices use on bookkeeping Update 2.0. 1 is taxable sales in Germany.",
          "error": null,
          "name": "sevdesk tax rule",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "The name of the sevdesk contact custom field that holds each buyer's Shopify customer ID.",
          "error": null,
          "name": "Shopify ID field in sevdesk",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "The name, or part of the name, of the sevdesk check account that Stripe payments are booked to.",
          "error": null,
          "name": "Stripe account in sevdesk",
          "type": "STRING",
          "value": ""
        }
      ],
      "initialData": null,
      "initialDataDefaultValues": {},
      "ownerFlowVersionId": null,
      "schedule": null,
      "sharedMemory": {
        "anchor": {
          "missingAnchorPolicy": null,
          "path": null,
          "type": "FLOW_MEMORY"
        },
        "expirationInSec": null
      },
      "wasLive": false
    }
  },
  "slaCalendars": [],
  "slaGoals": [],
  "subFlows": [],
  "exportDate": "2026-11-17T09:57:59.779Z"
}
