Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Let merchants connect EasyPost test keys

Damian Legawiecb8d0d8b0b24a
diff --git a/docs/plans/6.0-delivery-rate-provider.md b/docs/plans/6.0-delivery-rate-provider.md
index 38776d7ada..a6361ab829 100644
--- a/docs/plans/6.0-delivery-rate-provider.md
+++ b/docs/plans/6.0-delivery-rate-provider.md
@@ -493,7 +493,7 @@ The Store API already speaks this vocabulary: `Spree::Api::V3::DeliveryRateSeria
### Phase 5 — reference external provider ✅ shipped (initial scaffold)
-- **Shipped 2026-08-06:** `spree/providers/easypost` (gem `spree_easypost`, module `SpreeEasyPost` — one Zeitwerk inflection) with `SpreeEasyPost::Integration` (password-preference API key, `can_connect?` via a cheap authenticated read) and `SpreeEasyPost::DeliveryRateProvider` on the official `easypost` gem: per-method carrier/service mapping via method metadata, shared shipment call through `Spree::Current.provider_cache` (several methods = one API round-trip, covered by spec), weight converted to ounces from the store unit system, enriched estimates (carrier/service/date/rate ids). Specs stub the client — no network. The how-to guide shipped with Phase 2. Since completed: `SpreeEasyPost::FulfillmentProvider` (label purchase on ship with a stale-quote re-quote that buys only the exact sold carrier/service, refund on cancel, label via `documents` — never raises into the transition) and CI wiring; VCR-backed API-contract specs mirror spree_stripe. The gem stays out of the `spree` meta-gem (optional install).
+- **Shipped 2026-08-06:** `spree/providers/easypost` (gem `spree_easypost`, module `SpreeEasyPost` — one Zeitwerk inflection) with `SpreeEasyPost::Integration` (password-preference API key, `can_connect?` via an address create — the one authenticated call EasyPost allows in both test and production modes; account-management endpoints reject test keys outright) and `SpreeEasyPost::DeliveryRateProvider` on the official `easypost` gem: per-method carrier/service mapping via method metadata, shared shipment call through `Spree::Current.provider_cache` (several methods = one API round-trip, covered by spec), weight converted to ounces from the store unit system, enriched estimates (carrier/service/date/rate ids). Specs stub the client — no network. The how-to guide shipped with Phase 2. Since completed: `SpreeEasyPost::FulfillmentProvider` (label purchase on ship with a stale-quote re-quote that buys only the exact sold carrier/service, refund on cancel, label via `documents` — never raises into the transition) and CI wiring; VCR-backed API-contract specs mirror spree_stripe. The gem stays out of the `spree` meta-gem (optional install).
## Constraints on Current Work
diff --git a/spree/providers/easypost/Gemfile.lock b/spree/providers/easypost/Gemfile.lock
index bb05f5dfeb..fb5852fdea 100644
--- a/spree/providers/easypost/Gemfile.lock
+++ b/spree/providers/easypost/Gemfile.lock
@@ -447,7 +447,7 @@ GEM
psych (>= 4.0.0)
tsort
regexp_parser (2.12.0)
- reline (0.6.3)
+ reline (0.7.0)
io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
@@ -547,7 +547,7 @@ GEM
yard (~> 0.9, >= 0.9.24)
yard-activesupport-concern (~> 0.0)
yard-solargraph (~> 0.1)
- sorbet-runtime (0.6.13409)
+ sorbet-runtime (0.6.13412)
sord (7.1.0)
commander (~> 5.0)
parlour (~> 9.1)
@@ -820,7 +820,7 @@ CHECKSUMS
rbs (4.1.2) sha256=050eb1d8b508f1233bed929c0f2c7052302f7adf295230d9cb314e9024078f48
rdoc (7.2.0) sha256=8650f76cd4009c3b54955eb5d7e3a075c60a57276766ebf36f9085e8c9f23192
regexp_parser (2.12.0) sha256=35a916a1d63190ab5c9009457136ae5f3c0c7512d60291d0d1378ba18ce08ebb
- reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
+ reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d
request_store (1.7.0) sha256=e1b75d5346a315f452242a68c937ef8e48b215b9453a77a6c0acdca2934c88cb
reverse_markdown (3.0.2) sha256=818ebb92ce39dbb1a291690dd1ec9a6d62530d4725296b17e9c8f668f9a5b8af
rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142
@@ -848,7 +848,7 @@ CHECKSUMS
simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
solargraph (0.60.3) sha256=3f2252faa27cc628a16a4aac1ba0bc0b06b0250194a8713da0ff42adb20bb19d
- sorbet-runtime (0.6.13409) sha256=6734a00932493f429b36cfa10904c08f2da34f5d84c860d01a6ef5997ceea5d2
+ sorbet-runtime (0.6.13412) sha256=587ef79b31364b88efd3e809e1b30c72935f1793c735053094a40ff9fa70c91f
sord (7.1.0) sha256=e02fd59294da520e50cea80a07fb9bc93db709c552d055871379ae8d8e87601f
spree (6.0.0.alpha)
spree_api (6.0.0.alpha)
diff --git a/spree/providers/easypost/app/models/spree_easypost/integration.rb b/spree/providers/easypost/app/models/spree_easypost/integration.rb
index adc6ebcfb6..10ee412e97 100644
--- a/spree/providers/easypost/app/models/spree_easypost/integration.rb
+++ b/spree/providers/easypost/app/models/spree_easypost/integration.rb
@@ -4,6 +4,16 @@ module SpreeEasyPost
class Integration < Spree::Integration
preference :api_key, :password
+ # EasyPost's own documentation example address — used only to prove the
+ # key authenticates.
+ VERIFICATION_ADDRESS = {
+ street1: '417 Montgomery Street',
+ city: 'San Francisco',
+ state: 'CA',
+ zip: '94104',
+ country: 'US'
+ }.freeze
+
def self.integration_group
'shipping'
end
@@ -22,12 +32,17 @@ module SpreeEasyPost
'Live multi-carrier delivery rates at checkout through your EasyPost account.'
end
- # A cheap authenticated read: fails with 401 on a bad key without
- # creating anything on the account.
+ # Verifies the key by creating an address — the one authenticated call
+ # that works in both modes. Account-management endpoints
+ # (`carrier_account.all`, `api_key.all`) are production-only and reject a
+ # valid test key with "This resource requires a production API Key",
+ # which would block merchants from connecting a test key at all.
+ # Addresses are inert: no shipment, no charge, nothing to clean up.
+ #
# Rescues broadly, not just SDK errors — a DNS failure or timeout must
# surface as a clean activation error, never a 500.
def can_connect?
- client.carrier_account.all
+ client.address.create(VERIFICATION_ADDRESS)
true
rescue StandardError => e
self.connection_error_message = e.message
diff --git a/spree/providers/easypost/bin/smoke b/spree/providers/easypost/bin/smoke
index c69809a352..fef2d24781 100755
--- a/spree/providers/easypost/bin/smoke
+++ b/spree/providers/easypost/bin/smoke
@@ -9,8 +9,8 @@ require 'easypost'
client = EasyPost::Client.new(api_key: ENV.fetch('EASYPOST_TEST_API_KEY'))
-puts '-> carrier_account.all (the can_connect? check)'
-client.carrier_account.all
+puts '-> address.create (the can_connect? check — works with test and production keys)'
+client.address.create(street1: '417 Montgomery Street', city: 'San Francisco', state: 'CA', zip: '94104', country: 'US')
puts ' ok'
puts '-> shipment.create (the estimate call)'
diff --git a/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb b/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
index 36fa2effa2..f05c6abe3f 100644
--- a/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
+++ b/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
@@ -24,17 +24,26 @@ RSpec.describe SpreeEasyPost::Integration do
end
describe '#can_connect?' do
- let(:carrier_account_service) { double(all: []) }
- let(:client) { instance_double(EasyPost::Client, carrier_account: carrier_account_service) }
+ let(:address_service) { double(create: double(id: 'adr_1')) }
+ let(:client) { instance_double(EasyPost::Client, address: address_service) }
before { allow(integration).to receive(:client).and_return(client) }
- it 'is true when an authenticated read succeeds' do
+ it 'is true when the authenticated call succeeds' do
expect(integration.can_connect?).to be(true)
end
+ # Account-management endpoints reject test keys outright; the check must
+ # use a call both modes allow so a merchant can connect a test key.
+ it 'verifies through an address create, not a production-only endpoint' do
+ integration.can_connect?
+
+ expect(address_service).to have_received(:create).with(described_class::VERIFICATION_ADDRESS)
+ expect(client).not_to respond_to(:carrier_account)
+ end
+
it 'captures the vendor message on failure' do
- allow(carrier_account_service).to receive(:all).
+ allow(address_service).to receive(:create).
and_raise(EasyPost::Errors::EasyPostError.new('unauthorized'))
expect(integration.can_connect?).to be(false)
@@ -51,13 +60,13 @@ RSpec.describe SpreeEasyPost::Integration do
end
it 'connects with a valid key' do
- VCR.use_cassette('carrier_accounts') do
+ VCR.use_cassette('verify_api_key') do
expect(integration.can_connect?).to be(true)
end
end
it 'captures the vendor message on a rejected key' do
- VCR.use_cassette('carrier_accounts_unauthorized') do
+ VCR.use_cassette('verify_api_key_unauthorized') do
expect(integration.can_connect?).to be(false)
expect(integration.connection_error_message).to be_present
end
diff --git a/spree/providers/easypost/spec/vcr/carrier_accounts.yml b/spree/providers/easypost/spec/vcr/carrier_accounts.yml
deleted file mode 100644
index ec518f0b97..0000000000
--- a/spree/providers/easypost/spec/vcr/carrier_accounts.yml
+++ /dev/null
@@ -1,23 +0,0 @@
----
-http_interactions:
-- request:
- method: get
- uri: https://api.easypost.com/v2/carrier_accounts
- body:
- encoding: US-ASCII
- string: ''
- headers:
- Authorization:
- - "<FILTERED>"
- response:
- status:
- code: 200
- message: OK
- headers:
- Content-Type:
- - application/json; charset=utf-8
- body:
- encoding: UTF-8
- string: '[{"id":"ca_recorded1","object":"CarrierAccount","type":"UspsAccount","readable":"USPS","created_at":"2026-08-06T12:00:00Z","updated_at":"2026-08-06T12:00:00Z"}]'
- recorded_at: Thu, 06 Aug 2026 20:00:00 GMT
-recorded_with: VCR 6.3.1
diff --git a/spree/providers/easypost/spec/vcr/verify_api_key.yml b/spree/providers/easypost/spec/vcr/verify_api_key.yml
new file mode 100644
index 0000000000..a4e3f563a5
--- /dev/null
+++ b/spree/providers/easypost/spec/vcr/verify_api_key.yml
@@ -0,0 +1,25 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://api.easypost.com/v2/addresses
+ body:
+ encoding: UTF-8
+ string: '{"address":{"street1":"417 Montgomery Street","city":"San Francisco","state":"CA","zip":"94104","country":"US"}}'
+ headers:
+ Authorization:
+ - "<FILTERED>"
+ Content-Type:
+ - application/json
+ response:
+ status:
+ code: 201
+ message: Created
+ headers:
+ Content-Type:
+ - application/json; charset=utf-8
+ body:
+ encoding: UTF-8
+ string: '{"id":"adr_recorded1","object":"Address","mode":"test","street1":"417 Montgomery Street","city":"San Francisco","state":"CA","zip":"94104","country":"US","created_at":"2026-08-07T09:00:00Z","updated_at":"2026-08-07T09:00:00Z"}'
+ recorded_at: Fri, 07 Aug 2026 09:00:00 GMT
+recorded_with: VCR 6.3.1
diff --git a/spree/providers/easypost/spec/vcr/carrier_accounts_unauthorized.yml b/spree/providers/easypost/spec/vcr/verify_api_key_unauthorized.yml
similarity index 55%
rename from spree/providers/easypost/spec/vcr/carrier_accounts_unauthorized.yml
rename to spree/providers/easypost/spec/vcr/verify_api_key_unauthorized.yml
index 8885974384..fa1fd4c01d 100644
--- a/spree/providers/easypost/spec/vcr/carrier_accounts_unauthorized.yml
+++ b/spree/providers/easypost/spec/vcr/verify_api_key_unauthorized.yml
@@ -1,14 +1,16 @@
---
http_interactions:
- request:
- method: get
- uri: https://api.easypost.com/v2/carrier_accounts
+ method: post
+ uri: https://api.easypost.com/v2/addresses
body:
- encoding: US-ASCII
- string: ''
+ encoding: UTF-8
+ string: '{"address":{"street1":"417 Montgomery Street","city":"San Francisco","state":"CA","zip":"94104","country":"US"}}'
headers:
Authorization:
- "<FILTERED>"
+ Content-Type:
+ - application/json
response:
status:
code: 401
@@ -19,5 +21,5 @@ http_interactions:
body:
encoding: UTF-8
string: '{"error":{"code":"UNAUTHORIZED","message":"Invalid API Key.","errors":[]}}'
- recorded_at: Thu, 06 Aug 2026 20:00:00 GMT
+ recorded_at: Fri, 07 Aug 2026 09:00:00 GMT
recorded_with: VCR 6.3.1