-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-capture-order-payment-based-on-shipping-method.json
20 lines (20 loc) · 3.65 KB
/
auto-capture-order-payment-based-on-shipping-method.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"docs": "This task auto-captures payment if the customer has selected a certain shipping method. Useful for expedited order fulfillments.\n\nTo use this task, populate the \"Allowed shipping methods\" list with shipping method titles (e.g. \"Economy\"). In Shopify, shipping method titles are configured as \"rates\"; you can find yours by navigating to Settings > Shipping and delivery, and then looking at the rates within each shipping zone.\n\nFor expected results, be sure to enable \"Manually capture payment for orders\" in Shopify, [using this guide](https://help.shopify.com/en/manual/payments/payment-authorization#set-up-manual-capture-of-credit-card-payments).",
"halt_action_run_sequence_on_error": true,
"name": "Auto-capture order payment based on shipping method",
"online_store_javascript": null,
"options": {
"allowed_shipping_methods__required_array": []
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": true,
"script": "{% unless options.allowed_shipping_methods__required_array contains order.shipping_lines.first.title or event.preview %}\n {% log message: \"This order is not using a configured shipping method; skipping.\" %}\n {% break %}\n{% endunless %}\n\n{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n name\n displayFinancialStatus\n transactions(capturable: true) {\n id\n kind\n totalUnsettledSet {\n presentmentMoney {\n amount\n currencyCode\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 \"name\": \"#SAMPLE\",\n \"displayFinancialStatus\": \"AUTHORIZED\",\n \"transactions\": [\n {\n \"id\": \"gid://shopify/OrderTransaction/1234567890\",\n \"kind\": \"AUTHORIZATION\",\n \"totalUnsettledSet\": {\n \"presentmentMoney\": {\n \"amount\": \"12.34\",\n \"currencyCode\": \"USD\"\n }\n }\n }\n ]\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% assign order = result.data.order %}\n\n{% if order.displayFinancialStatus == \"AUTHORIZED\" or order.displayFinancialStatus == \"PARTIALLY_PAID\" %}\n {% assign authorized_transactions = order.transactions | where: \"kind\", \"AUTHORIZATION\" %}\n\n {% for transaction in authorized_transactions %}\n {% assign unsettled_amount = transaction.totalUnsettledSet.presentmentMoney.amount | times: 1.0 %}\n\n {% if unsettled_amount > 0 %}\n {% action \"shopify\" %}\n mutation {\n orderCapture(\n input: {\n id: {{ order.id | json }}\n parentTransactionId: {{ transaction.id | json }}\n amount: {{ unsettled_amount | json }}\n currency: {{ transaction.totalUnsettledSet.presentmentMoney.currencyCode }}\n }\n ) {\n transaction {\n id\n status\n parentTransaction {\n id\n kind\n }\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n {% endfor %}\n{% endif %}\n",
"subscriptions": [
"shopify/orders/create"
],
"subscriptions_template": "shopify/orders/create",
"tags": [
"Payment",
"Shipping"
]
}