Skip to content

Commit

Permalink
Fix for C2 country code for China
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Tapia authored and tvdeyen committed Dec 19, 2024
1 parent 5a0a8da commit a8f02bd
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions app/models/solidus_paypal_commerce_platform/paypal_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ def add_email_to_order(recipient)
@order.update(email: recipient[:email_address])
end

def find_country(state_name, country_code)
country = ::Spree::Country.find_by(iso: country_code)
return country if country.present?

state = ::Spree::State.find_by("lower(name) LIKE '%#{state_name.downcase}%'")
state.country
end

def find_state(state_name, country)
if state = country.states.find_by(abbr: state_name) || country.states.find_by(name: state_name)
state
else
SolidusPaypalCommercePlatform.config.state_guesser_class.new(state_name, country).guess
end
return nil if country.blank?

state = country.states.find_by(abbr: state_name) ||
country.states.find_by(name: state_name)
return state if state.present?

state = SolidusPaypalCommercePlatform.config.state_guesser_class.new(
state_name,
country
)
state.guess
end

def format_simulated_address(paypal_address)
Expand All @@ -60,11 +74,13 @@ def format_simulated_address(paypal_address)
end

def address_attributes(address, recipient)
country = ::Spree::Country.find_by(iso: address[:country_code])
state = find_state(
address[:admin_area_1] || address[:admin_area_2] || address[:state],
country,
)
state_name = address[:admin_area_1] ||
address[:admin_area_2] ||
address[:state]
country_code = address[:country_code]

country = find_country(state_name, country_code)
state = find_state(state_name, country)

attributes = {
address1: address[:address_line_1],
Expand Down

0 comments on commit a8f02bd

Please sign in to comment.