[ { "label": "Cancel and void an order if pending after 24 hours", "trigger_type": [ "order_created" ], "object_type": "order", "app_id": "triggers", "tags": [], "settings": { "priority": 0, "condition_groups": { "1": { "conditions": { "1": { "field": "order.delay", "settings": { "wait": "custom", "custom_wait": "12 hours", "check_date": { "submit": "Check Date" }, "token_browser": "{{ Browse Tokens }}", "token_object_type": "order", "condition_type": "AND" }, "weight": 999 }, "2": { "field": "order.financial_status", "settings": { "operator": "any", "value": { "pending": "pending", "authorized": 0, "partially_paid": 0, "paid": 0, "partially_refunded": 0, "refunded": 0, "voided": 0 }, "condition_type": "AND" }, "weight": 999 } }, "actions": { "1": { "type": "custom", "settings": { "wait": "0", "custom_wait": "", "label": "Cancel Pending Payment and void the order", "twig": "{% set payments_to_cancel = [] %}\r\n{% set payments_cancelled = [] %}\r\n\r\n{% set response = RUN_ACTION(\"shopify_api_request\", {\r\n method: \"GET\",\r\n path: \"orders\/\"~order.id~\"\/transactions\",\r\n data: {limit: 5}\r\n}) %}\r\n\r\n{% for transaction in response.response.transactions if transaction.kind==\"void\" %}\r\n{% set payments_cancelled = payments_cancelled|merge([transaction.parent_id]) %}\r\n{% endfor %}\r\n\r\n{% for transaction in response.response.transactions if transaction.kind==\"sale\" and transaction.id not in payments_cancelled %}\r\n{% set payments_to_cancel = payments_to_cancel|merge([transaction.id]) %}\r\n{% endfor %}\r\n\r\n{% for payment in payments_to_cancel %}\r\n{% set cancelled = RUN_ACTION(\"shopify_api_request\", {\r\n method: \"POST\",\r\n path: \"orders\/\"~order.id~\"\/transactions\",\r\n data: {\r\n \"transaction\": {\r\n \"kind\": \"void\",\r\n \"parent_id\": payment\r\n }\r\n}\r\n}) %}\r\n{% endfor %}\r\n\r\n{% do QUEUE_ACTION('order_cancel',{ \r\n resource: order,\r\n reason: \"other\",\r\n restock: true,\r\n void: true,\r\n notify_customer: false\r\n}) \r\n%}\r\n{% do QUEUE_ACTION('order_add_tags',{ \r\n resource: order,\r\n tags: [\"AUTOCLOSED\"]\r\n}) \r\n%}", "token_object_type": "order" }, "weight": 999, "target_key": "order" } } } }, "shared_workflow_id": 33215 } } ]