{
  "name": "Payment-to-follow-up journey",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "journey/payment",
        "responseMode": "onReceived",
        "options": {
          "rawBody": true
        }
      },
      "id": "6f28cabe-61cf-481b-a9cb-c84ff0ad5106",
      "name": "Payment captured",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "webhookId": "0c088c4b-a1ad-4d62-a519-7495bb23d06a"
    },
    {
      "parameters": {
        "jsCode": "const crypto = require('crypto');\nconst expected = crypto.createHmac('sha256', $env.RAZORPAY_WEBHOOK_SECRET).update($json.rawBody || JSON.stringify($json.body)).digest('hex');\nif (expected !== $json.headers['x-razorpay-signature']) throw new Error('Bad Razorpay signature');\nconst p = $json.body.payload.payment.entity;\nreturn [{ json: { payment_id: p.id, amount: p.amount / 100, email: p.email, phone: p.contact } }];"
      },
      "id": "69e8049f-42f4-46dc-ad4d-7541f7ee5f2b",
      "name": "Verify signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        512,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO supporters (email, phone, first_seen) VALUES ($1, $2, now()) ON CONFLICT (email) DO UPDATE SET phone = EXCLUDED.phone RETURNING (SELECT count(*) FROM payments WHERE email = $1) AS prior_gifts;",
        "options": {
          "queryReplacement": "={{ $json.email }},{{ $json.phone }}"
        }
      },
      "id": "b0fa8717-cbf8-4be8-a46e-57335c2caf39",
      "name": "Upsert supporter",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        784,
        300
      ],
      "credentials": {
        "postgres": {
          "id": "REPLACE_ME",
          "name": "Postgres (self-hosted)"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "g1",
                    "leftValue": "={{ $(\"Verify signature\").item.json.amount }}",
                    "rightValue": 25000,
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "large gift"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "g2",
                    "leftValue": "={{ $json.prior_gifts }}",
                    "rightValue": 0,
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "returning"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "g3",
                    "leftValue": "={{ $json.prior_gifts }}",
                    "rightValue": 0,
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "first-time"
            }
          ]
        },
        "options": {}
      },
      "id": "5a925784-e73b-4407-a44b-e485a89d5a1d",
      "name": "Segment",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1056,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m1",
              "name": "message",
              "value": "Thank you. A member of the team will write to you personally.",
              "type": "string"
            }
          ]
        }
      },
      "id": "d20c6336-0ace-4fa3-a81e-24ddb99546c0",
      "name": "Personal note",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1328,
        154
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m2",
              "name": "message",
              "value": "Thank you for giving again. It makes a real difference.",
              "type": "string"
            }
          ]
        }
      },
      "id": "2b789b6c-aab4-439e-abd6-bd41eb942cd8",
      "name": "Recognition",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1328,
        329
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m3",
              "name": "message",
              "value": "Welcome, and thank you for your first gift.",
              "type": "string"
            }
          ]
        }
      },
      "id": "38ab89d0-d0f2-48e3-ac57-fc07e5d06e6b",
      "name": "Welcome",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1328,
        504
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "w1",
              "leftValue": "={{ $(\"Verify signature\").item.json.phone }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "52ae3b7a-32de-4280-a3ea-d5ce73f139dc",
      "name": "Has WhatsApp?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1600,
        329
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "REPLACE_ME",
        "recipientPhoneNumber": "={{ $(\"Verify signature\").item.json.phone }}",
        "textBody": "={{ $json.message }}"
      },
      "id": "9721de7e-d22f-4173-aba4-a2093cffc168",
      "name": "Send on WhatsApp",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        1872,
        227
      ],
      "credentials": {
        "whatsAppApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp Business"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $(\"Verify signature\").item.json.email }}",
        "subject": "Thank you",
        "message": "={{ $json.message }}"
      },
      "id": "6b8a5973-01e6-48e7-af46-5154ffb02e9e",
      "name": "Send by email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1872,
        446
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "REPLACE_ME",
          "name": "Gmail"
        }
      }
    },
    {
      "parameters": {
        "resume": "timeInterval",
        "amount": 3,
        "unit": "days"
      },
      "id": "7ee9697e-a353-4720-a0ec-cab9720d5949",
      "name": "Wait three days",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2144,
        227
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "REPLACE_ME",
        "recipientPhoneNumber": "={{ $(\"Verify signature\").item.json.phone }}",
        "textBody": "Here is how your gift is being used this week."
      },
      "id": "c811d5ea-0271-4197-afec-73bcc2408b5f",
      "name": "Follow-up",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        2416,
        227
      ],
      "credentials": {
        "whatsAppApi": {
          "id": "REPLACE_ME",
          "name": "WhatsApp Business"
        }
      }
    }
  ],
  "connections": {
    "Payment captured": {
      "main": [
        [
          {
            "node": "Verify signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify signature": {
      "main": [
        [
          {
            "node": "Upsert supporter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert supporter": {
      "main": [
        [
          {
            "node": "Segment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Segment": {
      "main": [
        [
          {
            "node": "Personal note",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Recognition",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Welcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Personal note": {
      "main": [
        [
          {
            "node": "Has WhatsApp?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recognition": {
      "main": [
        [
          {
            "node": "Has WhatsApp?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome": {
      "main": [
        [
          {
            "node": "Has WhatsApp?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has WhatsApp?": {
      "main": [
        [
          {
            "node": "Send on WhatsApp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send by email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send on WhatsApp": {
      "main": [
        [
          {
            "node": "Wait three days",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait three days": {
      "main": [
        [
          {
            "node": "Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "A payment lands, the right message goes out on the right channel."
  },
  "tags": []
}