{
  "schema_version": "1.0.0",
  "id": "refund-request-over-limit",
  "title": "Send refund requests over a limit to finance",
  "category": "support",
  "difficulty": "intermediate",
  "featured": false,
  "description": "Pull the order number and amount out of a refund request email and ask finance in Slack when it is over what support may approve.",
  "tags": [
    "refunds",
    "support",
    "gmail",
    "approvals",
    "slack"
  ],
  "apps": [
    "Gmail",
    "AI by Zapier",
    "Code by Zapier",
    "Filter by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 4 steps after the trigger",
      "Filter by Zapier",
      "AI by Zapier"
    ]
  },
  "tasks": {
    "typical": 2,
    "max": 3
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Labeled Email",
    "kind": "polling",
    "title": "New email under Support/Refunds",
    "why": "Fires for each email under the refunds label. Agents can label by hand, or a Gmail filter on \"refund\" can do it.",
    "config": {
      "Label": "Support/Refunds"
    },
    "outputs": [
      "message_id",
      "thread_id",
      "from_email",
      "from_name",
      "to",
      "subject",
      "date",
      "body_plain",
      "snippet",
      "labels",
      "attachment_count",
      "attachment_names"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "extract",
      "kind": "ai",
      "app": "AI by Zapier",
      "event": "Analyze and Return Data",
      "title": "Read the order and amount",
      "why": "Asks for the amount exactly as written, so the Code step can parse \"€189,90\" correctly.",
      "fields": {
        "Model": "Default (fast)",
        "Instructions": "This email asks for a refund. Return order_number (as written), amount_text (the amount the customer wants back, exactly as written with currency symbol or code; empty if they do not say), currency (ISO code if clear), and reason (one short sentence). Do not guess an amount.",
        "Input data": "From: {{trigger.from_name}} <{{trigger.from_email}}>\nSubject: {{trigger.subject}}\n\n{{trigger.body_plain}}",
        "Output fields": "order_number, amount_text, currency, reason"
      },
      "outputs": [
        "order_number",
        "amount_text",
        "currency",
        "reason"
      ]
    },
    {
      "key": "money",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Read the amount",
      "why": "Turns the written amount into cents so the limit check is exact.",
      "code": {
        "language": "javascript",
        "module": "parse-money",
        "file": "code/parse-money.js"
      },
      "input_data": {
        "amount_text": "{{extract.amount_text}}",
        "currency_hint": "{{extract.currency}}"
      },
      "outputs": [
        "amount",
        "amount_fixed",
        "amount_cents",
        "currency",
        "format",
        "needs_review"
      ]
    },
    {
      "key": "over",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only requests over the support limit",
      "why": "Requests of 150.00 or less stop here; support handles them.",
      "conditions": [
        [
          {
            "field": "{{money.amount_cents}}",
            "operator": "(Number) Greater than",
            "value": "15000"
          }
        ]
      ],
      "usually": false
    },
    {
      "key": "ask",
      "kind": "action",
      "app": "Slack",
      "event": "Send Channel Message",
      "title": "Ask finance to approve",
      "why": "Finance gets the order, amount, and reason, and replies in the thread.",
      "fields": {
        "Channel": "#finance-approvals",
        "Message Text": "Refund approval needed: order {{extract.order_number}}, {{money.amount_fixed}} {{money.currency}} for {{trigger.from_email}}. Reason: {{extract.reason}}. Email: https://mail.google.com/mail/u/0/#all/{{trigger.message_id}}",
        "Send as a bot?": "Yes",
        "Bot Name": "Zap alerts",
        "Include a link to this Zap?": "No"
      },
      "outputs": [
        "ts",
        "permalink"
      ]
    }
  ]
}
