Skip to content

Commit

Permalink
Datatrans: Modify authorization_from string for store (activemerchant…
Browse files Browse the repository at this point in the history
…#5193)

Summary:
Modify the string for store to be separated by '|' instead of
'-'.

SER-1395

Tests
Remote Test:
Finished in 31.477035 seconds.
25 tests, 72 assertions, 0 failures, 0 errors, 0 pendings, 1 omissions, 0 notifications
100% passed

Unit Tests:
Finished in 0.115603 seconds.
29 tests, 165 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Rubocop
798 files inspected, no offenses detected

Co-authored-by: Gustavo Sanmartin <gsanmartin@EN2010363.local>
  • Loading branch information
2 people authored and bryansquadup committed Aug 21, 2024
1 parent 04e4866 commit 402a297
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/active_merchant/billing/gateways/datatrans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def store(payment_method, options = {})
end

def unstore(authorization, options = {})
data_alias = authorization.split('|')[2].split('-')[0]
data_alias = authorization.split('|')[2]
commit('delete_alias', {}, { alias_id: data_alias }, :delete)
end

Expand All @@ -110,7 +110,7 @@ def scrub(transcript)
def add_payment_method(post, payment_method)
case payment_method
when String
token, exp_month, exp_year = payment_method.split('|')[2].split('-')
token, exp_month, exp_year = payment_method.split('|')[2..4]
card = {
type: 'ALIAS',
alias: token,
Expand Down Expand Up @@ -250,9 +250,9 @@ def success_from(action, response)
end

def authorization_from(response, action, options)
string = [response.dig('responses', 0, 'alias'), options[:expiry_month], options[:expiry_year]].join('-') if action == 'tokenize'
token_array = [response.dig('responses', 0, 'alias'), options[:expiry_month], options[:expiry_year]].join('|') if action == 'tokenize'

auth = [response['transactionId'], response['acquirerAuthorizationCode'], string].join('|')
auth = [response['transactionId'], response['acquirerAuthorizationCode'], token_array].join('|')
return auth unless auth == '||'
end

Expand Down
4 changes: 2 additions & 2 deletions test/unit/gateways/datatrans_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ def test_authorization_from
assert_equal '|9248|', @gateway.send(:authorization_from, { 'acquirerAuthorizationCode' => '9248' }, '', {})
assert_equal nil, @gateway.send(:authorization_from, {}, '', {})
# tes for store
assert_equal '||any_alias-any_month-any_year', @gateway.send(:authorization_from, { 'responses' => [{ 'alias' => 'any_alias' }] }, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' })
assert_equal '||any_alias|any_month|any_year', @gateway.send(:authorization_from, { 'responses' => [{ 'alias' => 'any_alias' }] }, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' })
# handle nil responses or missing keys
assert_equal '||-any_month-any_year', @gateway.send(:authorization_from, {}, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' })
assert_equal '|||any_month|any_year', @gateway.send(:authorization_from, {}, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' })
end

def test_parse
Expand Down

0 comments on commit 402a297

Please # to comment.