{
  "name": "FlowPantry - Ask for a review after a Square or Stripe payment",
  "nodes": [
    {
      "id": "2ddfebb7-b241-41f4-b454-70550473d5ce",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "payment-succeeded",
        "responseMode": "onReceived",
        "options": {}
      },
      "webhookId": "34ba3684-58bd-4124-8c2a-06a8ba0576f2"
    },
    {
      "id": "da459132-cd55-4cfb-a571-49dfc44f0162",
      "name": "Extract customer",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return $input.all().map(i=>{const b=i.json.body||i.json;const o=(b.data&&b.data.object)||{};const p=o.payment||o;const c=o.customer_details||o.billing_details||{};return {json:{name:(c.name||'there').split(' ')[0],phone:c.phone||p.buyer_phone_number||null,email:c.email||p.buyer_email_address||null}}}).filter(i=>i.json.phone||i.json.email);"
      }
    },
    {
      "id": "64db4aa3-0246-4438-9112-152a1938d14c",
      "name": "Wait 3 hours",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        480,
        300
      ],
      "parameters": {
        "amount": 3,
        "unit": "hours"
      }
    },
    {
      "id": "73959193-2b7d-457c-8299-56595a23b2be",
      "name": "Ask for review",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "=https://api.twilio.com/2010-04-01/Accounts/{{$env.TWILIO_ACCOUNT_SID}}/Messages.json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "To",
              "value": "={{$('Extract customer').item.json.phone}}"
            },
            {
              "name": "From",
              "value": "={{$env.TWILIO_FROM_NUMBER}}"
            },
            {
              "name": "Body",
              "value": "=Thanks for visiting {{$env.BUSINESS_NAME}}, {{$('Extract customer').item.json.name}}! Mind leaving a quick review? {{$env.GOOGLE_REVIEW_URL}} Reply STOP to opt out."
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Extract customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract customer": {
      "main": [
        [
          {
            "node": "Wait 3 hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 3 hours": {
      "main": [
        [
          {
            "node": "Ask for review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}