-
Notifications
You must be signed in to change notification settings - Fork 35
/
script.liquid
87 lines (80 loc) · 2.16 KB
/
script.liquid
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
id
name
displayFinancialStatus
transactions(capturable: true) {
id
kind
totalUnsettledSet {
presentmentMoney {
amount
currencyCode
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"order": {
"id": "gid://shopify/Order/1234567890",
"name": "#SAMPLE",
"displayFinancialStatus": "AUTHORIZED",
"transactions": [
{
"id": "gid://shopify/OrderTransaction/1234567890",
"kind": "AUTHORIZATION",
"totalUnsettledSet": {
"presentmentMoney": {
"amount": "12.34",
"currencyCode": "USD"
}
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign order = result.data.order %}
{% if order.displayFinancialStatus == "AUTHORIZED" or order.displayFinancialStatus == "PARTIALLY_PAID" %}
{% assign authorized_transactions = order.transactions | where: "kind", "AUTHORIZATION" %}
{% for transaction in authorized_transactions %}
{% assign unsettled_amount = transaction.totalUnsettledSet.presentmentMoney.amount | times: 1.0 %}
{% if unsettled_amount > 0 %}
{% action "shopify" %}
mutation {
orderCapture(
input: {
id: {{ order.id | json }}
parentTransactionId: {{ transaction.id | json }}
amount: {{ unsettled_amount | json }}
currency: {{ transaction.totalUnsettledSet.presentmentMoney.currencyCode }}
}
) {
transaction {
id
status
parentTransaction {
id
kind
}
}
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endfor %}
{% endif %}