Skip to content

Commit

Permalink
make sure order id is returned in query (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekhaus authored Jul 31, 2023
1 parent e214482 commit c38622f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
id
paymentGatewayNames
transactions(capturable: true) {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign payment_gateway_names = options.payment_gateway_names__array_required %}\n\n{% if payment_gateway_names contains \"shopify_payments\" %}\n {% error \"Shopify payments does not support multiple partial captures on a single authorization. Verify that any configured payment gateways support multiple captures.\" %}\n{% endif %}\n\n{% if event.preview %}\n {% assign order = hash %}\n {% assign order[\"admin_graphql_api_id\"] = \"gid://shopify/Order/1234567890\" %}\n {% assign order[\"financial_status\"] = \"partially_paid\" %}\n{% endif %}\n\n{% if order.financial_status != \"authorized\" and order.financial_status != \"partially_paid\" %}\n {% log \"Order is not either authorized or partially_paid.\" %}\n\n{% else %}\n {% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n paymentGatewayNames\n transactions(capturable: true) {\n id\n amountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n totalPriceSet {\n presentmentMoney {\n amount\n }\n }\n subtotalPriceSet {\n presentmentMoney {\n amount\n }\n }\n totalCapturableSet {\n presentmentMoney {\n amount\n }\n }\n fulfillments {\n name\n fulfillmentLineItems(first: 250) {\n pageInfo {\n hasNextPage\n }\n nodes {\n discountedTotalSet {\n presentmentMoney {\n amount\n }\n }\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 \"paymentGatewayNames\": [\n {{ payment_gateway_names.first | json }}\n ],\n \"transactions\": [\n {\n \"id\": \"gid://shopify/OrderTransaction/1234567890\",\n \"amountSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.99\",\n \"currencyCode\": \"USD\"\n }\n }\n }\n ],\n \"totalPriceSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.99\"\n }\n },\n \"subtotalPriceSet\": {\n \"presentmentMoney\": {\n \"amount\": \"10.0\"\n }\n },\n \"totalCapturableSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.54\"\n }\n },\n \"fulfillments\": [\n {\n \"name\": \"#1234-F1\",\n \"fulfillmentLineItems\": {\n \"nodes\": [\n {\n \"discountedTotalSet\": {\n \"presentmentMoney\": {\n \"amount\": \"5.0\"\n }\n }\n }\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 {% unless order.paymentGatewayNames.size == 1 and payment_gateway_names contains order.paymentGatewayNames.first %}\n {% log\n message: \"This order did not use one of the configured gateways or there are multiple gateways on the order; skipping.\",\n configured_payment_gateway_names: payment_gateway_names,\n order: result.data.order\n %}\n {% break %}\n {% endunless %}\n\n {% assign total = order.totalPriceSet.presentmentMoney.amount | times: 1.0 %}\n {% assign total_captured = total | minus: order.totalCapturableSet.presentmentMoney.amount %}\n {% assign subtotal = order.subtotalPriceSet.presentmentMoney.amount | times: 1.0 %}\n {% assign subtotal_fulfilled = 0.0 %}\n\n {% for fulfillment in order.fulfillments %}\n {% if fulfillment.fulfillmentLineItems.pageInfo.hasNextPage %}\n {% error \"This order has a fulfillment with more than 250 line items in it. This is not supported by this task.\" %}\n {% break %}\n {% endif %}\n\n {% for fulfillment_line_item in fulfillment.fulfillmentLineItems.nodes %}\n {% assign subtotal_fulfilled = subtotal_fulfilled | plus: fulfillment_line_item.discountedTotalSet.presentmentMoney.amount %}\n {% endfor %}\n {% endfor %}\n\n {% assign desired_total_captured = subtotal_fulfilled | divided_by: subtotal | times: total %}\n {% assign amount_to_capture = desired_total_captured | minus: total_captured | times: 100 | round | divided_by: 100.0 %}\n {% assign parent_transaction = order.transactions.first %}\n\n {% log\n total: total,\n total_captured: total_captured,\n subtotal: subtotal,\n subtotal_fulfilled: subtotal_fulfilled,\n desired_total_captured: desired_total_captured,\n amount_to_capture: amount_to_capture,\n parent_transaction: parent_transaction\n %}\n\n {% if order.capturable == false %}\n {% log \"This order is not capturable.\" %}\n\n {% elsif amount_to_capture == 0 %}\n {% log \"Nothing to capture at this time.\" %}\n\n {% else %}\n {% action \"shopify\" %}\n mutation {\n orderCapture(\n input: {\n id: {{ order.id | json }}\n parentTransactionId: {{ parent_transaction.id | json }}\n amount: {{ amount_to_capture | append: \"\" | json }}\n currency: {{ parent_transaction.amountSet.presentmentMoney.currencyCode }}\n }\n ) {\n transaction {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n\n {% log order %}\n{% endif %}\n",
"subscriptions": [
"shopify/orders/updated"
],
"script": "{% assign payment_gateway_names = options.payment_gateway_names__array_required %}\n\n{% if payment_gateway_names contains \"shopify_payments\" %}\n {% error \"Shopify payments does not support multiple partial captures on a single authorization. Verify that any configured payment gateways support multiple captures.\" %}\n{% endif %}\n\n{% if event.preview %}\n {% assign order = hash %}\n {% assign order[\"admin_graphql_api_id\"] = \"gid://shopify/Order/1234567890\" %}\n {% assign order[\"financial_status\"] = \"partially_paid\" %}\n{% endif %}\n\n{% if order.financial_status != \"authorized\" and order.financial_status != \"partially_paid\" %}\n {% log \"Order is not either authorized or partially_paid.\" %}\n\n{% else %}\n {% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n paymentGatewayNames\n transactions(capturable: true) {\n id\n amountSet {\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n totalPriceSet {\n presentmentMoney {\n amount\n }\n }\n subtotalPriceSet {\n presentmentMoney {\n amount\n }\n }\n totalCapturableSet {\n presentmentMoney {\n amount\n }\n }\n fulfillments {\n name\n fulfillmentLineItems(first: 250) {\n pageInfo {\n hasNextPage\n }\n nodes {\n discountedTotalSet {\n presentmentMoney {\n amount\n }\n }\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 \"paymentGatewayNames\": [\n {{ payment_gateway_names.first | json }}\n ],\n \"transactions\": [\n {\n \"id\": \"gid://shopify/OrderTransaction/1234567890\",\n \"amountSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.99\",\n \"currencyCode\": \"USD\"\n }\n }\n }\n ],\n \"totalPriceSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.99\"\n }\n },\n \"subtotalPriceSet\": {\n \"presentmentMoney\": {\n \"amount\": \"10.0\"\n }\n },\n \"totalCapturableSet\": {\n \"presentmentMoney\": {\n \"amount\": \"16.54\"\n }\n },\n \"fulfillments\": [\n {\n \"name\": \"#1234-F1\",\n \"fulfillmentLineItems\": {\n \"nodes\": [\n {\n \"discountedTotalSet\": {\n \"presentmentMoney\": {\n \"amount\": \"5.0\"\n }\n }\n }\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 {% unless order.paymentGatewayNames.size == 1 and payment_gateway_names contains order.paymentGatewayNames.first %}\n {% log\n message: \"This order did not use one of the configured gateways or there are multiple gateways on the order; skipping.\",\n configured_payment_gateway_names: payment_gateway_names,\n order: result.data.order\n %}\n {% break %}\n {% endunless %}\n\n {% assign total = order.totalPriceSet.presentmentMoney.amount | times: 1.0 %}\n {% assign total_captured = total | minus: order.totalCapturableSet.presentmentMoney.amount %}\n {% assign subtotal = order.subtotalPriceSet.presentmentMoney.amount | times: 1.0 %}\n {% assign subtotal_fulfilled = 0.0 %}\n\n {% for fulfillment in order.fulfillments %}\n {% if fulfillment.fulfillmentLineItems.pageInfo.hasNextPage %}\n {% error \"This order has a fulfillment with more than 250 line items in it. This is not supported by this task.\" %}\n {% break %}\n {% endif %}\n\n {% for fulfillment_line_item in fulfillment.fulfillmentLineItems.nodes %}\n {% assign subtotal_fulfilled = subtotal_fulfilled | plus: fulfillment_line_item.discountedTotalSet.presentmentMoney.amount %}\n {% endfor %}\n {% endfor %}\n\n {% assign desired_total_captured = subtotal_fulfilled | divided_by: subtotal | times: total %}\n {% assign amount_to_capture = desired_total_captured | minus: total_captured | times: 100 | round | divided_by: 100.0 %}\n {% assign parent_transaction = order.transactions.first %}\n\n {% log\n total: total,\n total_captured: total_captured,\n subtotal: subtotal,\n subtotal_fulfilled: subtotal_fulfilled,\n desired_total_captured: desired_total_captured,\n amount_to_capture: amount_to_capture,\n parent_transaction: parent_transaction\n %}\n\n {% if order.capturable == false %}\n {% log \"This order is not capturable.\" %}\n\n {% elsif amount_to_capture == 0 %}\n {% log \"Nothing to capture at this time.\" %}\n\n {% else %}\n {% action \"shopify\" %}\n mutation {\n orderCapture(\n input: {\n id: {{ order.id | json }}\n parentTransactionId: {{ parent_transaction.id | json }}\n amount: {{ amount_to_capture | append: \"\" | json }}\n currency: {{ parent_transaction.amountSet.presentmentMoney.currencyCode }}\n }\n ) {\n transaction {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endif %}\n\n {% log order %}\n{% endif %}\n",
"subscriptions": ["shopify/orders/updated"],
"subscriptions_template": "shopify/orders/updated",
"tags": [
"Fulfillment",
"Orders",
"Payment"
]
"tags": ["Fulfillment", "Orders", "Payment"]
}

0 comments on commit c38622f

Please sign in to comment.