Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paysafe: Truncate address fields #4841

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a lake in Australia? I feel like they'd have a lake named something like this. And if that's the case, how dare you truncate it?!?!

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saddened to see the disrespect shown to this made up lake.


assert_success response
end

def test_scrub
assert @gateway.supports_scrubbing?
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
Expand Down
Loading