portage-ucp-shopify 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/portage/ucp/shopify/adapter.rb +45 -10
- data/lib/portage/ucp/shopify/queries.rb +7 -0
- data/lib/portage/ucp/shopify/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a58454217826e6adbbd5890a72590dfcb149433563ea405f6f7619873bf3a5a
|
|
4
|
+
data.tar.gz: dd1487e65da0b6109e6de33c015245e82eedaf408422c9a2c2bc39acf06e37d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd3012473d74a06019d3ad2c8c2d13305c4dc57b9aca177f1d2a8d4514f9098f6b41311351c4c6bce1b659031669ee5926727c7cf98ffa2a36db7706f5d9d224
|
|
7
|
+
data.tar.gz: 6833cb36b19eaaca8eef4b3e51508bef631b85b4faf84f9d4d7859350e159ea76b60f2b3b95045b511fb10412c9fa5aaf10c8a2fb06c4d8e9ff53db8f9ebf614
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ pre-1.0, so APIs may still shift between minor versions.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.7.0] - 2026-10-13
|
|
10
|
+
|
|
11
|
+
- **Added: cart, checkout and order responses carry the shop's `policies[]`** (UCP 2026-08-25). The Storefront `shop { refundPolicy shippingPolicy }` becomes `dev.ucp.shopping.policy.return` and the custom `com.shopify.policy.shipping`, each with the policy `url` and a `description` of the sanitized `html` plus a tag-stripped `plain`. A policy the merchant never wrote is omitted. It costs one extra Storefront request per adapter instance (cached for the process, so a policy edited later shows after a restart); a failed fetch, or a client without a `storefront_access_token`, yields no policies rather than an error. Catalog responses don't carry it. Requires `portage-ucp` 0.15 (design-log §60).
|
|
12
|
+
|
|
9
13
|
## [0.6.1] - 2026-10-07
|
|
10
14
|
|
|
11
15
|
- **Fixed: a checkout the shopper paid for in the browser now reads as `completed` from a new process.** Status lived only in the creating process, so `portage orders reconcile` always saw `incomplete`, or not-found once Storefront stopped returning the cart. `#get_checkout` now runs the Admin `orders(query: "cart_token:…")` search the adapter already used at completion, and when an order exists reports `completed` with the `order` confirmation (id and `statusPageUrl`), rebuilding the checkout from the order if the cart is gone. No order, or a failed search, keeps `incomplete`/not-found. Needs the Admin token, and `portage-ucp` 0.13.0 for the `CheckoutState` platform hook, so the gem now requires `portage-ucp` `~> 0.13`. Patch-level.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "bigdecimal"
|
|
2
|
+
require "cgi"
|
|
2
3
|
|
|
3
4
|
module Portage
|
|
4
5
|
module Ucp
|
|
@@ -55,6 +56,8 @@ module Portage
|
|
|
55
56
|
include Portage::Ucp::Support::Retry
|
|
56
57
|
|
|
57
58
|
SUBMIT_POLL_MAX_ATTEMPTS = 3
|
|
59
|
+
POLICY_TYPES = { "refundPolicy" => "dev.ucp.shopping.policy.return",
|
|
60
|
+
"shippingPolicy" => "com.shopify.policy.shipping" }.freeze
|
|
58
61
|
|
|
59
62
|
def initialize(client:)
|
|
60
63
|
super()
|
|
@@ -81,18 +84,18 @@ module Portage
|
|
|
81
84
|
|
|
82
85
|
def get_cart(cart_id:)
|
|
83
86
|
cart_node = fetch_cart_node(cart_id)
|
|
84
|
-
cart_node && Mapper.cart(cart_node)
|
|
87
|
+
cart_node && with_policies(Mapper.cart(cart_node))
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
def create_cart(line_items:, idempotency_key:, discount_codes: nil)
|
|
88
|
-
dedup(idempotency_key) { Mapper.cart(create_cart_node(line_items, discount_codes)) }
|
|
91
|
+
dedup(idempotency_key) { with_policies(Mapper.cart(create_cart_node(line_items, discount_codes))) }
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
# Full replacement, matching UCP's real cart semantics: Storefront has
|
|
92
95
|
# no atomic "replace all lines" mutation, so this removes every current
|
|
93
96
|
# line then adds the desired ones back (two Storefront calls).
|
|
94
97
|
def update_cart(cart_id:, line_items:, idempotency_key:, discount_codes: nil)
|
|
95
|
-
dedup(idempotency_key) { Mapper.cart(replace_lines(cart_id, line_items, discount_codes)) }
|
|
98
|
+
dedup(idempotency_key) { with_policies(Mapper.cart(replace_lines(cart_id, line_items, discount_codes))) }
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
# Shopify has no cart-cancellation mutation — carts simply expire.
|
|
@@ -107,7 +110,7 @@ module Portage
|
|
|
107
110
|
cart_node = create_cart_node(line_items, discount_codes)
|
|
108
111
|
cart_node = apply_fulfillment(cart_node["id"], fulfillment) if fulfillment
|
|
109
112
|
record_checkout_status(cart_node["id"], "incomplete")
|
|
110
|
-
Mapper.checkout(cart_node, status: "incomplete")
|
|
113
|
+
with_policies(Mapper.checkout(cart_node, status: "incomplete"))
|
|
111
114
|
end
|
|
112
115
|
end
|
|
113
116
|
|
|
@@ -116,9 +119,10 @@ module Portage
|
|
|
116
119
|
# #platform_checkout_order).
|
|
117
120
|
def get_checkout(checkout_id:)
|
|
118
121
|
cart_node = fetch_cart_node(checkout_id)
|
|
119
|
-
return checkout_from_platform_order(checkout_id) unless cart_node
|
|
122
|
+
return with_policies(checkout_from_platform_order(checkout_id)) unless cart_node
|
|
120
123
|
|
|
121
|
-
Mapper.checkout(cart_node, status: checkout_status(checkout_id),
|
|
124
|
+
with_policies(Mapper.checkout(cart_node, status: checkout_status(checkout_id),
|
|
125
|
+
order: checkout_order(checkout_id)))
|
|
122
126
|
end
|
|
123
127
|
|
|
124
128
|
# Full replacement, same rationale as #update_cart — Shopify checkout
|
|
@@ -128,7 +132,7 @@ module Portage
|
|
|
128
132
|
cart_node = replace_lines(checkout_id, line_items, discount_codes)
|
|
129
133
|
cart_node = apply_fulfillment(checkout_id, fulfillment) if fulfillment
|
|
130
134
|
record_checkout_status(checkout_id, "incomplete")
|
|
131
|
-
Mapper.checkout(cart_node, status: "incomplete")
|
|
135
|
+
with_policies(Mapper.checkout(cart_node, status: "incomplete"))
|
|
132
136
|
end
|
|
133
137
|
end
|
|
134
138
|
|
|
@@ -151,14 +155,14 @@ module Portage
|
|
|
151
155
|
dedup(idempotency_key) do
|
|
152
156
|
record_checkout_status(checkout_id, "canceled")
|
|
153
157
|
cart_node = fetch_cart_node(checkout_id)
|
|
154
|
-
Mapper.checkout(cart_node, status: "canceled")
|
|
158
|
+
with_policies(Mapper.checkout(cart_node, status: "canceled"))
|
|
155
159
|
end
|
|
156
160
|
end
|
|
157
161
|
|
|
158
162
|
def get_order(order_id:)
|
|
159
163
|
data = @client.admin_query(Queries::GET_ORDER, variables: { id: order_id })
|
|
160
164
|
node = data["order"]
|
|
161
|
-
node && Mapper.order(node, checkout_id: checkout_id_for(order_id))
|
|
165
|
+
node && with_policies(Mapper.order(node, checkout_id: checkout_id_for(order_id)))
|
|
162
166
|
end
|
|
163
167
|
|
|
164
168
|
# orderCancel returns only a (possibly still-pending) job — the
|
|
@@ -207,6 +211,37 @@ module Portage
|
|
|
207
211
|
|
|
208
212
|
private
|
|
209
213
|
|
|
214
|
+
# The shop's refund policy as a UCP `dev.ucp.shopping.policy.return`
|
|
215
|
+
# (and shipping as the custom `com.shopify.policy.shipping`), attached
|
|
216
|
+
# to cart, checkout and order responses. One Storefront query per
|
|
217
|
+
# adapter instance, cached; ponytail: no expiry, a policy edited
|
|
218
|
+
# mid-process shows after restart. A failed fetch is not cached and
|
|
219
|
+
# yields no policies, so it never breaks a cart or checkout.
|
|
220
|
+
def with_policies(result)
|
|
221
|
+
result&.with(policies: policies)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def policies
|
|
225
|
+
@policies ||= begin
|
|
226
|
+
shop = @client.storefront_query(Queries::SHOP_POLICIES)["shop"] || {}
|
|
227
|
+
POLICY_TYPES.filter_map { |key, type| policy_entry(type, shop[key]) }
|
|
228
|
+
end
|
|
229
|
+
rescue StandardError
|
|
230
|
+
[]
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def policy_entry(type, policy)
|
|
234
|
+
return unless policy && policy["body"]
|
|
235
|
+
|
|
236
|
+
{ "type" => type, "url" => policy["url"],
|
|
237
|
+
"description" => { "html" => policy["body"], "plain" => html_to_text(policy["body"]) } }.compact
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def html_to_text(html)
|
|
241
|
+
text = html.gsub(%r{</(p|div|li|h\d)>|<br\s*/?>}i, "\n").gsub(/<[^>]*>/, "")
|
|
242
|
+
CGI.unescapeHTML(text).gsub(/\n{3,}/, "\n\n").strip
|
|
243
|
+
end
|
|
244
|
+
|
|
210
245
|
def raise_on_errors!(data, field, errors_key)
|
|
211
246
|
errors = data.dig(field, errors_key)
|
|
212
247
|
raise Portage::Ucp::Shopify::UserError.new(field, errors) if errors && !errors.empty?
|
|
@@ -339,7 +374,7 @@ module Portage
|
|
|
339
374
|
pay_for_cart(checkout_id, cart_node.dig("cost", "totalAmount"), payment_token)
|
|
340
375
|
|
|
341
376
|
status, order, resume_url = poll_submission(checkout_id, idempotency_key)
|
|
342
|
-
Mapper.checkout(cart_node, status: status, order: order, resume_url: resume_url)
|
|
377
|
+
with_policies(Mapper.checkout(cart_node, status: status, order: order, resume_url: resume_url))
|
|
343
378
|
end
|
|
344
379
|
end
|
|
345
380
|
|
|
@@ -98,6 +98,13 @@ module Portage
|
|
|
98
98
|
GRAPHQL
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
# Storefront ShopPolicy (title, body as sanitized HTML, url); null when
|
|
102
|
+
# the merchant never wrote one. Fetched once per adapter, see
|
|
103
|
+
# Adapter#policies.
|
|
104
|
+
SHOP_POLICIES = <<~GRAPHQL.freeze
|
|
105
|
+
query ShopPolicies { shop { refundPolicy { body url } shippingPolicy { body url } } }
|
|
106
|
+
GRAPHQL
|
|
107
|
+
|
|
101
108
|
CART_FIELDS = <<~GRAPHQL.freeze
|
|
102
109
|
id
|
|
103
110
|
checkoutUrl
|
metadata
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: portage-ucp-shopify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Whitbread
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bigdecimal
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: portage-ucp
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
16
30
|
requirements:
|
|
17
31
|
- - "~>"
|
|
18
32
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
33
|
+
version: '0.15'
|
|
20
34
|
type: :runtime
|
|
21
35
|
prerelease: false
|
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
37
|
requirements:
|
|
24
38
|
- - "~>"
|
|
25
39
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.
|
|
40
|
+
version: '0.15'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: rake
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|