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.

Read addresses through the renamed country and state columns

Damian Legawiecfa2d48630320
diff --git a/spree/providers/stripe/app/models/spree_stripe/gateway/payment_sessions.rb b/spree/providers/stripe/app/models/spree_stripe/gateway/payment_sessions.rb
index 033808a87c..1d8252ff7b 100644
--- a/spree/providers/stripe/app/models/spree_stripe/gateway/payment_sessions.rb
+++ b/spree/providers/stripe/app/models/spree_stripe/gateway/payment_sessions.rb
@@ -234,11 +234,11 @@ module SpreeStripe
{
address: {
city: ship_address.city,
- country: ship_address.country_iso,
+ country: ship_address.country_code,
line1: ship_address.address1,
line2: ship_address.address2,
postal_code: ship_address.zipcode,
- state: ship_address.state_abbr
+ state: ship_address.state_code
},
name: ship_address.full_name
}
@@ -276,7 +276,7 @@ module SpreeStripe
# Countries are reference data now, not records — addresses name one by
# ISO code rather than holding a foreign key.
- owner.bill_address ||= Spree::Address.new(country_iso: country.iso, customer: owner.customer)
+ owner.bill_address ||= Spree::Address.new(country_code: country.iso, customer: owner.customer)
owner.bill_address.quick_checkout = true
# Google Pay sometimes omits the name entirely.
diff --git a/spree/providers/stripe/app/presenters/spree_stripe/customer_presenter.rb b/spree/providers/stripe/app/presenters/spree_stripe/customer_presenter.rb
index 2032ca0ec1..5a47b171d5 100644
--- a/spree/providers/stripe/app/presenters/spree_stripe/customer_presenter.rb
+++ b/spree/providers/stripe/app/presenters/spree_stripe/customer_presenter.rb
@@ -28,8 +28,8 @@ module SpreeStripe
line1: address.address1,
line2: address.address2,
postal_code: address.zipcode,
- country: address.country_iso,
- state: address.state_abbr.presence || address.state_name_text
+ country: address.country_code,
+ state: address.state_code.presence || address.state_name_text
}
end
end
diff --git a/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
index 2895a83d26..852df8acd3 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
@@ -293,7 +293,7 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
order.reload
expect(order.bill_address).to be_present
- expect(order.bill_address.country_iso).to eq(default_country.iso)
+ expect(order.bill_address.country_code).to eq(default_country.iso)
end
end
diff --git a/spree/providers/stripe/spec/presenters/spree_stripe/customer_presenter_spec.rb b/spree/providers/stripe/spec/presenters/spree_stripe/customer_presenter_spec.rb
new file mode 100644
index 0000000000..dd40b3c48c
--- /dev/null
+++ b/spree/providers/stripe/spec/presenters/spree_stripe/customer_presenter_spec.rb
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+RSpec.describe SpreeStripe::CustomerPresenter do
+ subject(:payload) { described_class.new(name: name, email: email, address: address).call }
+
+ let(:name) { 'Jane Moe' }
+ let(:email) { '[email protected]' }
+ let(:address) do
+ create(
+ :address,
+ address1: '100 California Street',
+ address2: 'Apt 1',
+ city: 'San Francisco',
+ zipcode: '94111',
+ country: Spree::Country.by_iso('US'),
+ state: Spree::Country.by_iso('US').states.find { |state| state.abbr == 'CA' }
+ )
+ end
+
+ it 'sends the name and email' do
+ expect(payload).to include(name: name, email: email)
+ end
+
+ # Stripe expects ISO codes here, matching the intent's shipping payload —
+ # full country and subdivision names degrade its location resolution.
+ it 'sends the address as ISO codes' do
+ expect(payload[:address]).to include(
+ city: 'San Francisco',
+ line1: '100 California Street',
+ line2: 'Apt 1',
+ postal_code: '94111',
+ country: 'US',
+ state: 'CA'
+ )
+ end
+
+ context 'when the address has no subdivision code' do
+ let(:address) do
+ build(:address, country: Spree::Country.by_iso('GB'), state: nil, state_name: 'Greater London')
+ end
+
+ it 'falls back to the free-text state name' do
+ expect(payload[:address][:state]).to eq('Greater London')
+ end
+ end
+
+ context 'without an address' do
+ let(:address) { nil }
+
+ it 'omits the address entirely' do
+ expect(payload).not_to have_key(:address)
+ end
+ end
+
+ context 'without a name or email' do
+ let(:name) { nil }
+ let(:email) { nil }
+
+ it 'omits them rather than sending blanks' do
+ expect(payload.keys).not_to include(:name, :email)
+ end
+ end
+end