diff --git a/CHANGELOG b/CHANGELOG index 814fbc8ba7d..2142fc29de1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ * PaymentExpress: Correct endpoints [steveh] #4827 * Adyen: Add option to elect which error message [aenand] #4843 * Reach: Update list of supported countries [jcreiff] #4842 +* Paysafe: Truncate address fields [jcreiff] #4841 == Version 1.134.0 (July 25, 2023) * Update required Ruby version [almalee24] #4823 diff --git a/lib/active_merchant/billing/gateways/paysafe.rb b/lib/active_merchant/billing/gateways/paysafe.rb index 1a35de0bb3a..a7cff9fe813 100644 --- a/lib/active_merchant/billing/gateways/paysafe.rb +++ b/lib/active_merchant/billing/gateways/paysafe.rb @@ -124,12 +124,13 @@ def add_billing_address(post, options) return unless address = options[:billing_address] || options[:address] post[:billingDetails] = {} - post[:billingDetails][:street] = address[:address1] - post[:billingDetails][:city] = address[:city] - post[:billingDetails][:state] = address[:state] + post[:billingDetails][:street] = truncate(address[:address1], 50) + post[:billingDetails][:street2] = truncate(address[:address2], 50) + post[:billingDetails][:city] = truncate(address[:city], 40) + post[:billingDetails][:state] = truncate(address[:state], 40) post[:billingDetails][:country] = address[:country] - post[:billingDetails][:zip] = address[:zip] - post[:billingDetails][:phone] = address[:phone] + post[:billingDetails][:zip] = truncate(address[:zip], 10) + post[:billingDetails][:phone] = truncate(address[:phone], 40) end # The add_address_for_vaulting method is applicable to the store method, as the APIs address @@ -138,12 +139,12 @@ def add_address_for_vaulting(post, options) return unless address = options[:billing_address] || options[:address] post[:card][:billingAddress] = {} - post[:card][:billingAddress][:street] = address[:address1] - post[:card][:billingAddress][:street2] = address[:address2] - post[:card][:billingAddress][:city] = address[:city] - post[:card][:billingAddress][:zip] = address[:zip] + post[:card][:billingAddress][:street] = truncate(address[:address1], 50) + post[:card][:billingAddress][:street2] = truncate(address[:address2], 50) + post[:card][:billingAddress][:city] = truncate(address[:city], 40) + post[:card][:billingAddress][:zip] = truncate(address[:zip], 10) post[:card][:billingAddress][:country] = address[:country] - post[:card][:billingAddress][:state] = address[:state] if address[:state] + post[:card][:billingAddress][:state] = truncate(address[:state], 40) if address[:state] end # This data is specific to creating a profile at the gateway's vault level diff --git a/test/remote/gateways/remote_paysafe_test.rb b/test/remote/gateways/remote_paysafe_test.rb index c7943d6801a..72f5c0a3aae 100644 --- a/test/remote/gateways/remote_paysafe_test.rb +++ b/test/remote/gateways/remote_paysafe_test.rb @@ -148,6 +148,20 @@ def test_successful_purchase_with_airline_details assert_equal 'F', response.params['airlineTravelDetails']['tripLegs']['leg2']['serviceClass'] end + def test_successful_purchase_with_truncated_address + options = { + billing_address: { + address1: "This is an extremely long address, it is unreasonably long and we can't allow it.", + address2: "This is an extremely long address2, it is unreasonably long and we can't allow it.", + city: 'Lake Chargoggagoggmanchauggagoggchaubunagungamaugg', + state: 'NC', + zip: '27701' + } + } + response = @gateway.purchase(@amount, @credit_card, options) + assert_success response + end + def test_successful_purchase_with_token response = @gateway.purchase(200, @pm_token, @options) assert_success response diff --git a/test/unit/gateways/paysafe_test.rb b/test/unit/gateways/paysafe_test.rb index 1b4302872e9..2d7c73d90ec 100644 --- a/test/unit/gateways/paysafe_test.rb +++ b/test/unit/gateways/paysafe_test.rb @@ -263,6 +263,27 @@ def test_merchant_ref_num_and_order_id assert_success response end + def test_truncate_long_address_fields + options = { + billing_address: { + address1: "This is an extremely long address, it is unreasonably long and we can't allow it.", + address2: "This is an extremely long address2, it is unreasonably long and we can't allow it.", + city: 'Lake Chargoggagoggmanchauggagoggchaubunagungamaugg', + state: 'NC', + zip: '27701' + } + } + response = stub_comms(@gateway, :ssl_request) do + @gateway.purchase(@amount, @credit_card, options) + end.check_request do |_method, _endpoint, data, _headers| + assert_match(/"street":"This is an extremely long address, it is unreasona"/, data) + assert_match(/"street2":"This is an extremely long address2, it is unreason"/, data) + assert_match(/"city":"Lake Chargoggagoggmanchauggagoggchaubuna"/, data) + end.respond_with(successful_purchase_response) + + assert_success response + end + def test_scrub assert @gateway.supports_scrubbing? assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed