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.

Record the carrier's real answers when a purchase fails

Damian Legawiecb8f95edc63f3
diff --git a/spree/providers/easypost/spec/models/spree_easypost/fulfillment_provider_spec.rb b/spree/providers/easypost/spec/models/spree_easypost/fulfillment_provider_spec.rb
index 5e50093379..ed89312ddc 100644
--- a/spree/providers/easypost/spec/models/spree_easypost/fulfillment_provider_spec.rb
+++ b/spree/providers/easypost/spec/models/spree_easypost/fulfillment_provider_spec.rb
@@ -332,5 +332,34 @@ RSpec.describe SpreeEasyPost::FulfillmentProvider do
expect(provider.refund_label(shipping_label)).to be_present
end
end
+
+ # What a merchant is told when a purchase fails is as much the contract as
+ # what they get when it succeeds, and these two are the failures they will
+ # actually hit. Recorded against the live API because the field-level
+ # detail these read lives in the response body: a stubbed exception would
+ # only prove the code handles a shape invented here.
+ context 'when the warehouse cannot ship' do
+ it 'names the detail a carrier requires but the location lacks' do
+ fulfillment.stock_location.update_columns(phone: nil)
+ store.update_columns(contact_phone: nil)
+
+ VCR.use_cassette('end_shipper_missing_phone') do
+ expect { provider.purchase_label(fulfillment) }.
+ to raise_error(Spree::Core::LabelPurchaseRefused, /phone/i)
+ end
+ end
+
+ it 'says the address could not be verified' do
+ fulfillment.stock_location.update_columns(
+ address1: '9 Nowhere Road', city: 'Reno', state_code: 'NV', zipcode: '89501',
+ country_code: 'US', phone: '7755551234'
+ )
+
+ VCR.use_cassette('end_shipper_bad_address') do
+ expect { provider.purchase_label(fulfillment) }.
+ to raise_error(Spree::Core::LabelPurchaseRefused, /address/i)
+ end
+ end
+ end
end
end
diff --git a/spree/providers/easypost/spec/vcr/end_shipper_bad_address.yml b/spree/providers/easypost/spec/vcr/end_shipper_bad_address.yml
new file mode 100644
index 0000000000..2e6550a14d
--- /dev/null
+++ b/spree/providers/easypost/spec/vcr/end_shipper_bad_address.yml
@@ -0,0 +1,74 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://api.easypost.com/v2/end_shippers
+ body:
+ encoding: UTF-8
+ string: '{"address":{"name":"Risa Macejkovic","street1":"9 Nowhere Road","city":"Reno","state":"NV","zip":"89501","country":"US","phone":"7755551234","email":"[email protected]"}}'
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - EasyPost/v2 RubyClient/7.7.0 Ruby/4.0.1-p0 OS/Darwin OSVersion/23 OSArch/arm64
+ Host:
+ - api.easypost.com
+ Content-Type:
+ - application/json
+ Authorization:
+ - "<FILTERED>"
+ response:
+ status:
+ code: 422
+ message: Unprocessable Entity
+ headers:
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Xss-Protection:
+ - 1; mode=block
+ X-Content-Type-Options:
+ - nosniff
+ X-Download-Options:
+ - noopen
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ Referrer-Policy:
+ - strict-origin-when-cross-origin
+ Easypost-Api-Version:
+ - '2015-01-01'
+ Vary:
+ - EasyPost-Api-Version
+ X-Ep-Request-Uuid:
+ - a3e55f4b6a9ac787ff1b8e8e0109dce2
+ Cache-Control:
+ - private, no-cache, no-store
+ Pragma:
+ - no-cache
+ Expires:
+ - '0'
+ Content-Type:
+ - application/json; charset=utf-8
+ X-Runtime:
+ - '0.057235'
+ Transfer-Encoding:
+ - chunked
+ X-Node:
+ - web110azw
+ X-Version-Label:
+ - easypost-202609032312-c09450d2bb-main
+ X-Backend:
+ - easypost
+ X-Proxied:
+ - extlb1azw dcaa0f86f7
+ - intlb2azw f881cede8e
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains; preload
+ body:
+ encoding: ASCII-8BIT
+ string: '{"error":{"code":"ADDRESS.VERIFY.FAILURE","message":"Unable to verify
+ address.","errors":[{"code":"E.ADDRESS.NOT_FOUND","field":"address","message":"Address
+ not found","suggestion":null}]}}'
+ recorded_at: Fri, 04 Sep 2026 13:28:40 GMT
+recorded_with: VCR 6.4.0
diff --git a/spree/providers/easypost/spec/vcr/end_shipper_missing_phone.yml b/spree/providers/easypost/spec/vcr/end_shipper_missing_phone.yml
new file mode 100644
index 0000000000..94a1eb312e
--- /dev/null
+++ b/spree/providers/easypost/spec/vcr/end_shipper_missing_phone.yml
@@ -0,0 +1,74 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://api.easypost.com/v2/end_shippers
+ body:
+ encoding: UTF-8
+ string: '{"address":{"name":"Kris Labadie","street1":"1600 Pennsylvania Ave
+ NW","city":"Washington","state":"AL","zip":"20500","country":"US","email":"[email protected]"}}'
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - EasyPost/v2 RubyClient/7.7.0 Ruby/4.0.1-p0 OS/Darwin OSVersion/23 OSArch/arm64
+ Host:
+ - api.easypost.com
+ Content-Type:
+ - application/json
+ Authorization:
+ - "<FILTERED>"
+ response:
+ status:
+ code: 422
+ message: Unprocessable Entity
+ headers:
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Xss-Protection:
+ - 1; mode=block
+ X-Content-Type-Options:
+ - nosniff
+ X-Download-Options:
+ - noopen
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ Referrer-Policy:
+ - strict-origin-when-cross-origin
+ Easypost-Api-Version:
+ - '2015-01-01'
+ Vary:
+ - EasyPost-Api-Version
+ X-Ep-Request-Uuid:
+ - 06cfc6286a9ac787ff1b8e8c010e5c1b
+ Cache-Control:
+ - private, no-cache, no-store
+ Pragma:
+ - no-cache
+ Expires:
+ - '0'
+ Content-Type:
+ - application/json; charset=utf-8
+ X-Runtime:
+ - '0.024800'
+ Transfer-Encoding:
+ - chunked
+ X-Node:
+ - web105azw
+ X-Version-Label:
+ - easypost-202609032312-c09450d2bb-main
+ X-Backend:
+ - easypost
+ X-Proxied:
+ - extlb2azw dcaa0f86f7
+ - intlb4azw f881cede8e
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains; preload
+ body:
+ encoding: ASCII-8BIT
+ string: '{"error":{"code":"PARAMETER.REQUIRED","message":"Missing required parameter.","errors":[{"field":"end_shipper.address.phone","message":"is
+ required but missing"}]}}'
+ recorded_at: Fri, 04 Sep 2026 13:28:39 GMT
+recorded_with: VCR 6.4.0