forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
91 lines (85 loc) · 2.25 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
88
89
90
91
{% if event.preview %}
{% action "shopify" %}
mutation {
orderCapture(
input: {
id: "gid://shopify/Order/1234567890"
parentTransactionId: "gid://shopify/OrderTransaction/1234567890"
amount: "10.00"
currency: {{ shop.currency }}
}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% else %}
{% assign cursor = nil %}
{% assign conditions = array %}
{% assign conditions[0] = "financial_status:authorized" %}
{% if options.include_partially_paid_orders__boolean %}
{% assign conditions[1] = "financial_status:partially_paid" %}
{% endif %}
{% for n in (0..100) %}
{% capture query %}
query {
orders(
first: 200
after: {{ cursor | json }}
query: {{ conditions | join: " OR " | json }}
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
transactions(
capturable: true
) {
id
kind
}
totalCapturableSet {
presentmentMoney {
amount
currencyCode
}
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% for edge in result.data.orders.edges %}
{% assign transaction = edge.node.transactions | where: "kind", "AUTHORIZATION" | first %}
{% action "shopify" %}
mutation {
orderCapture(
input: {
id: {{ edge.node.id | json }}
parentTransactionId: {{ transaction.id | json }}
amount: {{ edge.node.totalCapturableSet.presentmentMoney.amount | json }}
currency: {{ edge.node.totalCapturableSet.presentmentMoney.currencyCode }}
}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endfor %}
{% if result.data.pageInfo.hasNextPage %}
{% assign cursor = result.data.orders.edges.last.cursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}