require 'base64' require 'json' # :nodoc: module Veritrans # :nodoc: class VTDirect include Config @@attr = [:token_id, :order_id, :order_items, :gross_amount, :email, :shipping_address, :billing_address] # constructor to create instance of Veritrans::Client def initialize class < server_host} copt[:ssl] = { :ca_path => VTDirect.config["ca_path"] } if VTDirect.config["ca_path"] #"/usr/lib/ssl/certs" conn = Faraday.new( copt ) @resp = conn.post do |req| req.url(charges_url) req.headers['Content-Type'] = 'application/json' req.headers['Authorization'] = "Basic #{basic}" req.body = parms end.env @data = @resp[:body] end def void api_call(void_url) end # :nodoc: # def ca_path # return VTDirect.config["ca_path"] ? VTDirect.config["ca_path"] : Config::CA_PATH # end # :nodoc: def server_host return VTDirect.config["server_host"] ? VTDirect.config["server_host"] : Config::SERVER_HOST end # :nodoc: def tokens_url return Client.config["tokens_url"] ? Client.config["tokens_url"] : Config::TOKENS_URL end # :nodoc: def charges_url return Client.config["charges_url"] ? Client.config["charges_url"] : Config::CHARGES_URL end # :nodoc: def void_url return Client.config["void_url"] ? Client.config["void_url"] : Config::VOID_URL end # :nodoc: def server_key return VTDirect.config["server_key"] end # :nodoc: def server_key= new_server_key VTDirect.config["server_key"] = new_server_key end private def api_call(url) parms = prepare_params(@@attr).to_json basic = Base64.encode64("#{server_key}:") copt = {:url => server_host} copt[:ssl] = { :ca_path => VTDirect.config["ca_path"] } if VTDirect.config["ca_path"] #"/usr/lib/ssl/certs" conn = Faraday.new( copt ) @resp = conn.post do |req| req.url(url) req.headers['Content-Type'] = 'application/json' req.headers['Authorization'] = "Basic #{basic}" req.body = parms end.env @data = @resp[:body] end def prepare_params(*arg) params = {} arg.flatten.each do |key| value = self.send(key) params[key.to_s.downcase] = value if value end return params end end end