Skip to content

Commit

Permalink
NMI: add customer vault fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Aug 15, 2024
1 parent 107c1d4 commit 59545a5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
* NMI: Fix Decrypted indicator for Google/Apple pay [javierpedrozaing] #5196
* FlexCharge: add more descriptives error messages [gasb150] #5199
* Braintree: Updates to Paypal Integration [almalee24] #5190
* Stripe and Stripe PI: Add metadata and order_id for refund and void [yunnydang] #5204
* CommerceHub: Update test url [DustinHaefele] #5211
* Adyen: Fix billing address empty string error [yunnydang] #5208
* Elavon: Update sending CVV for MIT transactions [almalee24] #5210
* Adyen: Fix NT integration [jherreraa] #5155
* HPS: Update NetworkTokenizationCreditCard flow [almalee24] #5178
* Braintree: Support override_application_id [aenand] #5194
* Decidir: Pass CVV for NT [almalee24] #5205
* NMI: Add customer vault fields [yunnydang] #5215

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down Expand Up @@ -43,8 +46,6 @@
* Elavon: Add updated stored credential version [almalee24] #5170
* Adyen: Add header fields to response body [yunnydang] #5184
* Stripe and Stripe PI: Add header fields to response body [yunnydang] #5185
* Stripe and Stripe PI: Add metadata and order_id for refund and void [yunnydang] #5204
* Adyen: Fix billing address empty string error [yunnydang] #5208

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
8 changes: 8 additions & 0 deletions lib/active_merchant/billing/gateways/nmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(options = {})
def purchase(amount, payment_method, options = {})
post = {}
add_invoice(post, amount, options)
add_customer_vault_data(post, options)
add_payment_method(post, payment_method, options)
add_stored_credential(post, options)
add_customer_data(post, options)
Expand All @@ -48,6 +49,7 @@ def purchase(amount, payment_method, options = {})
def authorize(amount, payment_method, options = {})
post = {}
add_invoice(post, amount, options)
add_customer_vault_data(post, options)
add_payment_method(post, payment_method, options)
add_stored_credential(post, options)
add_customer_data(post, options)
Expand Down Expand Up @@ -97,6 +99,7 @@ def credit(amount, payment_method, options = {})

def verify(payment_method, options = {})
post = {}
add_customer_vault_data(post, options)
add_payment_method(post, payment_method, options)
add_customer_data(post, options)
add_vendor_data(post, options)
Expand Down Expand Up @@ -279,6 +282,11 @@ def add_vendor_data(post, options)
post[:processor_id] = options[:processor_id] if options[:processor_id]
end

def add_customer_vault_data(post, options)
post[:customer_vault] = options[:customer_vault] if options[:customer_vault]
post[:customer_vault_id] = options[:customer_vault_id] if options[:customer_vault_id]
end

def add_merchant_defined_fields(post, options)
(1..20).each do |each|
key = "merchant_defined_field_#{each}".to_sym
Expand Down
56 changes: 56 additions & 0 deletions test/remote/gateways/remote_nmi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ def test_successful_purchase
assert response.authorization
end

def test_successful_purchase_with_customer_vault_data
vault_id = SecureRandom.hex(16)

options = {
order_id: generate_unique_id,
billing_address: address,
description: 'Store purchase',
customer_vault: 'add_customer'
}

assert response = @gateway.purchase(@amount, @credit_card, options.merge(customer_vault_id: vault_id))
assert_success response
assert response.test?
assert_equal 'Succeeded', response.message
assert_equal vault_id, response.params['customer_vault_id']
assert response.authorization
end

def test_successful_purchase_with_customer_vault_and_auto_generate_customer_vault_id
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(customer_vault: 'add_customer'))
assert_success response
assert response.test?

assert_equal 'Succeeded', response.message
assert response.params.include?('customer_vault_id')
assert response.authorization
end

def test_successful_purchase_sans_cvv
@credit_card.verification_value = nil
assert response = @gateway.purchase(@amount, @credit_card, @options)
Expand Down Expand Up @@ -353,6 +381,34 @@ def test_successful_verify
assert_match 'Succeeded', response.message
end

def test_successful_verify_with_customer_vault_data
vault_id = SecureRandom.hex(16)

options = {
order_id: generate_unique_id,
billing_address: address,
description: 'Store purchase',
customer_vault: 'add_customer'
}

assert response = @gateway.verify(@credit_card, options.merge(customer_vault_id: vault_id))
assert_success response
assert response.test?
assert_equal 'Succeeded', response.message
assert_equal vault_id, response.params['customer_vault_id']
assert response.authorization
end

def test_successful_verify_with_customer_vault_and_auto_generate_customer_vault_id
assert response = @gateway.verify(@credit_card, @options.merge(customer_vault: 'add_customer'))
assert_success response
assert response.test?

assert_equal 'Succeeded', response.message
assert response.params.include?('customer_vault_id')
assert response.authorization
end

def test_failed_verify
card = credit_card(year: 2010)
response = @gateway.verify(card, @options)
Expand Down
17 changes: 17 additions & 0 deletions test/unit/gateways/nmi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ def test_purchase_with_shipping_fields
assert_success response
end

def test_purchase_with_customer_vault_options
options = {
description: 'Store purchase',
customer_vault: 'add_customer',
customer_vault_id: '12345abcde'
}

response = stub_comms do
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
assert_match(/customer_vault=add_customer/, data)
assert_match(/customer_vault_id=12345abcde/, 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) })

Expand Down

0 comments on commit 59545a5

Please sign in to comment.