{
  "flow": [
    {
      "id": 2,
      "mapper": {},
      "module": "tally:watchNewResponse",
      "version": 1,
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        }
      },
      "parameters": {
        "__IMTHOOK__": null
      }
    },
    {
      "id": 3,
      "mapper": {
        "limit": "1",
        "query": "email:'{{2.fieldsById.YOUR_TALLY_FIELD}}'",
        "expand": []
      },
      "module": "stripe:searchCustomersAdv",
      "version": 1,
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Find Stripe Customer"
        }
      },
      "parameters": {
        "__IMTCONN__": null
      }
    },
    {
      "id": 4,
      "mapper": {
        "limit": "1",
        "customer": "{{3.id}}"
      },
      "module": "stripe:listPaymentIntents",
      "version": 1,
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Get Payment Amount"
        }
      },
      "parameters": {
        "__IMTCONN__": null
      }
    },
    {
      "id": 5,
      "mapper": null,
      "module": "builtin:BasicRouter",
      "routes": [
        {
          "flow": [
            {
              "id": 6,
              "filter": {
                "name": "$29 or under \u2014 auto-refund",
                "conditions": [
                  [
                    {
                      "a": "{{4.amount}}",
                      "b": "2900",
                      "o": "number:lessorequal"
                    }
                  ]
                ]
              },
              "mapper": {
                "amount": "",
                "charge": "{{4.charges.data[1].id}}",
                "reason": "requested_by_customer",
                "metadata": [],
                "reverse_transfer": false,
                "refund_application_fee": false
              },
              "module": "stripe:createRefund",
              "onerror": [
                {
                  "id": 13,
                  "mapper": {
                    "base": "YOUR_AIRTABLE_BASE_ID",
                    "table": "YOUR_AIRTABLE_TABLE_ID",
                    "record": {
                      "YOUR_FIELD_1": "{{now}}",
                      "YOUR_FIELD_2": "Todo",
                      "YOUR_FIELD_3": "[HIGH SEVERITY] Stripe refund failed for {{2.fieldsById.YOUR_TALLY_FIELD}}: {{6.error.message}}",
                      "YOUR_FIELD_4": "Tally Refund Requests"
                    },
                    "typecast": false,
                    "useColumnId": false
                  },
                  "module": "airtable:ActionCreateRecord",
                  "version": 3,
                  "metadata": {
                    "designer": {
                      "x": 1200,
                      "y": -350,
                      "name": "Log High-Severity Error"
                    }
                  },
                  "parameters": {
                    "__IMTCONN__": null
                  }
                },
                {
                  "id": 14,
                  "mapper": {
                    "text": "\ud83d\udea8 HIGH SEVERITY \u2014 Stripe refund failed in Tally Refund Requests. Customer {{2.fieldsById.YOUR_TALLY_FIELD}} is waiting. Error: {{6.error.message}}. Check Make's execution history immediately.",
                    "chatId": "YOUR_TELEGRAM_CHAT_ID"
                  },
                  "module": "telegram:SendReplyMessage",
                  "version": 1,
                  "metadata": {
                    "designer": {
                      "x": 1500,
                      "y": -350,
                      "name": "Alert \u2014 Refund Failed"
                    }
                  },
                  "parameters": {
                    "__IMTCONN__": null
                  }
                },
                {
                  "id": 15,
                  "mapper": {
                    "count": 3,
                    "retry": true,
                    "interval": 15
                  },
                  "module": "builtin:Break",
                  "version": 1,
                  "metadata": {
                    "designer": {
                      "x": 1800,
                      "y": -350,
                      "name": "Save for Retry"
                    }
                  },
                  "parameters": {}
                }
              ],
              "version": 1,
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": -150,
                  "name": "Issue Refund"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            },
            {
              "id": 7,
              "mapper": {
                "id": "YOUR_KIT_TAG_ID",
                "email": "{{2.fieldsById.YOUR_TALLY_FIELD}}"
              },
              "module": "convertkit:addTagToCustomer",
              "version": 1,
              "metadata": {
                "designer": {
                  "x": 1500,
                  "y": -150,
                  "name": "Tag as Refunded"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            },
            {
              "id": 8,
              "mapper": {
                "email": "{{2.fieldsById.YOUR_TALLY_FIELD}}"
              },
              "module": "convertkit:unsubscribe",
              "version": 1,
              "metadata": {
                "designer": {
                  "x": 1800,
                  "y": -150,
                  "name": "Remove from Sequences"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            },
            {
              "id": 9,
              "mapper": {
                "base": "YOUR_AIRTABLE_BASE_ID",
                "table": "YOUR_AIRTABLE_TABLE_ID",
                "formula": "{Customer} = \"{{2.fieldsById.YOUR_TALLY_FIELD}}\"",
                "maxRecords": 1,
                "useColumnId": false
              },
              "module": "airtable:ActionSearchRecords",
              "version": 3,
              "metadata": {
                "designer": {
                  "x": 2100,
                  "y": -150,
                  "name": "Find Order Record"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            },
            {
              "id": 10,
              "mapper": {
                "id": "{{9.id}}",
                "base": "YOUR_AIRTABLE_BASE_ID",
                "table": "YOUR_AIRTABLE_TABLE_ID",
                "record": {
                  "YOUR_FIELD_1": "Refunded"
                },
                "typecast": true,
                "useColumnId": false
              },
              "module": "airtable:ActionUpdateRecords",
              "version": 3,
              "metadata": {
                "designer": {
                  "x": 2400,
                  "y": -150,
                  "name": "Mark Order Refunded"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            },
            {
              "id": 11,
              "mapper": {
                "text": "\u2705 Refund processed automatically. Email: {{2.fieldsById.YOUR_TALLY_FIELD}} | Amount (cents): {{4.amount}} | Order updated to Refunded in Airtable, tagged + removed from sequences in Kit.",
                "chatId": "YOUR_TELEGRAM_CHAT_ID"
              },
              "module": "telegram:SendReplyMessage",
              "version": 1,
              "metadata": {
                "designer": {
                  "x": 2700,
                  "y": -150,
                  "name": "Notify \u2014 Refund Processed"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 12,
              "filter": {
                "name": "Over $29 \u2014 needs approval",
                "conditions": [
                  [
                    {
                      "a": "{{4.amount}}",
                      "b": "2900",
                      "o": "number:greater"
                    }
                  ]
                ]
              },
              "mapper": {
                "text": "\u26a0\ufe0f Refund needs your approval \u2014 amount is above the $29 auto-refund threshold. Email: {{2.fieldsById.YOUR_TALLY_FIELD}} | Order #: {{2.fieldsById.YOUR_TALLY_FIELD}} | Amount (cents): {{4.amount}} | Reason: {{2.fieldsById.YOUR_TALLY_FIELD}}. Process manually in Stripe, then update Kit and Airtable by hand.",
                "chatId": "YOUR_TELEGRAM_CHAT_ID"
              },
              "module": "telegram:SendReplyMessage",
              "version": 1,
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": 150,
                  "name": "Notify \u2014 Approval Needed"
                }
              },
              "parameters": {
                "__IMTCONN__": null
              }
            }
          ]
        }
      ],
      "version": 1,
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "Check Refund Threshold ($29)"
        }
      }
    }
  ],
  "name": "Refund Chain \u2014 Tally to Stripe to Kit to Airtable",
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "dlq": true,
      "slots": null,
      "dataloss": false,
      "maxErrors": 3,
      "autoCommit": true,
      "roundtrips": 1,
      "sequential": false,
      "confidential": false,
      "freshVariables": false,
      "autoCommitTriggerLast": true
    }
  },
  "scheduling": {
    "type": "immediately",
    "maximum_runs_per_minute": 100
  },
  "interface": {
    "input": [],
    "output": []
  }
}