lib/veritrans/client.rb in veritrans-2.1.3 vs lib/veritrans/client.rb in veritrans-2.2.0

- old
+ new

@@ -5,11 +5,12 @@ require 'excon' class Veritrans module Client - # Failback for activesupport + # If you using Rails then it will call ActiveSupport::JSON.encode + # Otherwise JSON.pretty_generate def self._json_encode(params) if defined?(ActiveSupport) && defined?(ActiveSupport::JSON) ActiveSupport::JSON.encode(params) else require 'json' unless defined?(JSON) @@ -19,10 +20,12 @@ def _json_encode(params) Veritrans::Client._json_encode(params) end + # If you using Rails then it will call ActiveSupport::JSON.decode + # Otherwise JSON.parse def self._json_decode(params) if defined?(ActiveSupport) && defined?(ActiveSupport::JSON) ActiveSupport::JSON.decode(params) else require 'json' unless defined?(JSON) @@ -76,11 +79,11 @@ #puts "Veritrans: #{method} #{url} #{_json_encode(params)}" default_options = config.http_options || {} # Add authentication and content type - # Docs http://docs.veritrans.co.id/sandbox/introduction.html + # Docs https://api-docs.midtrans.com/#http-s-header request_options = { :path => URI.parse(url).path, :headers => { :Authorization => auth_header || basic_auth_header(config.server_key), :Accept => "application/json", @@ -97,11 +100,11 @@ connection_options = { read_timeout: 120, write_timeout: 120, connect_timeout: 120 - }.deep_merge(default_options) + }.merge(default_options) s_time = Time.now request = Excon.new(url, connection_options) response = request.send(method.downcase.to_sym, request_options) @@ -109,10 +112,10 @@ logger.info "Veritrans: got #{(Time.now - s_time).round(3)} sec #{response.status} #{response.body}" Result.new(response, url, request_options, Time.now - s_time) rescue Excon::Errors::SocketError => error - logger.info "Veritrans: socket error, can not connect" + logger.info "Veritrans: socket error, can not connect (#{error.message})" error_response = Excon::Response.new( body: '{"status_code": "500", "status_message": "Internal server error, no response from backend. Try again later"}', status: '500' ) Veritrans::Result.new(error_response, url, request_options, Time.now - s_time)