portage-ucp-magento 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea401b98661b2c2e96586cf55bf37ee69a8287f39399a4131396d96d2cdfd13d
4
- data.tar.gz: a646cb0522acba00f521255af96a7e7d0c7a6c2294536c21b1cb8d728c61a5b3
3
+ metadata.gz: 7a3583ce532646dc6ddf40dc3b43dee13f687130cfdc36537a0bf1b831863b7c
4
+ data.tar.gz: 6c672de6a1b8f492e163a515f6fef183411bf3708b41db8a32e5e5b43b44c0e6
5
5
  SHA512:
6
- metadata.gz: 40ced25b368ea1b9ef46d8fd5e2130971d504b387ea7c7b333290b368eb9d228f73588639640c64352df7d712fc92ac893d4d3237eeaa16870fab27e64762ee2
7
- data.tar.gz: a4ca4a63d937ffbaefb0829845ce38b3d5c3eed397bc33e07953f2484534b86c07a1a08d1c7a76c21dead3da2a056464a831b4ce524261415c4a3c721b59aafd
6
+ metadata.gz: bd726a0a6bd8d7c2d7cacf295a937b381a8e7eb6c6a5760ed4361f338f67608fed98e2221608b6f488d3a14e8f39859f5710bcc54b93f300e2358e56df50acaa
7
+ data.tar.gz: ac8100b5ee1689328aca7b86b68670d25cb5b62d42c14049aae2bc18425aa97f3330d09aa44a11c15abbdd17d89e8deee146f432f03ed7e22882e26d4186f29f
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.2.1] - 2026-10-07
10
+
11
+ - **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 an error once Magento deactivated the quote. `#get_checkout` now resolves the masked cart id to its quote id (`GET /V1/guest-carts/{cartId}`, which still answers for an inactive quote), searches admin orders by `quote_id`, and reports `completed` with the `order` confirmation when one is `processing`, `complete` or `closed`, rebuilding the checkout from that order if the cart can no longer be read. The order search needs `admin_token`. No order, or a failed lookup, keeps `incomplete`; a cart that 404s with no order now returns nil instead of raising `ApiError`, like the other reads. Needs `portage-ucp` 0.13.0 for the `CheckoutState` platform hook, so the gem now requires `portage-ucp` `~> 0.13`. Patch-level.
12
+
9
13
  ## [0.2.0] - 2026-10-05
10
14
 
11
15
  - **Removed the unused `Client#admin_post`.** Nothing in the gem called it. It was public on the client class, so this is **breaking** for any caller using it directly; minor-level for a pre-1.0 gem.
@@ -46,6 +46,13 @@ module Portage
46
46
  # rather than an empty body, which UCP's reads report as nil.
47
47
  include Portage::Ucp::Support::NotFound
48
48
 
49
+ # Order states that mean the order was placed and paid
50
+ # (https://experienceleague.adobe.com/en/docs/commerce-admin/stores-sales/order-management/orders/order-status):
51
+ # `processing` (invoiced), `complete` ("created, paid, and shipped")
52
+ # and `closed` (paid, then refunded). Left out: `new` (no invoice
53
+ # yet), `pending_payment`, `payment_review`, `holded`, `canceled`.
54
+ PLACED_ORDER_STATES = %w[processing complete closed].freeze
55
+
49
56
  def initialize(client:, currency:, site_url: nil, payment_method: nil, payment_data_key: "cc_token",
50
57
  default_address: nil)
51
58
  super()
@@ -125,10 +132,16 @@ module Portage
125
132
  end
126
133
  end
127
134
 
135
+ # Placing an order deactivates the guest cart's quote, and the
136
+ # items/totals endpoints only read an active quote (404 after that),
137
+ # so a not-found here falls back to the order Magento placed from it,
138
+ # if any (see #platform_checkout_order).
128
139
  def get_checkout(checkout_id:)
129
- items, currency = cart_snapshot(checkout_id)
140
+ items, currency = nil_on_not_found { cart_snapshot(checkout_id) }
141
+ return checkout_from_platform_order(checkout_id) unless items
142
+
130
143
  Mapper.checkout(items, id: checkout_id, currency: currency,
131
- status: checkout_status(checkout_id))
144
+ status: checkout_status(checkout_id), order: checkout_order(checkout_id))
132
145
  end
133
146
 
134
147
  # Full replacement, same rationale as #update_cart.
@@ -167,6 +180,27 @@ module Portage
167
180
 
168
181
  private
169
182
 
183
+ # Support::CheckoutState's platform hook. The masked guest-cart id
184
+ # never appears on an order, but `GET /V1/guest-carts/{cartId}`
185
+ # resolves it to the quote's own `id` even after the quote went
186
+ # inactive (GuestCartRepository#get loads it with
187
+ # QuoteRepository#get, not #getActive:
188
+ # https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php),
189
+ # and an order's `quote_id` is that id, searchable through the admin
190
+ # orders endpoint's searchCriteria
191
+ # (https://developer.adobe.com/commerce/webapi/rest/use-rest/performing-searches/).
192
+ def platform_checkout_order(checkout_id)
193
+ quote_id = @client.guest_get("/guest-carts/#{checkout_id}")["id"]
194
+ return nil unless quote_id
195
+
196
+ params = { "searchCriteria[filterGroups][0][filters][0][field]" => "quote_id",
197
+ "searchCriteria[filterGroups][0][filters][0][value]" => quote_id,
198
+ "searchCriteria[filterGroups][0][filters][0][conditionType]" => "eq" }
199
+ orders = @client.admin_get("/orders?#{URI.encode_www_form(params)}")["items"] || []
200
+ placed = orders.find { |o| PLACED_ORDER_STATES.include?(o["state"]) }
201
+ placed && Mapper.order(placed, checkout_id: checkout_id)
202
+ end
203
+
170
204
  # Merges the guest-cart `items` resource (sku/name/qty/price) with
171
205
  # the `totals` resource (row_total/tax_amount/quote_currency_code)
172
206
  # by `item_id` — see Mapper.cart's comment on why Magento needs this
@@ -1,7 +1,7 @@
1
1
  module Portage
2
2
  module Ucp
3
3
  module Magento
4
- VERSION = "0.2.0".freeze
4
+ VERSION = "0.2.1".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portage-ucp-magento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-05 00:00:00.000000000 Z
11
+ date: 2026-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: portage-ucp
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '0.13'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: '0.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement