diff --git a/lib/offsite_payments/integrations/realex_offsite.rb b/lib/offsite_payments/integrations/realex_offsite.rb index b09b743e3..07c231fef 100644 --- a/lib/offsite_payments/integrations/realex_offsite.rb +++ b/lib/offsite_payments/integrations/realex_offsite.rb @@ -93,7 +93,11 @@ def extract_digits(value) end def extract_avs_code(params={}) - [extract_digits(params[:zip]), extract_digits(params[:address1])].join('|') + code = [params[:zip], params[:address1]] + if 'GB' == params[:country] + code = code.collect{|p| extract_digits(p) } + end + code.reject{|p| p.empty? }.join('|') end end diff --git a/test/unit/integrations/realex_offsite/realex_offsite_helper_test.rb b/test/unit/integrations/realex_offsite/realex_offsite_helper_test.rb index ff5e3d1ee..a21f39551 100644 --- a/test/unit/integrations/realex_offsite/realex_offsite_helper_test.rb +++ b/test/unit/integrations/realex_offsite/realex_offsite_helper_test.rb @@ -47,10 +47,22 @@ def test_address_mapping :city => 'Leeds', :state => 'Yorkshire', :zip => 'LS2 7EE', - :country => 'CA' + :country => 'GB' assert_field 'BILLING_CODE', '27|1' - assert_field 'BILLING_CO', 'CA' + assert_field 'BILLING_CO', 'GB' + end + + def test_address_mapping_us + @helper.billing_address :address1 => '123 My Street', + :address2 => 'Apt. 1', + :city => 'Anytown', + :state => 'Anystate', + :zip => '54321', + :country => 'US' + + assert_field 'BILLING_CODE', '54321|123 My Street' + assert_field 'BILLING_CO', 'US' end def test_shipping_address @@ -66,6 +78,19 @@ def test_shipping_address assert_field 'SHIPPING_CO', 'GB' end + def test_shipping_address_us + @helper.shipping_address :name => 'Testing Tester', + :address1 => '123 My Street', + :address2 => 'Apt. 1', + :city => 'Anytown', + :state => 'Anystate', + :zip => '54321', + :country => 'US' + + assert_field 'SHIPPING_CODE', '54321|123 My Street' + assert_field 'SHIPPING_CO', 'US' + end + def test_format_amount_as_float amount_gbp = @helper.format_amount_as_float(929, 'GBP') assert_in_delta amount_gbp, 9.29, 0.00