Skip to content

Commit

Permalink
Paysafe: Truncate address fields
Browse files Browse the repository at this point in the history
Limits the length of address fields, according to Paysafe docs
  • Loading branch information
jcreiff committed Jul 31, 2023
1 parent 9cfe650 commit 0ff6eaa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions lib/active_merchant/billing/gateways/paysafe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/remote/gateways/remote_paysafe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/unit/gateways/paysafe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ff6eaa

Please sign in to comment.