lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.133.0 vs lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.137.0

- old
+ new

@@ -2,11 +2,11 @@ module Billing #:nodoc: class EbanxGateway < Gateway self.test_url = 'https://sandbox.ebanxpay.com/ws/' self.live_url = 'https://api.ebanxpay.com/ws/' - self.supported_countries = %w(BR MX CO CL AR PE) + self.supported_countries = %w(BR MX CO CL AR PE BO EC) self.default_currency = 'USD' self.supported_cardtypes = %i[visa master american_express discover diners_club elo hipercard] self.homepage_url = 'http://www.ebanx.com/' self.display_name = 'EBANX' @@ -18,32 +18,25 @@ authorize: 'direct', capture: 'capture', refund: 'refund', void: 'cancel', store: 'token', - inquire: 'query' + inquire: 'query', + verify: 'verifycard' } HTTP_METHOD = { purchase: :post, authorize: :post, capture: :get, refund: :post, void: :get, store: :post, - inquire: :get + inquire: :get, + verify: :post } - VERIFY_AMOUNT_PER_COUNTRY = { - 'br' => 100, - 'ar' => 100, - 'co' => 50000, - 'pe' => 300, - 'mx' => 2000, - 'cl' => 80000 - } - def initialize(options = {}) requires!(options, :integration_key) super end @@ -105,21 +98,26 @@ end def store(credit_card, options = {}) post = {} add_integration_key(post) - add_payment_details(post, credit_card) - post[:country] = customer_country(options) + customer_country(post, options) + add_payment_type(post) + post[:creditcard] = payment_details(credit_card) commit(:store, post) end def verify(credit_card, options = {}) - MultiResponse.run(:use_first_response) do |r| - r.process { authorize(VERIFY_AMOUNT_PER_COUNTRY[customer_country(options)], credit_card, options) } - r.process(:ignore_result) { void(r.authorization, options) } - end + post = {} + add_integration_key(post) + add_payment_type(post) + customer_country(post, options) + post[:card] = payment_details(credit_card) + post[:device_id] = options[:device_id] if options[:device_id] + + commit(:verify, post) end def inquire(authorization, options = {}) post = {} add_integration_key(post) @@ -190,18 +188,17 @@ post[:payment][:order_number] = options[:order_id][0..39] if options[:order_id] end def add_card_or_token(post, payment, options) payment = payment.split('|')[0] if payment.is_a?(String) - post[:payment][:payment_type_code] = 'creditcard' + add_payment_type(post[:payment]) post[:payment][:creditcard] = payment_details(payment) post[:payment][:creditcard][:soft_descriptor] = options[:soft_descriptor] if options[:soft_descriptor] end - def add_payment_details(post, payment) + def add_payment_type(post) post[:payment_type_code] = 'creditcard' - post[:creditcard] = payment_details(payment) end def payment_details(payment) if payment.is_a?(String) { token: payment } @@ -235,11 +232,11 @@ success = success_from(action, response) Response.new( success, - message_from(response), + message_from(action, response), response, authorization: authorization_from(action, parameters, response), test: test?, error_code: error_code_from(response, success) ) @@ -257,29 +254,36 @@ def add_processing_type_to_commit_headers(commit_headers, processing_type) commit_headers['x-ebanx-api-processing-type'] = processing_type end def success_from(action, response) - payment_status = response.try(:[], 'payment').try(:[], 'status') + status = response.dig('payment', 'status') - if %i[purchase capture refund].include?(action) - payment_status == 'CO' - elsif action == :authorize - payment_status == 'PE' - elsif action == :void - payment_status == 'CA' - elsif %i[store inquire].include?(action) - response.try(:[], 'status') == 'SUCCESS' + case action + when :purchase, :capture, :refund + status == 'CO' + when :authorize + status == 'PE' + when :void + status == 'CA' + when :verify + response.dig('card_verification', 'transaction_status', 'code') == 'OK' + when :store, :inquire + response.dig('status') == 'SUCCESS' else false end end - def message_from(response) + def message_from(action, response) return response['status_message'] if response['status'] == 'ERROR' - response.try(:[], 'payment').try(:[], 'transaction_status').try(:[], 'description') + if action == :verify + response.dig('card_verification', 'transaction_status', 'description') + else + response.dig('payment', 'transaction_status', 'description') + end end def authorization_from(action, parameters, response) if action == :store if success_from(action, response) @@ -325,12 +329,12 @@ response.try(:[], 'payment').try(:[], 'transaction_status').try(:[], 'code') end end - def customer_country(options) + def customer_country(post, options) if country = options[:country] || (options[:billing_address][:country] if options[:billing_address]) - country.downcase + post[:country] = country.downcase end end def customer_name(payment, options) address_name = options[:billing_address][:name] if options[:billing_address] && options[:billing_address][:name]