Skip to content

Commit

Permalink
PayJunctionv2: Fix billing address fields
Browse files Browse the repository at this point in the history
The billing address fields were recently added to the PayJunctionv2
gateway but were mapped to incorrect fields for the gateway.

This update corrects these fields to send the data in the correctly
named fields according to [PayJunction's documentation](https://developer.payjunction.com/hc/en-us/articles/216477407-POST-transactions).

In addition, new remote test assertions were added to ensure that the
gateway is correctly receiving and returning the billing address fields
in the response.

CE-437

Unit:
19 tests, 87 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions,
0 notifications
100% passed

Remote:
20 tests, 63 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions,
0 notifications
100% passed

All unit tests:
4464 tests, 71595 assertions, 0 failures, 0 errors, 0 pendings, 2
omissions, 0 notifications
100% passed
  • Loading branch information
leila-alderman committed Feb 28, 2020
1 parent 5ecd3f0 commit f3f2fd2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
23 changes: 10 additions & 13 deletions lib/active_merchant/billing/gateways/pay_junction_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,16 @@ def add_payment_method(post, payment_method)
end

def add_address(post, options)
if (address = options[:billing_address])
post[:billing] = {}
post[:billing][:firstName] = address[:first_name] if address[:first_name]
post[:billing][:lastName] = address[:last_name] if address[:last_name]
post[:billing][:companyName] = address[:company] if address[:company]
post[:billing][:phone] = address[:phone_number] if address[:phone_number]

post[:billing][:address] = {}
post[:billing][:address][:address] = address[:address1] if address[:address1]
post[:billing][:address][:city] = address[:city] if address[:city]
post[:billing][:address][:state] = address[:state] if address[:state]
post[:billing][:address][:country] = address[:country] if address[:country]
post[:billing][:address][:zip] = address[:zip] if address[:zip]
if address = options[:billing_address]
post[:billingFirstName] = address[:first_name] if address[:first_name]
post[:billingLastName] = address[:last_name] if address[:last_name]
post[:billingCompanyName] = address[:company] if address[:company]
post[:billingPhone] = address[:phone_number] if address[:phone_number]
post[:billingAddress] = address[:address1] if address[:address1]
post[:billingCity] = address[:city] if address[:city]
post[:billingState] = address[:state] if address[:state]
post[:billingCountry] = address[:country] if address[:country]
post[:billingZip] = address[:zip] if address[:zip]
end
end

Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_pay_junction_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def test_successful_purchase
assert_success response
assert_equal 'Approved', response.message
assert response.test?

assert_match @options[:billing_address][:company], response.params['billing']['companyName']
assert_match @options[:billing_address][:address1], response.params['billing']['address']['address']
assert_match @options[:billing_address][:city], response.params['billing']['address']['city']
assert_match @options[:billing_address][:state], response.params['billing']['address']['state']
assert_match @options[:billing_address][:country], response.params['billing']['address']['country']
assert_match @options[:billing_address][:zip], response.params['billing']['address']['zip']
end

def test_successful_purchase_sans_options
Expand Down
19 changes: 9 additions & 10 deletions test/unit/gateways/pay_junction_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,15 @@ def test_failed_store
def test_add_address
post = {card: {billingAddress: {}}}
@gateway.send(:add_address, post, @options)
# Billing Address
assert_equal @options[:billing_address][:first_name], post[:billing][:firstName]
assert_equal @options[:billing_address][:last_name], post[:billing][:lastName]
assert_equal @options[:billing_address][:company], post[:billing][:companyName]
assert_equal @options[:billing_address][:phone_number], post[:billing][:phone]
assert_equal @options[:billing_address][:address1], post[:billing][:address][:address]
assert_equal @options[:billing_address][:city], post[:billing][:address][:city]
assert_equal @options[:billing_address][:state], post[:billing][:address][:state]
assert_equal @options[:billing_address][:country], post[:billing][:address][:country]
assert_equal @options[:billing_address][:zip], post[:billing][:address][:zip]
assert_equal @options[:billing_address][:first_name], post[:billingFirstName]
assert_equal @options[:billing_address][:last_name], post[:billingLastName]
assert_equal @options[:billing_address][:company], post[:billingCompanyName]
assert_equal @options[:billing_address][:phone_number], post[:billingPhone]
assert_equal @options[:billing_address][:address1], post[:billingAddress]
assert_equal @options[:billing_address][:city], post[:billingCity]
assert_equal @options[:billing_address][:state], post[:billingState]
assert_equal @options[:billing_address][:country], post[:billingCountry]
assert_equal @options[:billing_address][:zip], post[:billingZip]
end

def test_scrub
Expand Down

0 comments on commit f3f2fd2

Please sign in to comment.