Skip to content

Commit

Permalink
Ebanx: Fix processing_type header
Browse files Browse the repository at this point in the history
  • Loading branch information
sinourain committed Nov 22, 2024
1 parent 6e98120 commit b37a971
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
37 changes: 15 additions & 22 deletions lib/active_merchant/billing/gateways/ebanx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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 = {})
Expand All @@ -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 = {})
Expand All @@ -88,15 +88,15 @@ 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 = {})
post = {}
add_integration_key(post)
add_authorization(post, authorization)

commit(:void, post)
commit(:void, post, options)
end

def store(credit_card, options = {})
Expand All @@ -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 = {})
Expand All @@ -117,15 +117,15 @@ 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 = {})
post = {}
add_integration_key(post)
add_authorization(post, authorization)

commit(:inquire, post)
commit(:inquire, post, options)
end

def supports_network_tokenization?
Expand Down Expand Up @@ -254,18 +254,17 @@ 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

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)

Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions test/remote/gateways/remote_ebanx_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def setup
},
tags: EbanxGateway::TAGS,
soft_descriptor: 'ActiveMerchant',
email: '[email protected]'
email: '[email protected]',
processing_type: 'local'
}

@hiper_card = credit_card('6062825624254001')
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b37a971

Please sign in to comment.