From 143ffe4da13d462bab72d8d9d05c5272fd64b8e1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 31 Jan 2012 08:47:33 +0100 Subject: [PATCH] paypal: Do no guess the state as this can cuase validation errors States are not common to use for addresses in Germany, a customer was putting 'DE' into the state, this is the abbreviation for Delaware. When trying to save the Address record the validation failed as the country of the address and the country of the state do not match at all. Fix it by always using the text form for addresses returned by PayPal. Make sure that the state is never blank. --- app/controllers/spree/checkout_controller_decorator.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/spree/checkout_controller_decorator.rb b/app/controllers/spree/checkout_controller_decorator.rb index 85b8048..112b6d3 100644 --- a/app/controllers/spree/checkout_controller_decorator.rb +++ b/app/controllers/spree/checkout_controller_decorator.rb @@ -88,15 +88,11 @@ module Spree # phone is currently blanked in AM's PPX response lib :phone => @ppx_details.params["phone"] || "(not given)" - state = Spree::State.find_by_abbr(ship_address["state"].upcase) if ship_address["state"].present? - if state - order_ship_address.state = state - else - order_ship_address.state_name = ship_address["state"] - end + # Do not guess the state as it might be a state from the wrong country + order_ship_address.state_name = ship_address["state"] # Paypal requires us to have a state for US and on some states it is empty - if order_ship_address.state_name.nil? && order_ship_address.state.nil? + if order_ship_address.state_name.nil? || order_ship_address.state_name.empty? order_ship_address.state_name = "N/A" end