Skip to content

Commit

Permalink
Nuvei: Fix send savePM in false by default
Browse files Browse the repository at this point in the history
Description
-------------------------
This commit send by default savePM in false if save_payment_method GSF is not
included in the request, only we send true for store request.

Unit test
-------------------------
28 tests, 143 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote test
-------------------------
42 tests, 136 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Rubocop
-------------------------
803 files inspected, no offenses detected
  • Loading branch information
javierpedrozaing authored and naashton committed Dec 3, 2024
1 parent 6e21157 commit 0d06a1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/active_merchant/billing/gateways/nuvei.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def initialize(options = {})

def authorize(money, payment, options = {}, transaction_type = 'Auth')
post = { transactionType: transaction_type }
post[:savePM] = options[:save_payment_method] ? options[:save_payment_method].to_s : 'false'

build_post_data(post)
add_amount(post, money, options)
Expand Down Expand Up @@ -94,6 +95,7 @@ def verify(credit_card, options = {})
end

def store(credit_card, options = {})
options[:save_payment_method] = true
authorize(0, credit_card, options)
end

Expand Down
14 changes: 11 additions & 3 deletions test/remote/gateways/remote_nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ def test_failed_purchase
end

def test_failed_purchase_with_invalid_cvv
@credit_card.verification_value = nil
@credit_card.verification_value = ''
response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert_match 'ERROR', response.params['transactionStatus']
assert_match 'Invalid CVV2', response.message
assert_match 'ERROR', response.params['status']
assert_match 'cardData.CVV is invalid', response.message
end

def test_failed_capture_invalid_transaction_id
Expand Down Expand Up @@ -220,6 +220,14 @@ def test_successful_verify
assert_match 'APPROVED', response.message
end

def test_successful_save_payment_method_override
response = @gateway.purchase(@amount, @credit_card, @options.merge(save_payment_method: false))
assert_success response
assert_match 'SUCCESS', response.params['status']
assert_match 'APPROVED', response.message
assert_not_nil response.params[:paymentOption][:userPaymentOptionId]
end

def test_successful_verify_with_authentication_only_type
response = @gateway.verify(@credit_card, @options.merge({ authentication_only_type: 'MAINTAINCARD' }))
assert_match 'SUCCESS', response.params['status']
Expand Down
2 changes: 2 additions & 0 deletions test/unit/gateways/nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_successful_purchase
end.check_request do |_method, endpoint, data, _headers|
if /payment/.match?(endpoint)
json_data = JSON.parse(data)
assert_equal 'false', json_data['savePM']
assert_match(/#{@amount}/, json_data['amount'])
assert_match(/#{@credit_card.number}/, json_data['paymentOption']['card']['cardNumber'])
assert_match(/#{@credit_card.verification_value}/, json_data['paymentOption']['card']['CVV'])
Expand Down Expand Up @@ -283,6 +284,7 @@ def test_successful_store
end.check_request do |_method, endpoint, data, _headers|
json_data = JSON.parse(data)
if /payment/.match?(endpoint)
assert_equal 'true', json_data['savePM']
assert_match(/#{@credit_card.number}/, json_data['paymentOption']['card']['cardNumber'])
assert_equal '0', json_data['amount']
end
Expand Down

0 comments on commit 0d06a1b

Please sign in to comment.