lib/veritrans/client.rb in veritrans-2.0.4 vs lib/veritrans/client.rb in veritrans-2.1.0
- old
+ new
@@ -2,25 +2,28 @@
require "base64"
require 'uri'
require 'excon'
-module Veritrans
+class Veritrans
module Client
- extend self
# Failback for activesupport
- def _json_encode(params)
+ def self._json_encode(params)
if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
ActiveSupport::JSON.encode(params)
else
require 'json' unless defined?(JSON)
- JSON.generate(params)
+ JSON.pretty_generate(params)
end
end
- def _json_decode(params)
+ def _json_encode(params)
+ Veritrans::Client._json_encode(params)
+ end
+
+ def self._json_decode(params)
if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
ActiveSupport::JSON.decode(params)
else
require 'json' unless defined?(JSON)
JSON.parse(params)
@@ -67,10 +70,12 @@
raise "Please add server_key to config/veritrans.yml"
end
method = method.to_s.upcase
logger.info "Veritrans: #{method} #{url} #{_json_encode(params)}"
+ logger.info "Veritrans: Using server key: #{config.server_key}"
+ #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
@@ -89,13 +94,13 @@
else
request_options[:body] = _json_encode(params)
end
connection_options = {
- read_timeout: 40,
- write_timeout: 40,
- connect_timeout: 40
+ read_timeout: 120,
+ write_timeout: 120,
+ connect_timeout: 120
}.deep_merge(default_options)
s_time = Time.now
request = Excon.new(url, connection_options)
@@ -104,15 +109,15 @@
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 "PAPI: socket error, can not connect"
+ logger.info "Veritrans: socket error, can not connect"
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, options, Time.now - s_time)
+ Veritrans::Result.new(error_response, url, request_options, Time.now - s_time)
end
end
end