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

NMI: Add shipping_firstname, shipping_lastname, shipping_email, and s… #4825

Merged
merged 1 commit into from
Jul 14, 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 @@ -9,6 +9,7 @@
* PaywayDotCom: update `live_url` [jcreiff] #4824
* Stripe & Stripe PI: Update login key validation [almalee24] #4816
* CheckoutV2: Parse the AVS and CVV checks more often [aenand] #4822
* NMI: Add shipping_firstname, shipping_lastname, shipping_email, and surcharge fields [jcreiff] #4825

== Version 1.131.0 (June 21, 2023)
* Redsys: Add supported countries [jcreiff] #4811
Expand Down
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])
Copy link
Contributor

Choose a reason for hiding this comment

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

noice

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: '[email protected]' })

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: '[email protected]' })

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
Loading