lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.126.0 vs lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.129.0

- old
+ new

@@ -4,45 +4,41 @@ 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.default_currency = 'USD' - self.supported_cardtypes = %i[visa master american_express discover diners_club] + self.supported_cardtypes = %i[visa master american_express discover diners_club elo hipercard] self.homepage_url = 'http://www.ebanx.com/' self.display_name = 'EBANX' - CARD_BRAND = { - visa: 'visa', - master: 'master_card', - american_express: 'amex', - discover: 'discover', - diners_club: 'diners' - } + TAGS = ['Spreedly'] URL_MAP = { purchase: 'direct', authorize: 'direct', capture: 'capture', refund: 'refund', void: 'cancel', - store: 'token' + store: 'token', + inquire: 'query' } HTTP_METHOD = { purchase: :post, authorize: :post, capture: :get, refund: :post, void: :get, - store: :post + store: :post, + inquire: :get } VERIFY_AMOUNT_PER_COUNTRY = { 'br' => 100, 'ar' => 100, - 'co' => 100, + 'co' => 50000, 'pe' => 300, 'mx' => 2000, 'cl' => 80000 } @@ -55,11 +51,11 @@ post = { payment: {} } add_integration_key(post) add_operation(post) add_invoice(post, money, options) add_customer_data(post, payment, options) - add_card_or_token(post, payment) + add_card_or_token(post, payment, options) add_address(post, options) add_customer_responsible_person(post, payment, options) add_additional_data(post, options) commit(:purchase, post) @@ -69,11 +65,11 @@ post = { payment: {} } add_integration_key(post) add_operation(post) add_invoice(post, money, options) add_customer_data(post, payment, options) - add_card_or_token(post, payment) + add_card_or_token(post, payment, options) add_address(post, options) add_customer_responsible_person(post, payment, options) add_additional_data(post, options) post[:payment][:creditcard][:auto_capture] = false @@ -122,10 +118,18 @@ r.process { authorize(VERIFY_AMOUNT_PER_COUNTRY[customer_country(options)], credit_card, options) } r.process(:ignore_result) { void(r.authorization, options) } end end + def inquire(authorization, options = {}) + post = {} + add_integration_key(post) + add_authorization(post, authorization) + + commit(:inquire, post) + end + def supports_scrubbing? true end def scrub(transcript) @@ -149,11 +153,11 @@ post[:hash] = authorization end def add_customer_data(post, payment, options) post[:payment][:name] = customer_name(payment, options) - post[:payment][:email] = options[:email] || 'unspecified@example.com' + post[:payment][:email] = options[:email] post[:payment][:document] = options[:document] post[:payment][:birth_date] = options[:birth_date] if options[:birth_date] end def add_customer_responsible_person(post, payment, options) @@ -184,18 +188,19 @@ post[:payment][:merchant_payment_code] = Digest::MD5.hexdigest(options[:order_id]) post[:payment][:instalments] = options[:instalments] || 1 post[:payment][:order_number] = options[:order_id][0..39] if options[:order_id] end - def add_card_or_token(post, payment) - payment, brand = payment.split('|') if payment.is_a?(String) - post[:payment][:payment_type_code] = payment.is_a?(String) ? brand : CARD_BRAND[payment.brand.to_sym] + def add_card_or_token(post, payment, options) + payment = payment.split('|')[0] if payment.is_a?(String) + post[:payment][:payment_type_code] = 'creditcard' 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) - post[:payment_type_code] = CARD_BRAND[payment.brand.to_sym] + post[:payment_type_code] = 'creditcard' post[:creditcard] = payment_details(payment) end def payment_details(payment) if payment.is_a?(String) @@ -214,10 +219,11 @@ post[:device_id] = options[:device_id] if options[:device_id] 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 @@ -251,17 +257,19 @@ 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') + if %i[purchase capture refund].include?(action) - response.try(:[], 'payment').try(:[], 'status') == 'CO' + payment_status == 'CO' elsif action == :authorize - response.try(:[], 'payment').try(:[], 'status') == 'PE' + payment_status == 'PE' elsif action == :void - response.try(:[], 'payment').try(:[], 'status') == 'CA' - elsif action == :store + payment_status == 'CA' + elsif %i[store inquire].include?(action) response.try(:[], 'status') == 'SUCCESS' else false end end @@ -272,11 +280,15 @@ response.try(:[], 'payment').try(:[], 'transaction_status').try(:[], 'description') end def authorization_from(action, parameters, response) if action == :store - "#{response.try(:[], 'token')}|#{CARD_BRAND[parameters[:payment_type_code].to_sym]}" + if success_from(action, response) + "#{response.try(:[], 'token')}|#{response['payment_type_code']}" + else + response.try(:[], 'token') + end else response.try(:[], 'payment').try(:[], 'hash') end end @@ -292,10 +304,10 @@ "#{hostname}#{URL_MAP[action]}" end def requires_http_get(action) - return true if %i[capture void].include?(action) + return true if %i[capture void inquire].include?(action) false end def convert_to_url_form_encoded(parameters)