class VantivLite::Request

Constants

InvalidConfig
ResponseError

Attributes

config[R]
http[R]
serializer[R]

Public Class Methods

new(config = VantivLite.default_config, http: nil, serializer: nil) click to toggle source
# File lib/vantiv_lite/request.rb, line 24
def initialize(config = VantivLite.default_config, http: nil, serializer: nil)
  raise InvalidConfig, 'invalid or missing config' unless config.is_a?(Config)
  @config = config
  @http = http || _http
  @parser = XML.parser_with(config.xml_lib)
  @serializer = serializer || XML.serializer_with(config.xml_lib)
end

Public Instance Methods

call(request_hash, *dig_keys) click to toggle source
# File lib/vantiv_lite/request.rb, line 32
def call(request_hash, *dig_keys)
  Response.new(post(serializer.(format_request(request_hash))), *dig_keys, parser: @parser)
end
post(xml) click to toggle source
# File lib/vantiv_lite/request.rb, line 36
def post(xml)
  http.dup.start { |h| h.request(post_request(xml)) }
end

Private Instance Methods

_http() click to toggle source
# File lib/vantiv_lite/request.rb, line 48
def _http
  Net::HTTP.new(config.uri.host, config.uri.port, *config.proxy_args).tap do |h|
    h.use_ssl = true if config.uri.scheme == 'https'
  end
end
default_attributes_with(hash) click to toggle source
# File lib/vantiv_lite/request.rb, line 54
def default_attributes_with(hash)
  hash['id'] ||= '0'
  hash['reportGroup'] ||= config.report_group
  hash
end
format_request(request_hash) click to toggle source
# File lib/vantiv_lite/request.rb, line 60
def format_request(request_hash)
  {
    'litleOnlineRequest' => {
      'xmlns' => 'http://www.litle.com/schema',
      'version' => config.version,
      'merchantId' => config.merchant_id,
      'authentication' => { 'user' => config.username, 'password' => config.password }
    }.merge(insert_default_attributes(request_hash))
  }
end
insert_default_attributes(request_hash) click to toggle source
# File lib/vantiv_lite/request.rb, line 71
def insert_default_attributes(request_hash)
  request_hash.each_with_object({}) do |(k, obj), h|
    h[k] = XML.hash_or_array(obj) { |o| default_attributes_with(o) }
  end
end
post_request(xml) click to toggle source
# File lib/vantiv_lite/request.rb, line 77
def post_request(xml)
  Net::HTTP::Post.new(config.uri.path).tap do |r|
    r['Content-Type'] ||= 'text/xml; charset=UTF-8'
    r.body = xml
  end
end