diff --git a/lib/active_merchant/billing/gateways/ebanx.rb b/lib/active_merchant/billing/gateways/ebanx.rb index 2dee65571f1..73b56f53203 100644 --- a/lib/active_merchant/billing/gateways/ebanx.rb +++ b/lib/active_merchant/billing/gateways/ebanx.rb @@ -52,7 +52,7 @@ def purchase(money, payment, options = {}) add_additional_data(post, options) add_stored_credentials(post, options) - commit(:purchase, post) + commit(:purchase, post, options) end def authorize(money, payment, options = {}) @@ -68,7 +68,7 @@ def authorize(money, payment, options = {}) add_stored_credentials(post, options) post[:payment][:creditcard][:auto_capture] = false - commit(:authorize, post) + commit(:authorize, post, options) end def capture(money, authorization, options = {}) @@ -77,7 +77,7 @@ def capture(money, authorization, options = {}) post[:hash] = authorization post[:amount] = amount(money) if options[:include_capture_amount].to_s == 'true' - commit(:capture, post) + commit(:capture, post, options) end def refund(money, authorization, options = {}) @@ -88,7 +88,7 @@ def refund(money, authorization, options = {}) post[:amount] = amount(money) post[:description] = options[:description] - commit(:refund, post) + commit(:refund, post, options) end def void(authorization, options = {}) @@ -96,7 +96,7 @@ def void(authorization, options = {}) add_integration_key(post) add_authorization(post, authorization) - commit(:void, post) + commit(:void, post, options) end def store(credit_card, options = {}) @@ -106,7 +106,7 @@ def store(credit_card, options = {}) add_payment_type(post) post[:creditcard] = payment_details(credit_card) - commit(:store, post) + commit(:store, post, options) end def verify(credit_card, options = {}) @@ -117,7 +117,7 @@ def verify(credit_card, options = {}) post[:card] = payment_details(credit_card) post[:device_id] = options[:device_id] if options[:device_id] - commit(:verify, post) + commit(:verify, post, options) end def inquire(authorization, options = {}) @@ -125,7 +125,7 @@ def inquire(authorization, options = {}) add_integration_key(post) add_authorization(post, authorization) - commit(:inquire, post) + commit(:inquire, post, options) end def supports_network_tokenization? @@ -254,7 +254,6 @@ def add_additional_data(post, options) post[:metadata] = options[:metadata] if options[:metadata] post[:metadata] = {} if post[:metadata].nil? post[:metadata][:merchant_payment_code] = options[:order_id] if options[:order_id] - post[:processing_type] = options[:processing_type] if options[:processing_type] post[:payment][:tags] = TAGS end @@ -262,10 +261,10 @@ def parse(body) JSON.parse(body) end - def commit(action, parameters) + def commit(action, parameters, options) url = url_for((test? ? test_url : live_url), action, parameters) - response = parse(ssl_request(HTTP_METHOD[action], url, post_data(action, parameters), headers(parameters))) + response = parse(ssl_request(HTTP_METHOD[action], url, post_data(action, parameters), headers(options))) success = success_from(action, response) @@ -279,17 +278,11 @@ def commit(action, parameters) ) end - def headers(params) - processing_type = params[:processing_type] - commit_headers = { 'x-ebanx-client-user-agent': "ActiveMerchant/#{ActiveMerchant::VERSION}" } - - add_processing_type_to_commit_headers(commit_headers, processing_type) if processing_type == 'local' - - commit_headers - end - - def add_processing_type_to_commit_headers(commit_headers, processing_type) - commit_headers['x-ebanx-api-processing-type'] = processing_type + def headers(options) + { + 'x-ebanx-client-user-agent': "ActiveMerchant/#{ActiveMerchant::VERSION}", + 'x-ebanx-api-processing-type': ('local' if options[:processing_type] == 'local') + }.compact end def success_from(action, response) diff --git a/test/remote/gateways/remote_ebanx_test.rb b/test/remote/gateways/remote_ebanx_test.rb index 5518d9500d1..1b1d391772f 100644 --- a/test/remote/gateways/remote_ebanx_test.rb +++ b/test/remote/gateways/remote_ebanx_test.rb @@ -25,7 +25,8 @@ def setup }, tags: EbanxGateway::TAGS, soft_descriptor: 'ActiveMerchant', - email: 'neymar@test.com' + email: 'neymar@test.com', + processing_type: 'local' } @hiper_card = credit_card('6062825624254001') @@ -153,7 +154,7 @@ def test_successful_partial_capture_when_include_capture_amount_is_not_passed auth = @gateway.authorize(@amount, @credit_card, @options) assert_success auth - assert capture = @gateway.capture(@amount - 1, auth.authorization) + assert capture = @gateway.capture(@amount - 1, auth.authorization, { processing_type: 'local' }) assert_success capture end @@ -168,7 +169,7 @@ def test_failed_partial_capture_when_include_capture_amount_is_passed end def test_failed_capture - response = @gateway.capture(@amount, '') + response = @gateway.capture(@amount, '', { processing_type: 'local' }) assert_failure response assert_equal 'Parameters hash or merchant_payment_code not informed', response.message end @@ -193,7 +194,7 @@ def test_partial_refund end def test_failed_refund - response = @gateway.refund(@amount, '') + response = @gateway.refund(@amount, '', { processing_type: 'local' }) assert_failure response assert_equal 'Parameters hash or merchant_payment_code not informed', response.message assert_equal 'BP-REF-1', response.error_code @@ -203,13 +204,13 @@ def test_successful_void auth = @gateway.authorize(@amount, @credit_card, @options) assert_success auth - assert void = @gateway.void(auth.authorization) + assert void = @gateway.void(auth.authorization, { processing_type: 'local' }) assert_success void assert_equal 'Accepted', void.message end def test_failed_void - response = @gateway.void('') + response = @gateway.void('', { processing_type: 'local' }) assert_failure response assert_equal 'Parameters hash or merchant_payment_code not informed', response.message end @@ -321,7 +322,7 @@ def test_successful_inquire purchase = @gateway.purchase(@amount, @credit_card, @options) assert_success purchase - inquire = @gateway.inquire(purchase.authorization) + inquire = @gateway.inquire(purchase.authorization, { processing_type: 'local' }) assert_success inquire assert_equal 'Accepted', purchase.message