-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-pay-orders-having-a-certain-tag.json
25 lines (25 loc) · 4.76 KB
/
auto-pay-orders-having-a-certain-tag.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"docs": "Use this task to quickly designate certain orders to be automatically marked as paid. Runs for orders as they're created and updated, and can also be run manually, to scan all orders in your store at once.\n\nWhen running manually, use test mode first to ensure that you'll receive the results you expect. :)",
"halt_action_run_sequence_on_error": false,
"name": "Auto-pay orders having a certain tag",
"online_store_javascript": null,
"options": {
"required_order_tag__required": null,
"test_mode__boolean": true
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.topic contains \"shopify/orders\" %}\n {% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n tags\n canMarkAsPaid\n }\n }\n {% endcapture %}\n\n {% assign result = query | shopify %}\n\n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"order\": {\n \"tags\": [\n {{ options.required_order_tag__required | json }}\n ],\n \"canMarkAsPaid\": true\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n {% endif %}\n\n {% assign order_node = result.data.order %}\n\n {% if order_node.tags contains options.required_order_tag__required %}\n {% if order_node.canMarkAsPaid == false %}\n {% log \"Order cannot be manually marked as paid - skipping.\" %}\n {% elsif options.test_mode__boolean %}\n {% action \"echo\" \"This order qualifies to be marked as paid.\" %}\n {% else %}\n {% action \"shopify\" %}\n mutation {\n orderMarkAsPaid(input: {\n id: {{ order.admin_graphql_api_id | json }}\n }) {\n order {\n fullyPaid\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n {% endif %}\n{% elsif event.topic == \"mechanic/user/trigger\" %}\n {% assign cursor = nil %}\n\n {% for n in (0..100) %}\n {% capture query %}\n query {\n orders(\n first: 250\n after: {{ cursor | json }}\n query: {{ options.required_order_tag__required | json | prepend: \"-financial_status:paid tag:\" | json }}\n ) {\n pageInfo {\n hasNextPage\n }\n edges {\n cursor\n node {\n id\n name\n tags\n canMarkAsPaid\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = query | shopify %}\n\n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"orders\": {\n \"edges\": [\n {\n \"node\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"name\": \"#1234\",\n \"tags\": [\n {{ options.required_order_tag__required | json }}\n ],\n \"canMarkAsPaid\": true\n }\n }\n ]\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n {% endif %}\n\n {% for edge in result.data.orders.edges %}\n {% assign order_node = edge.node %}\n\n {% if order_node.canMarkAsPaid == false %}\n {% continue %}\n {% endif %}\n\n {% unless order_node.tags contains options.required_order_tag__required %}\n {% continue %}\n {% endunless %}\n\n {% if options.test_mode__boolean %}\n {% assign message = \"Order \" | append: order_node.name | append: \" qualifies to be marked as paid.\" %}\n {% action \"echo\" message %}\n {% else %}\n {% action \"shopify\" %}\n mutation {\n orderMarkAsPaid(input: {\n id: {{ order_node.id | json }}\n }) {\n order {\n name\n fullyPaid\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n {% endfor %}\n\n {% if orders_result.data.orders.pageInfo.hasNextPage %}\n {% assign cursor = orders_result.data.orders.edges.last.cursor %}\n {% else %}\n {% break %}\n {% endif %}\n {% endfor %}\n{% endif %}",
"subscriptions": [
"shopify/orders/create",
"shopify/orders/updated",
"mechanic/user/trigger"
],
"subscriptions_template": "shopify/orders/create\nshopify/orders/updated\nmechanic/user/trigger",
"tags": [
"Orders",
"Payment",
"Tag",
"Watch"
]
}