Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/offsite_payments/integrations/realex_offsite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down