-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce capture amount when items are removed (#283)
- Loading branch information
Showing
3 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
{ | ||
"docs": "Upon the fulfillment of an authorized or partially paid order, this task attempts to capture all open authorized payments for that order. (Multiple authorizations can exist on edited orders or with post-purchase upsells.)\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).\n\n__Please note__: You are responsible for ensuring that fulfillment occurs within the order payment's authorization period.", | ||
"docs": "Upon the fulfillment of an authorized or partially paid order, this task attempts to capture all open authorized payments for that order. (Multiple authorizations can exist on edited orders or with post-purchase upsells.)\n\nIf any items are removed from the order before fulfillment, then this task will reduce the amount captured by the subtotal of the removed line items (including their discounts and taxes, as calculated by Shopify). It will **not** reduce any shipping costs on the order.\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).\n\n__Please note__: You are responsible for ensuring that fulfillment occurs within the order payment's authorization period.", | ||
"halt_action_run_sequence_on_error": true, | ||
"name": "Capture order payment upon fulfillment", | ||
"online_store_javascript": null, | ||
"options": {}, | ||
"order_status_javascript": null, | ||
"perform_action_runs_in_sequence": true, | ||
"script": "{% 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/fulfilled" | ||
], | ||
"script": "{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n name\n displayFinancialStatus\n currentTotalPriceSet {\n presentmentMoney {\n amount\n }\n }\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 \"currentTotalPriceSet\": {\n \"presentmentMoney\": {\n \"amount\": \"23.45\"\n }\n },\n \"transactions\": [\n {\n \"id\": \"gid://shopify/OrderTransaction/1234567890\",\n \"kind\": \"AUTHORIZATION\",\n \"totalUnsettledSet\": {\n \"presentmentMoney\": {\n \"amount\": \"20.00\",\n \"currencyCode\": \"USD\"\n }\n }\n },\n {\n \"id\": \"gid://shopify/OrderTransaction/2345678901\",\n \"kind\": \"AUTHORIZATION\",\n \"totalUnsettledSet\": {\n \"presentmentMoney\": {\n \"amount\": \"10.00\",\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{% assign left_to_capture = order.currentTotalPriceSet.presentmentMoney.amount | times: 1.0 %}\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 {% assign amount_to_capture = unsettled_amount | at_most: left_to_capture %}\n\n {% if amount_to_capture > 0 %}\n {% assign left_to_capture = left_to_capture | minus: amount_to_capture %}\n \n {% action \"shopify\" %}\n mutation {\n orderCapture(\n input: {\n id: {{ order.id | json }}\n parentTransactionId: {{ transaction.id | json }}\n amount: {{ amount_to_capture | 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/fulfilled"], | ||
"subscriptions_template": "shopify/orders/fulfilled", | ||
"tags": [ | ||
"Fulfillment", | ||
"Payment" | ||
] | ||
"tags": ["Fulfillment", "Payment"] | ||
} |