Skip to content

Commit

Permalink
HiPay: Fix parse authorization string
Browse files Browse the repository at this point in the history
Description
-------------------------
This commit fixes the parse authorization string when the first value is nil
also fixes a issue trying to get the payment_method.brand when the
payment method is not a credit card

Unit test
-------------------------
Finished in 0.800901 seconds.

23 tests, 59 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

28.72 tests/s, 73.67 assertions/s

Remote test
-------------------------
Finished in 9.141401 seconds.

1 tests, 6 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

0.11 tests/s, 0.66 assertions/s

Rubocop
-------------------------
795 files inspected, no offenses detected
  • Loading branch information
Javier Pedroza committed May 9, 2024
1 parent 4b0ee60 commit 877ac11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/active_merchant/billing/gateways/hi_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ def authorize(money, payment_method, options = {})
response = r.process { tokenize(payment_method, options) }
card_token = response.params['token']
elsif payment_method.is_a?(String)
_transaction_ref, card_token, payment_product = payment_method.split('|')
_transaction_ref, card_token, payment_product = payment_method.split('|') if payment_method.split('|').size == 3
card_token, payment_product = payment_method.split('|') if payment_method.split('|').size == 2
end

payment_product = payment_method.is_a?(CreditCard) ? payment_method.brand : payment_product&.downcase
post = {
payment_product: payment_product&.downcase || PAYMENT_PRODUCT[payment_method.brand],
payment_product: payment_product,
operation: options[:operation] || 'Authorization',
cardtoken: card_token
}
Expand All @@ -66,7 +67,8 @@ def store(payment_method, options = {})
end

def unstore(authorization, options = {})
_transaction_ref, card_token, _payment_product = authorization.split('|')
_transaction_ref, card_token, _payment_product = authorization.split('|') if authorization.split('|').size == 3
card_token, _payment_product = authorization.split('|') if authorization.split('|').size == 2
commit('unstore', { card_token: card_token }, options, :delete)
end

Expand Down Expand Up @@ -227,7 +229,7 @@ def authorization_from(action, response)
end

def authorization_string(*args)
args.join('|')
args.flatten.compact.reject(&:empty?).join('|')
end

def post_data(params)
Expand Down
13 changes: 13 additions & 0 deletions test/unit/gateways/hi_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ def test_purchase_with_stored_pm
end.respond_with(successful_capture_response)
end

def test_authorization_string_with_nil_values
auth_string_nil_value_first = @gateway.send :authorization_string, [nil, '123456', 'visa']
assert_equal '123456|visa', auth_string_nil_value_first

auth_string_nil_values = @gateway.send :authorization_string, [nil, '123456', nil]
assert_equal '123456', auth_string_nil_values
end

def test_authorization_string_with_full_values
complete_auth_string = @gateway.send :authorization_string, %w(86786788 123456 visa)
assert_equal '86786788|123456|visa', complete_auth_string
end

def test_purhcase_with_credit_card; end

def test_capture
Expand Down

0 comments on commit 877ac11

Please sign in to comment.