Skip to content

Commit

Permalink
NMI: Add shipping_firstname, shipping_lastname, shipping_email, and s…
Browse files Browse the repository at this point in the history
…urcharge fields

CER-666
CER-673

LOCAL
5547 tests, 77613 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

760 files inspected, no offenses detected

UNIT
56 tests, 454 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

REMOTE
51 tests, 184 assertions, 3 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
94.1176% passed

*Test failures are related to Apple Pay and eCheck, and are also failing on master
  • Loading branch information
jcreiff committed Jul 7, 2023
1 parent 2566c8b commit e3db259
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/active_merchant/billing/gateways/nmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def add_level3_fields(post, options)

def add_invoice(post, money, options)
post[:amount] = amount(money)
post[:surcharge] = options[:surcharge] if options[:surcharge]
post[:orderid] = options[:order_id]
post[:orderdescription] = options[:description]
post[:currency] = options[:currency] || currency(money)
Expand Down Expand Up @@ -232,6 +233,9 @@ def add_customer_data(post, options)
end

if (shipping_address = options[:shipping_address])
first_name, last_name = split_names(shipping_address[:name])
post[:shipping_firstname] = first_name if first_name
post[:shipping_lastname] = last_name if last_name
post[:shipping_company] = shipping_address[:company]
post[:shipping_address1] = shipping_address[:address1]
post[:shipping_address2] = shipping_address[:address2]
Expand All @@ -240,6 +244,7 @@ def add_customer_data(post, options)
post[:shipping_country] = shipping_address[:country]
post[:shipping_zip] = shipping_address[:zip]
post[:shipping_phone] = shipping_address[:phone]
post[:shipping_email] = options[:shipping_email] if options[:shipping_email]
end

if (descriptor = options[:descriptors])
Expand Down
20 changes: 20 additions & 0 deletions test/remote/gateways/remote_nmi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ def test_successful_purchase_with_descriptors
assert response.authorization
end

def test_successful_purchase_with_shipping_fields
options = @options.merge({ shipping_address: shipping_address, shipping_email: 'test@example.com' })

assert response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert response.test?
assert_equal 'Succeeded', response.message
assert response.authorization
end

def test_successful_purchase_with_surcharge
options = @options.merge({ surcharge: '1.00' })

assert response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert response.test?
assert_equal 'Succeeded', response.message
assert response.authorization
end

def test_failed_authorization
assert response = @gateway.authorize(99, @credit_card, @options)
assert_failure response
Expand Down
64 changes: 64 additions & 0 deletions test/unit/gateways/nmi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,70 @@ def test_purchase_with_options
assert_success response
end

def test_purchase_with_surcharge
options = @transaction_options.merge({ surcharge: '1.00' })

response = stub_comms do
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
test_transaction_options(data)

assert_match(/surcharge=1.00/, data)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_purchase_with_shipping_fields
options = @transaction_options.merge({ shipping_address: shipping_address })

response = stub_comms do
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
test_transaction_options(data)

assert_match(/shipping_firstname=Jon/, data)
assert_match(/shipping_lastname=Smith/, data)
assert_match(/shipping_address1=123\+Your\+Street/, data)
assert_match(/shipping_address2=Apt\+2/, data)
assert_match(/shipping_city=Toronto/, data)
assert_match(/shipping_state=ON/, data)
assert_match(/shipping_country=CA/, data)
assert_match(/shipping_zip=K2C3N7/, data)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_purchase_with_shipping_fields_omits_blank_name
options = @transaction_options.merge({ shipping_address: shipping_address(name: nil) })

response = stub_comms do
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
test_transaction_options(data)

refute_match(/shipping_firstname/, data)
refute_match(/shipping_lastname/, data)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_purchase_with_shipping_email
options = @transaction_options.merge({ shipping_address: shipping_address, shipping_email: 'test@example.com' })

response = stub_comms do
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
test_transaction_options(data)

assert_match(/shipping_email=test%40example\.com/, data)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_failed_purchase
response = stub_comms do
@gateway.purchase(@amount, @credit_card)
Expand Down

0 comments on commit e3db259

Please sign in to comment.