{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Notify Customers on WhatsApp When Stripe Payment Succeeds with MoltFlow",
  "tags": [
    {
      "name": "whatsapp"
    },
    {
      "name": "stripe"
    },
    {
      "name": "payments"
    },
    {
      "name": "moltflow"
    },
    {
      "name": "receipts"
    }
  ],
  "nodes": [
    {
      "id": "i1000001-0000-4000-0900-000000000010",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -300
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## Stripe Payment \u2192 WhatsApp Receipt\nSend an instant WhatsApp confirmation when a customer's Stripe payment succeeds, powered by [MoltFlow](https://molt.waiflow.app).\n\n**How it works:**\n1. Stripe fires a `checkout.session.completed` webhook\n2. Customer name, email, phone, and amount are extracted\n3. A WhatsApp receipt message is sent via MoltFlow\n4. Result is logged for tracking"
      },
      "typeVersion": 1
    },
    {
      "id": "i1000001-0000-4000-0900-000000000011",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -300
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 280,
        "content": "## Setup (5 min)\n1. Create a [MoltFlow account](https://molt.waiflow.app) and connect WhatsApp\n2. Activate this workflow \u2014 copy the webhook URL\n3. In Stripe Dashboard \u2192 Developers \u2192 Webhooks, add the n8n URL for `checkout.session.completed`\n4. Set `YOUR_SESSION_ID` in the Format Receipt node\n5. Add MoltFlow API Key: Header Auth \u2192 `X-API-Key`\n\n**Note:** Customer phone is pulled from Stripe's `customer_details.phone`"
      },
      "typeVersion": 1
    },
    {
      "id": "i1000001-0000-4000-0900-000000000001",
      "name": "Stripe Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        0
      ],
      "parameters": {
        "path": "stripe-payment",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "i1000001-0000-4000-0900-000000000002",
      "name": "Format Receipt",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const SESSION_ID = 'YOUR_SESSION_ID';\n\nconst body = $input.first().json.body || $input.first().json;\nconst event = body.data ? body.data.object : body;\n\nconst customerName = event.customer_details\n  ? event.customer_details.name || 'Customer'\n  : 'Customer';\n\nconst phone = event.customer_details && event.customer_details.phone\n  ? event.customer_details.phone.replace(/[^0-9]/g, '')\n  : '';\n\nconst email = event.customer_details\n  ? event.customer_details.email || ''\n  : '';\n\nconst amount = event.amount_total\n  ? (event.amount_total / 100).toFixed(2)\n  : '0.00';\n\nconst currency = (event.currency || 'usd').toUpperCase();\nconst paymentId = event.payment_intent || event.id || '';\n\nif (!phone || phone.length < 7) {\n  return [{ json: { skip: true, reason: 'No phone number on payment', email, paymentId } }];\n}\n\nconst message = `Hi ${customerName}! Your payment of ${currency} ${amount} has been received. Payment ID: ${paymentId.slice(-8)}. Thank you for your purchase! If you have any questions, just reply to this message.`;\n\nreturn [{\n  json: {\n    session_id: SESSION_ID,\n    chat_id: phone + '@c.us',\n    message: message,\n    customer_name: customerName,\n    amount: amount,\n    currency: currency,\n    phone: phone,\n    skip: false\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "i1000001-0000-4000-0900-000000000003",
      "name": "Has Phone?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "not-skip",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.skip }}",
              "rightValue": false
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "i1000001-0000-4000-0900-000000000004",
      "name": "Send WhatsApp Receipt",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        -100
      ],
      "parameters": {
        "url": "https://apiv2.waiflow.app/api/v2/messages/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ JSON.stringify({ session_id: $json.session_id, chat_id: $json.chat_id, message: $json.message }) }}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "i1000001-0000-4000-0900-000000000005",
      "name": "Log Success",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        -100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $('Format Receipt').first().json;\nreturn [{ json: {\n  status: 'sent',\n  customer: data.customer_name,\n  amount: data.currency + ' ' + data.amount\n} }];"
      },
      "typeVersion": 2
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Has Phone?": {
      "main": [
        [
          {
            "node": "Send WhatsApp Receipt",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Format Receipt": {
      "main": [
        [
          {
            "node": "Has Phone?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stripe Webhook": {
      "main": [
        [
          {
            "node": "Format Receipt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Receipt": {
      "main": [
        [
          {
            "node": "Log Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}