portage-ucp-woocommerce 0.1.3 → 0.2.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 +27 -0
- data/README.md +25 -8
- data/exe/portage-ucp-woocommerce +10 -3
- data/lib/portage/ucp/woocommerce/adapter.rb +24 -7
- data/lib/portage/ucp/woocommerce/mapper.rb +12 -2
- data/lib/portage/ucp/woocommerce/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 267329024b55bc6e5ff322972afa261a42de7461122cf797f180107bf8ea5b47
|
|
4
|
+
data.tar.gz: 188c4863958b7764041ecc5b071ab56cfef7ac4e852fd662458994e6d106fbcb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0cb179e1680c0f9b20ed6408829a98ff6d64587ec1cd364a8a151f54eb4416290116311102415968d76aad1f9adb18ad961a86d3941548e66c0b2d808ebe1fb
|
|
7
|
+
data.tar.gz: 1f0e0f6b090ae7d370f9a2c282306ebeac965654cb381f741a7d9801136681a92c80f8935cfed8f20b26b2b122719657ecee8c977e1e81a6920680f0ea32dbbd
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,33 @@ All notable changes to this project are documented here. Format loosely follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/); this project is
|
|
5
5
|
pre-1.0, so APIs may still shift between minor versions.
|
|
6
6
|
|
|
7
|
+
## [0.2.0] - 2026-09-22
|
|
8
|
+
|
|
9
|
+
- `Mapper.checkout` builds a `resume-checkout` link at `<site_url>/checkout/`
|
|
10
|
+
for any non-completed checkout, instead of always emitting `links: []`.
|
|
11
|
+
Without it, `Buy#checkout_url_of` returned `nil` and `Buy#hand_off` bailed
|
|
12
|
+
out before it ran — confirmed live: the `no_payment_token` dead end
|
|
13
|
+
reported `checkout_url: null` and `handoff: null`. `/checkout/` is
|
|
14
|
+
WooCommerce's default slug, not guaranteed; a store that's renamed its
|
|
15
|
+
checkout page gets a dead link. **Breaking for anyone calling `Mapper`
|
|
16
|
+
directly**: `Mapper.checkout` now takes a required `site_url:` keyword.
|
|
17
|
+
- `Adapter.new` takes a `billing_address:` keyword (a Store API-shaped
|
|
18
|
+
hash), supplied at construction from `WOOCOMMERCE_BILLING_ADDRESS` (JSON)
|
|
19
|
+
by the `exe/portage-ucp-woocommerce` script. The Store API's `/checkout`
|
|
20
|
+
endpoint 400s without one ("Missing parameter(s): billing_address"),
|
|
21
|
+
confirmed live right after `payment_method` was wired through. UCP's
|
|
22
|
+
`Adapter#complete_checkout` interface has no buyer-address parameter, and
|
|
23
|
+
threading one through every adapter gem is a bigger change than this gem
|
|
24
|
+
alone should make — same one-fixed-value-per-process stopgap as
|
|
25
|
+
`payment_method`, and wrong the moment something needs a different
|
|
26
|
+
address per checkout.
|
|
27
|
+
|
|
28
|
+
## [0.1.4] - 2026-09-17
|
|
29
|
+
|
|
30
|
+
- No behavior change — widens the `portage-ucp` dependency pin to `~> 0.8`
|
|
31
|
+
so this gem can install alongside `portage-ucp` 0.8.0 (the `~> 0.7` pin
|
|
32
|
+
published with 0.1.3 is pessimistic and excludes it).
|
|
33
|
+
|
|
7
34
|
## [0.1.3] - 2026-09-16
|
|
8
35
|
|
|
9
36
|
- No behavior change — 0.1.2 was built and pushed with `gem build` run from
|
data/README.md
CHANGED
|
@@ -18,14 +18,29 @@ Update/replace operations (`update_cart`, `update_checkout`) are full-replacemen
|
|
|
18
18
|
|
|
19
19
|
Unlike Shopify/Wix, there's no `AccessTokenFetcher` — WooCommerce Admin keys are static, generated once in wp-admin (WooCommerce → Settings → Advanced → REST API), with nothing to exchange or expire.
|
|
20
20
|
|
|
21
|
-
## ⚠️
|
|
21
|
+
## ⚠️ Verified against a local install
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Run against a throwaway Docker WooCommerce (WP 7.1.1 + WooCommerce 11.1.1, TLS via a local Caddy reverse proxy — see `docs/plans/woocommerce-local-validation.md` for the full setup and test ladder). What actually held up, and what didn't:
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
25
|
+
**Confirmed working:**
|
|
26
|
+
- Admin REST Basic Auth, `Client#store_request`'s `Cart-Token`/`Nonce` session threading across `create_cart` → `update_cart` → `create_checkout` → `get_checkout`, and `Resolver.detect_platform` all work exactly as coded — against a real store, not just WebMock stubs.
|
|
27
|
+
- `POST /cart/add-item` accepts a variable product's variation id directly as `id` — no separate `variation` param needed, confirmed live.
|
|
28
|
+
- `Mapper.variant`'s `attributes[].option` join produces correct titles (e.g. `"Blue / Yes"`) against a real variable product.
|
|
29
|
+
- Store API money fields map to correct minor units through `Mapper`.
|
|
30
|
+
|
|
31
|
+
**Fixed since this pass:**
|
|
32
|
+
|
|
33
|
+
1. **Hand-off now fires on WooCommerce.** `Mapper.checkout` builds a `resume-checkout` link at `<site_url>/checkout/` (WooCommerce's default slug — a store that's renamed its checkout page gets a dead link) for any non-completed checkout, so `Buy#checkout_url_of`/`#hand_off` have something to work with instead of bailing early on `links: []`.
|
|
34
|
+
2. **`Resolver` now threads `payment_method`/`billing_address` through to the adapter.** Its WooCommerce entry was missing both from its `env:` map, so `complete_checkout` failed with no gateway or address configured even when `WOOCOMMERCE_PAYMENT_METHOD`/`WOOCOMMERCE_BILLING_ADDRESS` were set.
|
|
35
|
+
3. **`portage buy`'s `adapter_flow` no longer hides a live adapter's own error.** It rescued `LoadError` and `StandardError` identically, so a real, actionable failure (e.g. "no payment_method configured on this Adapter") surfaced as the same generic "no automated path" dead end as an adapter that isn't installed at all. A `StandardError` past that point now comes back as its own report, distinguishable by `source`.
|
|
36
|
+
4. **`submit_checkout` now supplies `billing_address`.** `POST /wc/store/v1/checkout` 400s without one; there's no UCP `complete_checkout` parameter for it, so — same stopgap posture as `payment_method` — the adapter takes one fixed `billing_address` hash at construction time via `WOOCOMMERCE_BILLING_ADDRESS` (JSON, Store API field names), not per-checkout. Fine for a single-buyer-per-process, wrong the moment something needs a different address per checkout.
|
|
37
|
+
|
|
38
|
+
**Remaining gaps, still unfixed:**
|
|
39
|
+
|
|
40
|
+
1. **`requires_escalation` is unreachable here.** The Woo adapter only ever records `incomplete`/`completed`/`canceled` — there's no path to that status on this backend at all.
|
|
41
|
+
2. **A dry run does not write to the purchase journal**, contrary to earlier assumption. `PurchaseJournal#record_checkout` only fires from `Dispatcher`'s `complete_checkout` settle point — a dry run only ever reaches `create_checkout`, so `~/.portage/journal.jsonl` is untouched. Confirmed by running two dry runs and finding no journal file created at all.
|
|
42
|
+
|
|
43
|
+
Also worth knowing: WooCommerce's Basic Auth for the Admin API only activates when `is_ssl()` is true (`WC_REST_Authentication#authenticate`) — over plain HTTP it silently falls through to OAuth1 query-param signing instead, which this client doesn't implement. A local HTTP-only install will get a generic `401 woocommerce_rest_cannot_view`, not an auth-scheme error; put TLS in front (even a local self-signed proxy) before debugging keys.
|
|
29
44
|
|
|
30
45
|
## Installation
|
|
31
46
|
|
|
@@ -40,7 +55,7 @@ bundle install
|
|
|
40
55
|
|
|
41
56
|
## Setup
|
|
42
57
|
|
|
43
|
-
You need a site URL, an Admin REST API consumer key/secret pair (wp-admin → WooCommerce → Settings → Advanced → REST API — grant Read/Write), your store's currency (the Admin product resource doesn't return one), and — only if you'll call `complete_checkout` — the WC payment gateway id you want to submit orders through.
|
|
58
|
+
You need a site URL, an Admin REST API consumer key/secret pair (wp-admin → WooCommerce → Settings → Advanced → REST API — grant Read/Write), your store's currency (the Admin product resource doesn't return one), and — only if you'll call `complete_checkout` — the WC payment gateway id you want to submit orders through and a `billing_address` the Store API's `/checkout` endpoint requires.
|
|
44
59
|
|
|
45
60
|
```ruby
|
|
46
61
|
require "portage/ucp/woocommerce"
|
|
@@ -55,7 +70,9 @@ adapter = Portage::Ucp::WooCommerce::Adapter.new(
|
|
|
55
70
|
client: client,
|
|
56
71
|
site_url: "https://your-shop.example.com",
|
|
57
72
|
currency: "USD",
|
|
58
|
-
payment_method: "stripe_cc" # only required for #complete_checkout
|
|
73
|
+
payment_method: "stripe_cc", # only required for #complete_checkout
|
|
74
|
+
billing_address: { "first_name" => "...", "address_1" => "...", "city" => "...",
|
|
75
|
+
"postcode" => "...", "country" => "..." } # only required for #complete_checkout
|
|
59
76
|
)
|
|
60
77
|
```
|
|
61
78
|
|
data/exe/portage-ucp-woocommerce
CHANGED
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
# Sidekiq's `-r` work — see ../examples/portage_ucp.rb for a starting point.
|
|
9
9
|
# Without one, the server still starts but rejects every mutating call.
|
|
10
10
|
#
|
|
11
|
-
# WOOCOMMERCE_PAYMENT_METHOD
|
|
12
|
-
#
|
|
11
|
+
# WOOCOMMERCE_PAYMENT_METHOD and WOOCOMMERCE_BILLING_ADDRESS (a JSON object,
|
|
12
|
+
# Store API field names — e.g. '{"first_name":"...","address_1":"...",
|
|
13
|
+
# "city":"...","postcode":"...","country":"..."}') are both optional — only
|
|
14
|
+
# needed to call #complete_checkout, which requires both a configured
|
|
15
|
+
# gateway id and a billing address the Store API's /checkout endpoint won't
|
|
16
|
+
# accept without.
|
|
13
17
|
|
|
18
|
+
require "json"
|
|
14
19
|
require "portage/ucp"
|
|
15
20
|
require "portage/ucp/woocommerce"
|
|
16
21
|
|
|
@@ -21,11 +26,13 @@ client = Portage::Ucp::WooCommerce::Client.new(
|
|
|
21
26
|
consumer_key: ENV.fetch("WOOCOMMERCE_CONSUMER_KEY"),
|
|
22
27
|
consumer_secret: ENV.fetch("WOOCOMMERCE_CONSUMER_SECRET")
|
|
23
28
|
)
|
|
29
|
+
billing_address = ENV["WOOCOMMERCE_BILLING_ADDRESS"] && JSON.parse(ENV["WOOCOMMERCE_BILLING_ADDRESS"])
|
|
24
30
|
adapter = Portage::Ucp::WooCommerce::Adapter.new(
|
|
25
31
|
client: client,
|
|
26
32
|
site_url: ENV.fetch("WOOCOMMERCE_SITE_URL"),
|
|
27
33
|
currency: ENV.fetch("WOOCOMMERCE_CURRENCY", "USD"),
|
|
28
|
-
payment_method: ENV.fetch("WOOCOMMERCE_PAYMENT_METHOD", nil)
|
|
34
|
+
payment_method: ENV.fetch("WOOCOMMERCE_PAYMENT_METHOD", nil),
|
|
35
|
+
billing_address: billing_address
|
|
29
36
|
)
|
|
30
37
|
|
|
31
38
|
Portage::Ucp::Mcp::Server.build(adapter: adapter).start
|
|
@@ -30,6 +30,19 @@ module Portage
|
|
|
30
30
|
# with a real gateway installed — same "needs confirming against a
|
|
31
31
|
# live store" posture as Portage::Ucp::Shopify::Adapter's own payment
|
|
32
32
|
# step.
|
|
33
|
+
#
|
|
34
|
+
# IMPORTANT CAVEAT #2: the Store API's `/checkout` endpoint also
|
|
35
|
+
# requires `billing_address` (confirmed live: a 400 naming it as
|
|
36
|
+
# missing without one). UCP's `Adapter#complete_checkout` interface
|
|
37
|
+
# has no buyer-address parameter at all, and threading one through
|
|
38
|
+
# every adapter gem is a bigger, cross-cutting change than this gem
|
|
39
|
+
# alone should make unilaterally — so, same posture as
|
|
40
|
+
# `payment_method` above, this is a WooCommerce-specific stopgap:
|
|
41
|
+
# supply one fixed `billing_address` hash at construction time
|
|
42
|
+
# (Store API field names, e.g. `first_name`/`address_1`/`postcode`),
|
|
43
|
+
# not per-checkout. Fine for the single-buyer-per-process shape this
|
|
44
|
+
# adapter already assumes (see `payment_method`'s own doc), wrong for
|
|
45
|
+
# anything that needs a different billing address per checkout.
|
|
33
46
|
class Adapter < Portage::Ucp::Adapter
|
|
34
47
|
# The Store API takes no idempotency key natively, so §9a dedup comes
|
|
35
48
|
# from Support::Idempotency's in-process table.
|
|
@@ -43,13 +56,15 @@ module Portage
|
|
|
43
56
|
# than an empty body, which UCP's reads report as nil.
|
|
44
57
|
include Portage::Ucp::Support::NotFound
|
|
45
58
|
|
|
46
|
-
def initialize(client:, site_url:, currency:, payment_method: nil, payment_data_key: "token"
|
|
59
|
+
def initialize(client:, site_url:, currency:, payment_method: nil, payment_data_key: "token",
|
|
60
|
+
billing_address: nil)
|
|
47
61
|
super()
|
|
48
62
|
@client = client
|
|
49
63
|
@site_url = site_url.chomp("/")
|
|
50
64
|
@currency = currency
|
|
51
65
|
@payment_method = payment_method
|
|
52
66
|
@payment_data_key = payment_data_key
|
|
67
|
+
@billing_address = billing_address
|
|
53
68
|
end
|
|
54
69
|
|
|
55
70
|
def search_catalog(query:, limit:)
|
|
@@ -94,12 +109,12 @@ module Portage
|
|
|
94
109
|
dedup(idempotency_key) do
|
|
95
110
|
node = replace_cart_lines(line_items)
|
|
96
111
|
record_checkout_status(@client.cart_token, "incomplete")
|
|
97
|
-
Mapper.checkout(node, id: @client.cart_token, status: "incomplete")
|
|
112
|
+
Mapper.checkout(node, id: @client.cart_token, status: "incomplete", site_url: @site_url)
|
|
98
113
|
end
|
|
99
114
|
end
|
|
100
115
|
|
|
101
116
|
def get_checkout(checkout_id:)
|
|
102
|
-
Mapper.checkout(fetch_cart_node, id: checkout_id, status: checkout_status(checkout_id))
|
|
117
|
+
Mapper.checkout(fetch_cart_node, id: checkout_id, status: checkout_status(checkout_id), site_url: @site_url)
|
|
103
118
|
end
|
|
104
119
|
|
|
105
120
|
# Full replacement, same rationale as #update_cart.
|
|
@@ -107,7 +122,7 @@ module Portage
|
|
|
107
122
|
dedup(idempotency_key) do
|
|
108
123
|
node = replace_cart_lines(line_items)
|
|
109
124
|
record_checkout_status(checkout_id, "incomplete")
|
|
110
|
-
Mapper.checkout(node, id: checkout_id, status: "incomplete")
|
|
125
|
+
Mapper.checkout(node, id: checkout_id, status: "incomplete", site_url: @site_url)
|
|
111
126
|
end
|
|
112
127
|
end
|
|
113
128
|
|
|
@@ -121,7 +136,7 @@ module Portage
|
|
|
121
136
|
def cancel_checkout(checkout_id:, idempotency_key:)
|
|
122
137
|
dedup(idempotency_key) do
|
|
123
138
|
record_checkout_status(checkout_id, "canceled")
|
|
124
|
-
Mapper.checkout(fetch_cart_node, id: checkout_id, status: "canceled")
|
|
139
|
+
Mapper.checkout(fetch_cart_node, id: checkout_id, status: "canceled", site_url: @site_url)
|
|
125
140
|
end
|
|
126
141
|
end
|
|
127
142
|
|
|
@@ -166,14 +181,16 @@ module Portage
|
|
|
166
181
|
# than a confirmed gateway-specific shape.
|
|
167
182
|
def submit_checkout(checkout_id, payment_token)
|
|
168
183
|
raise Portage::Ucp::WooCommerce::Error, "no payment_method configured on this Adapter" unless @payment_method
|
|
184
|
+
raise Portage::Ucp::WooCommerce::Error, "no billing_address configured on this Adapter" unless @billing_address
|
|
169
185
|
|
|
170
186
|
data = @client.store_post("/checkout", {
|
|
171
187
|
payment_method: @payment_method,
|
|
172
|
-
payment_data: [{ key: @payment_data_key, value: payment_token }]
|
|
188
|
+
payment_data: [{ key: @payment_data_key, value: payment_token }],
|
|
189
|
+
billing_address: @billing_address
|
|
173
190
|
})
|
|
174
191
|
record_checkout_status(checkout_id, "completed")
|
|
175
192
|
order = build_order_confirmation(data, checkout_id)
|
|
176
|
-
Mapper.checkout(data, id: checkout_id, status: "completed", order: order)
|
|
193
|
+
Mapper.checkout(data, id: checkout_id, status: "completed", site_url: @site_url, order: order)
|
|
177
194
|
end
|
|
178
195
|
|
|
179
196
|
# Same order-received URL pattern as Mapper.order's `permalink_url` —
|
|
@@ -96,7 +96,7 @@ module Portage
|
|
|
96
96
|
# cart *is* the checkout, same as Shopify's Cart-as-Checkout, so the
|
|
97
97
|
# adapter tracks status itself and passes it in here, same rationale
|
|
98
98
|
# as `id:` above.
|
|
99
|
-
def checkout(node, id:, status:, order: nil)
|
|
99
|
+
def checkout(node, id:, status:, site_url:, order: nil)
|
|
100
100
|
currency = node.dig("totals", "currency_code")
|
|
101
101
|
Portage::Ucp::Checkout.new(
|
|
102
102
|
id: id,
|
|
@@ -104,11 +104,21 @@ module Portage
|
|
|
104
104
|
line_items: (node["items"] || []).map { |n| cart_line_item(n, currency) },
|
|
105
105
|
currency: currency,
|
|
106
106
|
totals: totals(node["totals"] || {}),
|
|
107
|
-
links:
|
|
107
|
+
links: checkout_links(status: status, site_url: site_url),
|
|
108
108
|
order: order
|
|
109
109
|
)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
# No Store API field returns the site's actual checkout page URL —
|
|
113
|
+
# `/checkout/` is WooCommerce's *default* slug, not guaranteed (a
|
|
114
|
+
# store can rename it). Good-enough-not-exhaustive, same posture as
|
|
115
|
+
# this adapter's other documented caveats (see README).
|
|
116
|
+
def checkout_links(status:, site_url:)
|
|
117
|
+
return [] if status == "completed"
|
|
118
|
+
|
|
119
|
+
[Portage::Ucp::Link.new(type: "resume-checkout", url: "#{site_url}/checkout/")]
|
|
120
|
+
end
|
|
121
|
+
|
|
112
122
|
def cart_line_item(node, _currency)
|
|
113
123
|
unit_price = minor_units_from_subunits(node.dig("prices", "price"), node.dig("prices", "currency_minor_unit"))
|
|
114
124
|
line_total = unit_price * node["quantity"]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: portage-ucp-woocommerce
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.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-09-
|
|
11
|
+
date: 2026-09-22 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.
|
|
19
|
+
version: '0.8'
|
|
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.
|
|
26
|
+
version: '0.8'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rspec
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|