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

Nuvei: Add card holder name verification params #5312

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions lib/active_merchant/billing/gateways/nuvei.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def authorize(money, payment, options = {}, transaction_type = 'Auth')
add_address(post, payment, options)
add_customer_ip(post, options)
add_stored_credentials(post, payment, options)
add_cardholder_name_verification(post, payment, transaction_type, options)
post[:userTokenId] = options[:user_token_id] if options[:user_token_id]
post[:isPartialApproval] = options[:is_partial_approval] ? 1 : 0
post[:authenticationOnlyType] = options[:authentication_only_type] if options[:authentication_only_type]

if options[:execute_threed]
execute_3ds_flow(post, money, payment, transaction_type, options)
else
Expand Down Expand Up @@ -258,6 +260,21 @@ def add_address(post, payment, options)
}.compact
end

def add_cardholder_name_verification(post, payment, transaction_type, options)
return unless transaction_type == 'Auth'

post[:cardHolderNameVerification] = { performNameVerification: 'true' } if options[:perform_name_verification]

cardholder_data = {
firstName: options[:cardholder_first_name],
middleName: options[:cardholder_middle_name],
lastName: options[:cardholder_last_name]
}.compact

post[:billingAddress] ||= {}
post[:billingAddress].merge!(cardholder_data)
end

def execute_3ds_flow(post, money, payment, transaction_type, options = {})
post_3ds = post.dup

Expand Down
6 changes: 6 additions & 0 deletions test/remote/gateways/remote_nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,10 @@ def test_successful_purchase_with_google_pay
assert_equal 'APPROVED', response.message
assert_not_nil response.params[:paymentOption][:userPaymentOptionId]
end

def test_successful_authorize_with_cardholder_name_verification
response = @gateway.authorize(0, @credit_card, @options.merge({ perform_name_verification: true, cardholder_first_name: 'John', cardholder_middle_name: 'Due', cardholder_last_name: 'Tester' }))
assert_success response
assert_match 'APPROVED', response.message
end
end
23 changes: 23 additions & 0 deletions test/unit/gateways/nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ def test_successful_purchase_with_google_pay
end.respond_with(successful_purchase_response)
end

def test_successful_authorize_cardholder_name_verification
@options.merge!(
perform_name_verification: true,
cardholder_first_name: 'John',
cardholder_middle_name: 'M',
cardholder_last_name: 'Doe'
)

stub_comms(@gateway, :ssl_request) do
@gateway.authorize(@amount, @credit_card, @options)
end.check_request do |_method, endpoint, data, _headers|
json_data = JSON.parse(data)
if /payment/.match?(endpoint)
assert_match(%r(/payment), endpoint)
assert_match(/Auth/, json_data['transactionType'])
assert_equal 'true', json_data['cardHolderNameVerification']['performNameVerification']
assert_equal 'John', json_data['billingAddress']['firstName']
assert_equal 'M', json_data['billingAddress']['middleName']
assert_equal 'Doe', json_data['billingAddress']['lastName']
end
end.respond_with(successful_authorize_response)
end

private

def three_ds_assertions(payment_option_card)
Expand Down
Loading