{ "name": "Outlevo: First Stripe payment to a closed-won outcome", "nodes": [ { "id": "686369f0-8f2a-4bc7-937e-f7eac3aaf26a", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -360 ], "parameters": { "content": "## How to set it up\n\n**Credentials** (n8n asks for each on first open):\n- **Stripe**: connect your Stripe account.\n- **Outlevo API key**: a Header Auth credential, name `Authorization`, value `Bearer olv_live_…` (Settings → API keys in Outlevo).\n\n**API key scopes**: `companies:read`, `outcomes:write`.\n\nThen switch the workflow to **Active**.", "height": 300, "width": 620 } }, { "id": "bcbabd89-2177-471f-9c52-1de51ef168ee", "name": "Invoice paid", "type": "n8n-nodes-base.stripeTrigger", "typeVersion": 1, "position": [ 0, 0 ], "parameters": { "events": [ "invoice.paid" ] }, "webhookId": "cc93604d-c910-4cd2-8798-a3f53cfb04f4", "credentials": { "stripeApi": { "id": "", "name": "Stripe" } } }, { "id": "b99979f5-1056-433e-83ab-fd0db7389988", "name": "First payment?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 240, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "51ee0c98-59aa-45ef-9ade-c7dc51a907e9", "leftValue": "={{ ($json.data && $json.data.object && $json.data.object.billing_reason) || \"\" }}", "rightValue": "subscription_create", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "39375727-7685-4699-aa52-120035e51ab2", "name": "The invoice", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 480, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Amounts come in the smallest unit (cents) except for zero-decimal currencies like JPY. Free mail names no company: skipped.\nconst ZERO = ['bif', 'clp', 'djf', 'gnf', 'jpy', 'kmf', 'krw', 'mga', 'pyg', 'rwf', 'ugx', 'vnd', 'vuv', 'xaf', 'xof', 'xpf'];\nconst FREE = ['gmail.com', 'googlemail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'live.com', 'icloud.com', 'me.com', 'aol.com', 'proton.me', 'protonmail.com', 'gmx.com', 'mail.com', 'yandex.com', 'mail.ru'];\nreturn $input.all().flatMap((item) => {\n const inv = (item.json.data && item.json.data.object) || {};\n const domain = (String(inv.customer_email || '').split('@')[1] || '').toLowerCase();\n if (!domain || FREE.includes(domain)) return [];\n const currency = String(inv.currency || 'usd').toLowerCase();\n const paidAt = (inv.status_transitions && inv.status_transitions.paid_at) || inv.created || item.json.created;\n return [{ json: { domain, invoice: inv.id, amount: ZERO.includes(currency) ? inv.amount_paid : inv.amount_paid / 100, currency: currency.toUpperCase(), occurred_at: (paidAt ? new Date(paidAt * 1000) : new Date()).toISOString() } }];\n});\n" } }, { "id": "baf09ceb-dd0a-49fa-b8c9-982400d49b61", "name": "Find the company", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 720, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/companies", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "domain", "value": "={{ $json.domain }}" }, { "name": "limit", "value": "1" } ] }, "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "5b0e8fd2-1bb9-46df-acf9-b7695a37c17f", "name": "The company", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// A payer that is not in your accounts is skipped: there is no outreach to credit. Lookups come back in the invoices' order.\nconst invoices = $('The invoice').all();\nreturn $input.all().flatMap((item, i) => {\n const co = (item.json.data || [])[0];\n return co ? [{ json: { ...invoices[i].json, company_id: co.id } }] : [];\n});\n" } }, { "id": "6c235a1d-3291-4247-8034-649fa9d28dcc", "name": "Record closed won", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "POST", "url": "=https://api.outlevo.com/v1/outcomes", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Idempotency-Key", "value": "={{ ('stripe-' + $json.invoice).slice(0, 200) }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ type: 'closed_won', company_id: $json.company_id, occurred_at: $json.occurred_at, amount: $json.amount, currency: $json.currency, external_ref: $json.invoice }) }}", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } } ], "connections": { "Invoice paid": { "main": [ [ { "node": "First payment?", "type": "main", "index": 0 } ] ] }, "First payment?": { "main": [ [ { "node": "The invoice", "type": "main", "index": 0 } ], [] ] }, "The invoice": { "main": [ [ { "node": "Find the company", "type": "main", "index": 0 } ] ] }, "Find the company": { "main": [ [ { "node": "The company", "type": "main", "index": 0 } ] ] }, "The company": { "main": [ [ { "node": "Record closed won", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }