-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathauto-tag-new-orders-based-on-payment-method.json
More file actions
22 lines (22 loc) · 3.54 KB
/
Copy pathauto-tag-new-orders-based-on-payment-method.json
File metadata and controls
22 lines (22 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "This task checks the payment gateways and payment methods on order creation and updates, and tags the order accordingly if any of the gateways or methods match a configured value.\n\nConfigure the \"Payment gateway names and tags\" fields with each payment gateway name you wish to monitor on the left, and the associated tag on the right.\n\nTip: this task will log out the payment gateways and methods from success transactions on each run, so review the log to verify any configuration values you wish to use (e.g. \"gift_card\", \"paypal\"). Case-sensitivity is important!",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag new orders based on payment method",
"online_store_javascript": null,
"options": {
"payment_gateway_names_and_tags__keyval_required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign payment_gateway_names_and_tags = options.payment_gateway_names_and_tags__keyval_required %}\n\n{% if event.topic == \"shopify/orders/create\" or event.topic == \"shopify/orders/updated\" %}\n {% comment %}\n -- get order and transactions data\n {% endcomment %}\n\n {% capture query %}\n query {\n order(\n id: {{ order.admin_graphql_api_id | json }}\n ) {\n id\n name\n displayFinancialStatus\n paymentGatewayNames\n tags\n transactions(first: 10) {\n id\n status\n kind\n formattedGateway\n gateway\n paymentDetails {\n __typename\n ... on BasePaymentDetails {\n paymentMethodName\n }\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 \"order\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"paymentGatewayNames\": {{ array | push: payment_gateway_names_and_tags.first.first | json }}\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n {% endif %}\n\n {% assign order = result.data.order %}\n\n {% log order_data: order %}\n\n {% comment %}\n -- get all payment gateways and payment methods (from success transactions)\n {% endcomment %}\n\n {% assign payment_gateways_and_methods\n = order.transactions\n | where: \"status\", \"SUCCESS\"\n | default: array\n | map: \"paymentDetails\"\n | map: \"paymentMethodName\"\n | concat: order.paymentGatewayNames\n | uniq\n %}\n\n {% assign tags_to_add = array %}\n\n {% for keyval in payment_gateway_names_and_tags %}\n {% assign payment_gateway_name = keyval[0] %}\n {% assign tag = keyval[1] %}\n\n {% if payment_gateways_and_methods contains payment_gateway_name %}\n {% unless order.tags contains tag %}\n {% assign tags_to_add = tags_to_add | push: tag %}\n {% endunless %}\n {% endif %}\n {% endfor %}\n\n {% if tags_to_add != blank %}\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.id | json }}\n tags: {{ tags_to_add | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n{% endif %}\n",
"subscriptions": [
"shopify/orders/create",
"shopify/orders/updated+15.seconds"
],
"subscriptions_template": "shopify/orders/create\nshopify/orders/updated+15.seconds",
"tags": [
"Auto-Tag",
"Orders",
"Payment"
]
}