{
  "name": "Shopify Bestelleingang zu ZUGFeRD E-Rechnung mit E-Mail-Versand",
  "flow": [
    {
      "id": 1,
      "module": "shopify:WatchOrders",
      "version": 2,
      "parameters": {
        "status": "any",
        "financial_status": "paid"
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "1. Shopify: Neue bezahlte Bestellung überwachen"
        }
      }
    },
    {
      "id": 2,
      "module": "http:ActionSendRequest",
      "version": 3,
      "parameters": {
        "handleErrors": false,
        "useCustomHeaders": true,
        "customHeaders": [
          {
            "name": "X-API-Key",
            "value": "zg_test_ouroboros_001"
          },
          {
            "name": "Content-Type",
            "value": "application/json"
          }
        ]
      },
      "mapper": {
        "url": "https://e-rechnung-cloud.de/v1/invoice/generate",
        "method": "post",
        "bodyType": "raw",
        "headers": "",
        "serializeUrl": false,
        "shareCookies": false,
        "parseResponse": false,
        "followRedirect": true,
        "useQuerystring": false,
        "data": "{\n  \"invoice_number\": \"SHOPIFY-{{1.order_number}}\",\n  \"issue_date\": \"{{formatDate(1.created_at; 'YYYY-MM-DD')}}\",\n  \"currency\": \"{{ifempty(1.currency; 'EUR')}}\",\n  \"seller\": {\n    \"name\": \"Mein Shopify Store GmbH\",\n    \"street\": \"Handelsstraße 12\",\n    \"zip_code\": \"20095\",\n    \"city\": \"Hamburg\",\n    \"country\": \"DE\",\n    \"vat_id\": \"DE345678901\",\n    \"iban\": \"DE21200400000123456789\"\n  },\n  \"buyer\": {\n    \"name\": \"{{ifempty(1.customer.first_name; '')}} {{ifempty(1.customer.last_name; 1.billing_address.name)}}\",\n    \"street\": \"{{ifempty(1.billing_address.address1; 'Musteradresse 1')}}\",\n    \"zip_code\": \"{{ifempty(1.billing_address.zip; '10115')}}\",\n    \"city\": \"{{ifempty(1.billing_address.city; 'Berlin')}}\",\n    \"country\": \"{{ifempty(1.billing_address.country_code; 'DE')}}\"\n  },\n  \"line_items\": [\n    {\n      \"description\": \"{{ifempty(1.line_items[1].title; 'Shopify Bestellung')}}\",\n      \"quantity\": \"{{ifempty(1.line_items[1].quantity; 1)}}\",\n      \"unit_price\": \"{{ifempty(1.line_items[1].price; 50.00)}}\",\n      \"tax_rate_percent\": 19.0\n    }\n  ]\n}"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "2. HTTP: ZUGFeRD PDF/A-3 via E-Rechnung Cloud API"
        }
      }
    },
    {
      "id": 3,
      "module": "email:ActionSendAnEmail",
      "version": 2,
      "parameters": {},
      "mapper": {
        "to": [
          "{{ifempty(1.email; 1.customer.email)}}"
        ],
        "subject": "Deine Rechnung zur Shopify-Bestellung #{{1.order_number}}",
        "content": "<p>Hallo {{1.customer.first_name}},<br><br>vielen Dank für deinen Einkauf in unserem Shop! Im Anhang findest du deine offizielle Rechnung im <strong>ZUGFeRD PDF/A-3 Format (EN 16931)</strong>.<br><br>Diese Rechnung erfüllt alle gesetzlichen Vorgaben für die E-Rechnungspflicht.<br><br>Herzliche Grüße<br>Dein Store-Team</p>",
        "attachments": [
          {
            "fileName": "Rechnung_Shopify_{{1.order_number}}.pdf",
            "data": "{{2.data}}"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "3. E-Mail: ZUGFeRD-Rechnung an Kunden versenden"
        }
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "confidential": false,
      "dataloss": false,
      "dlq": false
    },
    "designer": {
      "orphans": []
    }
  }
}