{
  "schema_version": "1.0.0",
  "id": "shopify-paid-order-log-flag",
  "title": "Log paid Shopify orders and flag the odd ones",
  "category": "ecommerce",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Log every paid Shopify order in a sheet and post the unusual ones to Slack before they ship: big first orders, country mismatches, stacked codes.",
  "tags": [
    "shopify",
    "orders",
    "fraud-check",
    "google-sheets",
    "slack"
  ],
  "apps": [
    "Shopify",
    "Code by Zapier",
    "Google Sheets",
    "Filter by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 4 steps after the trigger",
      "Filter by Zapier",
      "premium app: Shopify"
    ]
  },
  "tasks": {
    "typical": 2,
    "max": 3
  },
  "trigger": {
    "app": "Shopify",
    "event": "New Paid Order",
    "kind": "instant",
    "title": "New paid order",
    "why": "Fires when an order is marked paid, so unpaid drafts and pending bank transfers stay out of the log.",
    "config": {
      "Store": "YOUR_STORE"
    },
    "outputs": [
      "id",
      "order_number",
      "email",
      "customer_first_name",
      "customer_name",
      "total_price",
      "subtotal_price",
      "currency",
      "shipping_country_code",
      "billing_country_code",
      "line_item_count",
      "line_item_titles",
      "line_item_quantities",
      "line_item_prices",
      "line_item_skus",
      "discount_codes",
      "customer_orders_count",
      "created_at",
      "admin_url"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "flags",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Check the order for odd signals",
      "why": "Runs plain rules (high value, billing and shipping countries differ, large first order, 10+ items, two or more discount codes, a disposable email domain) and returns them as one comma-separated word list a Filter can test.",
      "code": {
        "language": "javascript",
        "module": "order-flags",
        "file": "code/order-flags.js"
      },
      "input_data": {
        "total": "{{trigger.total_price}}",
        "currency": "{{trigger.currency}}",
        "shipping_country": "{{trigger.shipping_country_code}}",
        "billing_country": "{{trigger.billing_country_code}}",
        "item_count": "{{trigger.line_item_count}}",
        "customer_order_count": "{{trigger.customer_orders_count}}",
        "discount_codes": "{{trigger.discount_codes}}",
        "email": "{{trigger.email}}",
        "high_value_threshold": "800"
      },
      "outputs": [
        "flags",
        "flag_count",
        "is_odd",
        "summary"
      ]
    },
    {
      "key": "log",
      "kind": "action",
      "app": "Google Sheets",
      "event": "Create Spreadsheet Row",
      "title": "Log the order",
      "why": "Every paid order is logged with its flags, so the sheet doubles as a record of what was checked.",
      "fields": {
        "Drive": "My Google Drive",
        "Spreadsheet": "Store orders",
        "Worksheet": "Paid orders",
        "Columns": {
          "paid_at": "{{trigger.created_at}}",
          "order_number": "{{trigger.order_number}}",
          "customer": "{{trigger.customer_name}}",
          "email": "{{trigger.email}}",
          "total": "{{trigger.total_price}}",
          "currency": "{{trigger.currency}}",
          "ship_to": "{{trigger.shipping_country_code}}",
          "flags": "{{flags.flags}}",
          "admin_link": "{{trigger.admin_url}}"
        }
      },
      "outputs": [
        "id",
        "row_number"
      ]
    },
    {
      "key": "odd",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only orders with at least one flag",
      "why": "Most orders have no flags and stop here. That is the point: Slack only hears about the exceptions.",
      "conditions": [
        [
          {
            "field": "{{flags.is_odd}}",
            "operator": "(Boolean) Is true"
          }
        ]
      ],
      "usually": false
    },
    {
      "key": "warn",
      "kind": "action",
      "app": "Slack",
      "event": "Send Channel Message",
      "title": "Post the order for a second look",
      "why": "Gives the packer the reason and a link to the order in Shopify admin, so the check takes a minute.",
      "fields": {
        "Channel": "#orders-review",
        "Message Text": ":mag: Order #{{trigger.order_number}} from {{trigger.customer_name}}: {{flags.summary}}. Hold it until someone checks: {{trigger.admin_url}}",
        "Send as a bot?": "Yes",
        "Bot Name": "Zap alerts",
        "Include a link to this Zap?": "No"
      },
      "outputs": [
        "ts",
        "permalink"
      ]
    }
  ]
}
