Skip to content

Commit

Permalink
Firstdata: Strip newline characters from address
Browse files Browse the repository at this point in the history
Implement change to formatting of VerificationStr1 to strip out \r and
\n characters from address components.  This is to conform with tighter
verification on VerificationStr1 value introduced by FirstData in May 2020.

Unit tests:
33 tests, 160 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions,
0 notifications
100% passed

All unit tests:
4508 tests, 72015 assertions, 0 failures, 0 errors, 0 pendings, 0
omissions, 0 notifications
100% passed

Remote tests:
currently lacking valid gateway test credentials, so the remote tests
are currently all failing

Closes activemerchant#3643
  • Loading branch information
Alex Henderson authored and leila-alderman committed May 24, 2020
1 parent ec55b84 commit d3285a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* EBANX: Send original order id as merchant_payment_code metadata [miguelxpn] #3637
* Element: Add card_present_code field [schwarzgeist] #3623
* Orbital: Add support for Level 3 fields [leila-alderman] #3639
* Firstdata: Strip newline characters from address [bittercoder] #3643

== Version 1.107.3 (May 8, 2020)
* Realex: Ignore IPv6 unsupported addresses [elfassy] #3622
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/firstdata_e4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def add_credit_card_verification_strings(xml, credit_card, options)
address = options[:billing_address] || options[:address]
if address
address_values = []
[:address1, :zip, :city, :state, :country].each { |part| address_values << address[part].to_s }
[:address1, :zip, :city, :state, :country].each { |part| address_values << address[part].to_s.tr("\r\n", ' ').strip }
xml.tag! 'VerificationStr1', address_values.join('|')
end

Expand Down
9 changes: 9 additions & 0 deletions test/unit/gateways/firstdata_e4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ def test_requests_include_verification_string
end.respond_with(successful_purchase_response)
end

def test_requests_scrub_newline_and_return_characters_from_verification_string_components
stub_comms do
options_with_newline_and_return_characters_in_address = @options.merge({billing_address: address({ address1: "123 My\nStreet", address2: "K1C2N6\r", city: "Ottawa\r\n" })})
@gateway.purchase(@amount, @credit_card, options_with_newline_and_return_characters_in_address)
end.check_request do |endpoint, data, headers|
assert_match '<VerificationStr1>123 My Street|K1C2N6|Ottawa|ON|CA</VerificationStr1>', data
end.respond_with(successful_purchase_response)
end

def test_tax_fields_are_sent
stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(tax1_amount: 830, tax1_number: 'Br59a'))
Expand Down

0 comments on commit d3285a9

Please sign in to comment.