Skip to content

Commit

Permalink
Nuvei: Fix isRebilling flag for Stored credentials (#5408)
Browse files Browse the repository at this point in the history
* Nuvei: Fix isRebilling flag for Stored credentials

Description
-------------------------
[SER-1617](https://spreedly.atlassian.net/browse/SER-1617)

This commit sends `isRebilling` field only for MIT transactions,
set "0" when is init MIT or "1" for subsequent MIT

Unit test
-------------------------
Finished in 1.482941 seconds.

34 tests, 180 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

22.93 tests/s, 121.38 assertions/s

Remote test
-------------------------
Finished in 601.986719 seconds.

45 tests, 150 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

0.07 tests/s, 0.25 assertions/s

Rubocop
-------------------------
808 files inspected, no offenses detected

* changelog

---------

Co-authored-by: Nick Ashton <[email protected]>
  • Loading branch information
javierpedrozaing and naashton authored Feb 20, 2025
1 parent 63757ac commit a52fb1f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
* New Credit Card Sol: Add new bin set for Sol credit card [javierpedrozaing] #5380
* Credit Card Sol: Update card name to `tarjeta_sol` instead of `sol` [javierpedrozaing] #5404
* Routex Bin: Update routex bin range to include 18 digits [yunnydang] #5410
* Nuvei: Fix isRebilling flag for Stored credentials [javierpedrozaing] #5408

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
5 changes: 4 additions & 1 deletion lib/active_merchant/billing/gateways/nuvei.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ def set_initiator_type(post, payment, options)
post[:paymentOption][:card][:storedCredentials] ||= {}
post[:paymentOption][:card][:storedCredentials][:storedCredentialsMode] = stored_credentials_mode
end
post[:isRebilling] = options[:is_rebilling] ? '1' : '0' if mit?(options[:stored_credential])
end

post[:isRebilling] = stored_credentials_mode
def mit?(stored_credential)
stored_credential[:reason_type] != 'unscheduled' && stored_credential[:initial_transaction] == false
end

def add_account_funding_transaction(post, payment, options = {})
Expand Down
13 changes: 12 additions & 1 deletion test/remote/gateways/remote_nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_purchase_using_stored_credentials_merchant_installments_cit
assert_match 'SUCCESS', recurring_response.params['status']
end

def test_purchase_subsequent_mit
def test_purchase_subsequent_init_mit
initial_options = @options.merge(user_token_id: '12345678', stored_credential: stored_credential(:merchant, :unscheduled, :initial))
initial_response = @gateway.purchase(@amount, @credit_card, initial_options)
assert_success initial_response
Expand All @@ -376,6 +376,17 @@ def test_purchase_subsequent_mit
assert_match 'SUCCESS', subsequent_response.params['status']
end

def test_successful_purchase_subsequent_mit
initial_options = @options.merge(user_token_id: '12345678', stored_credential: stored_credential(:merchant, :unscheduled, :initial))
initial_response = @gateway.purchase(@amount, @credit_card, initial_options)
assert_success initial_response

subsequent_options = @options.merge(user_token_id: '12345678', stored_credential: stored_credential(:merchant, :recurring, network_transaction_id: initial_response.authorization))
subsequent_response = @gateway.purchase(@amount, @credit_card, subsequent_options.merge(is_rebilling: true))
assert_success subsequent_response
assert_match 'SUCCESS', subsequent_response.params['status']
end

def test_successful_partial_approval
response = @gateway.authorize(55, @credit_card, @options.merge(is_partial_approval: true))
assert_success response
Expand Down
20 changes: 17 additions & 3 deletions test/unit/gateways/nuvei_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,30 @@ def test_successful_stored_credentials_cardholder_unscheduled
end.check_request do |_method, endpoint, data, _headers|
if /payment/.match?(endpoint)
json_data = JSON.parse(data)
assert_equal('0', json_data['isRebilling'])
assert_not_includes(json_data, 'isRebilling')
assert_equal('0', json_data['paymentOption']['card']['storedCredentials']['storedCredentialsMode'])
assert_match(/ADDCARD/, json_data['authenticationOnlyType'])
end
end.respond_with(successful_purchase_response)
end

def test_successful_stored_credentials_merchant_recurring
def test_successful_stored_credentials_init_mit
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: stored_credential(:merchant, :recurring, id: 'abc123'), is_rebilling: false))
end.check_request do |_method, endpoint, data, _headers|
if /payment/.match?(endpoint)
json_data = JSON.parse(data)
assert_equal('0', json_data['isRebilling'])
assert_equal('1', json_data['paymentOption']['card']['storedCredentials']['storedCredentialsMode'])
assert_match(/abc123/, json_data['relatedTransactionId'])
assert_match(/RECURRING/, json_data['authenticationOnlyType'])
end
end.respond_with(successful_purchase_response)
end

def test_successful_stored_credentials_subsequent_mit
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: stored_credential(:merchant, :recurring, id: 'abc123')))
@gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: stored_credential(:merchant, :recurring, id: 'abc123'), is_rebilling: true))
end.check_request do |_method, endpoint, data, _headers|
if /payment/.match?(endpoint)
json_data = JSON.parse(data)
Expand Down

0 comments on commit a52fb1f

Please sign in to comment.