lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.103.0 vs lib/active_merchant/billing/gateways/ebanx.rb in activemerchant-1.104.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 = ['BR', 'MX', 'CO', 'CL', 'AR'] + self.supported_countries = %w(BR MX CO CL AR PE) self.default_currency = 'USD' self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club] self.homepage_url = 'http://www.ebanx.com/' self.display_name = 'EBANX' @@ -49,10 +49,11 @@ add_invoice(post, money, options) add_customer_data(post, payment, options) add_card_or_token(post, payment) add_address(post, options) add_customer_responsible_person(post, payment, options) + add_additional_data(post, options) commit(:purchase, post) end def authorize(money, payment, options={}) @@ -71,11 +72,11 @@ def capture(money, authorization, options={}) post = {} add_integration_key(post) post[:hash] = authorization - post[:amount] = amount(money) + post[:amount] = amount(money) if options[:include_capture_amount].to_s == 'true' commit(:capture, post) end def refund(money, authorization, options={}) @@ -196,10 +197,14 @@ card_cvv: payment.verification_value } end end + def add_additional_data(post, options) + post[:device_id] = options[:device_id] if options[:device_id] + end + def parse(body) JSON.parse(body) end def commit(action, parameters) @@ -232,10 +237,11 @@ end end def message_from(response) return response['status_message'] if response['status'] == 'ERROR' + response.try(:[], 'payment').try(:[], 'transaction_status').try(:[], 'description') end def authorization_from(action, parameters, response) if action == :store @@ -246,32 +252,37 @@ end def post_data(action, parameters = {}) return nil if requires_http_get(action) return convert_to_url_form_encoded(parameters) if action == :refund + "request_body=#{parameters.to_json}" end def url_for(hostname, action, parameters) return "#{hostname}#{URL_MAP[action]}?#{convert_to_url_form_encoded(parameters)}" if requires_http_get(action) + "#{hostname}#{URL_MAP[action]}" end def requires_http_get(action) return true if [:capture, :void].include?(action) + false end def convert_to_url_form_encoded(parameters) parameters.map do |key, value| next if value != false && value.blank? + "#{key}=#{value}" end.compact.join('&') end def error_code_from(response, success) unless success return response['status_code'] if response['status'] == 'ERROR' + response.try(:[], 'payment').try(:[], 'transaction_status').try(:[], 'code') end end def customer_country(options)