{ "name": "Lead Qualified -> Payment Email", "nodes": [ { "parameters": { "schema": { "__rl": true, "mode": "list", "value": "public" }, "tableName": { "__rl": true, "value": "sales_orders", "mode": "list", "cachedResultName": "sales_orders" }, "additionalFields": {}, "options": {} }, "id": "4337dcb2-b962-4bdb-8517-20e570016c05", "name": "Postgres Trigger", "type": "n8n-nodes-base.postgresTrigger", "typeVersion": 1, "position": [0, 0], "credentials": { "postgres": { "id": "__POSTGRES_CREDENTIAL_ID__", "name": "Postgres account" } } }, { "parameters": { "operation": "executeQuery", "query": "SELECT c.id, c.name, c.email, c.phone,\n so.order_number, so.total_eur, so.deposit_eur,\n so.date_from, so.date_to, so.vehicle_label,\n so.daily_subtotal, so.weekend_subtotal,\n so.subtotal_eur, so.vat_eur,\n so.total_days, so.weekday_count, so.weekend_day_count\nFROM public.customers c\nJOIN public.sales_orders so ON so.customer_id = c.id\nWHERE so.id = '{{ $json.payload.id }}'::uuid", "options": {} }, "id": "ca4ca61e-fea9-4044-9586-216af016cb2e", "name": "Fetch Order Data", "type": "n8n-nodes-base.postgres", "typeVersion": 2.5, "position": [224, 0], "credentials": { "postgres": { "id": "__POSTGRES_CREDENTIAL_ID__", "name": "Postgres account" } } }, { "parameters": { "mode": "runOnceForEachItem", "jsCode": "const item = $json;\n\nconst formatEur = (value) => {\n const n = Number(value || 0);\n return new Intl.NumberFormat(\"de-AT\", { style: \"currency\", currency: \"EUR\" }).format(n);\n};\n\nconst formatDate = (value) => {\n if (!value) return \"-\";\n const d = new Date(value);\n if (Number.isNaN(d.getTime())) return String(value);\n return new Intl.DateTimeFormat(\"de-AT\", { day: \"2-digit\", month: \"2-digit\", year: \"numeric\" }).format(d);\n};\n\nconst orderNumber = item.order_number || \"\";\nconst dateFrom = formatDate(item.date_from);\nconst dateTo = formatDate(item.date_to);\nconst rentalRange = `${dateFrom} bis ${dateTo}`;\n\nconst depositEur = formatEur(item.deposit_eur);\nconst rentalEur = formatEur(item.total_eur);\nconst subtotalEur = formatEur(item.subtotal_eur);\nconst vatEur = formatEur(item.vat_eur);\n\nconst safeName = item.name || \"Kundin/Kunde\";\nconst vehicle = item.vehicle_label || \"-\";\n\nconst subject = `MC Cars – Buchung bestätigt (${orderNumber}) – Zahlungsinformationen`;\n\nconst paypalButton = (url, alt) => `\n \n \"${alt}\"\n \n`;\n\nconst html = `\n
\n \n \n \n \n \n \n \n
\n
MC Cars
\n

Ihre Miete wurde freigegeben

\n
\n

Guten Tag ${safeName},

\n

\n Ihre Buchung wurde auf Basis der von Ihnen bereitgestellten Informationen geprüft und freigegeben.\n Nachfolgend finden Sie die Zahlungsanweisungen für Kaution und Mietbetrag.\n

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Bestellnummer${orderNumber}
Fahrzeug${vehicle}
Mietzeitraum${rentalRange}
Zwischensumme${subtotalEur}
MwSt.${vatEur}
Mietbetrag${rentalEur}
Kaution${depositEur}
\n\n

1) Kaution bezahlen

\n

Sie können die Kaution in Höhe von ${depositEur} per PayPal bezahlen:

\n ${paypalButton('__PAYPAL_KAUTION_LINK__', 'PayPal Kaution bezahlen')}\n

Alternativ ist Barzahlung möglich. In diesem Fall antworten Sie bitte so schnell wie möglich auf diese E-Mail, damit wir die Übergabe bestätigen können.

\n\n

2) Mietbetrag bezahlen

\n

Den Mietbetrag von ${rentalEur} können Sie über folgenden PayPal-Button bezahlen:

\n ${paypalButton('__PAYPAL_MIETE_LINK__', 'PayPal Mietbetrag bezahlen')}\n\n

Falls Sie Fragen haben, antworten Sie einfach auf diese E-Mail.

\n

Freundliche Grüße
MC Cars Team

\n
\n
`;\n\nreturn {\n toEmail: item.email,\n subject,\n html,\n};\n" }, "id": "a39ba066-d093-4444-bd45-6a295d599637", "name": "Build Payment Email", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [448, 0] }, { "parameters": { "fromEmail": "office@mc-cars.at", "toEmail": "={{ $json.toEmail }}", "subject": "={{ $json.subject }}", "html": "={{ $json.html }}", "options": { "appendAttribution": false }, "continueOnFail": true }, "id": "c537fb83-bc97-4015-b9fe-5ff3ca8b2c97", "name": "Send Payment Email", "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, "position": [672, 0], "credentials": { "smtp": { "id": "__SMTP_CREDENTIAL_ID__", "name": "SMTP account" } } }, { "parameters": { "operation": "executeQuery", "query": "UPDATE public.sales_orders SET email_sent = 1, updated_at = now() WHERE id = '{{ $json.payload.id }}'::uuid", "options": {} }, "id": "update-email-sent-1", "name": "Update email_sent = 1", "type": "n8n-nodes-base.postgres", "typeVersion": 2.5, "position": [1024, -100], "credentials": { "postgres": { "id": "__POSTGRES_CREDENTIAL_ID__", "name": "Postgres account" } } }, { "parameters": { "operation": "executeQuery", "query": "UPDATE public.sales_orders SET email_sent = 2, updated_at = now() WHERE id = '{{ $json.payload.id }}'::uuid", "options": {} }, "id": "update-email-sent-2", "name": "Update email_sent = 2", "type": "n8n-nodes-base.postgres", "typeVersion": 2.5, "position": [1024, 100], "credentials": { "postgres": { "id": "__POSTGRES_CREDENTIAL_ID__", "name": "Postgres account" } } }, { "parameters": { "conditions": { "options": { "testDirectly": true }, "boolean": [ { "leftValue": "={{ $json.error }}", "condition": "isEmpty" } ] } }, "id": "check-email-error", "name": "IF", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [896, 0] } ], "pinData": {}, "connections": { "Postgres Trigger": { "main": [ [ { "node": "Fetch Order Data", "type": "main", "index": 0 } ] ] }, "Fetch Order Data": { "main": [ [ { "node": "Build Payment Email", "type": "main", "index": 0 } ] ] }, "Build Payment Email": { "main": [ [ { "node": "Send Payment Email", "type": "main", "index": 0 } ] ] }, "Send Payment Email": { "main": [ [ { "node": "IF", "type": "main", "index": 0 } ] ] }, "IF": { "main": [ [ { "node": "Update email_sent = 1", "type": "main", "index": 0 } ], [ { "node": "Update email_sent = 2", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": { "executionOrder": "v1", "binaryMode": "separate" }, "versionId": "814e8f72-95dc-4097-bc94-76fe437448ef", "meta": { "templateCredsSetupCompleted": true }, "id": "rI1gUpcRXSikxWhi", "tags": [ { "name": "mc-cars" } ] }