Class: VantivLite::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vantiv_lite/config.rb

Defined Under Namespace

Classes: Builder

Constant Summary collapse

InvalidEnvironment =
Class.new(StandardError)
ENVS =
{
  'sandbox' => URI('https://www.testvantivcnp.com/sandbox/communicator/online'),
  'prelive' => URI('https://payments.vantivprelive.com/vap/communicator/online'),
  'postlive' => URI('https://payments.vantivcnp.com/vap/communicator/online')
}.freeze
OPTS =
%i[env merchant_id password proxy_url report_group username version xml_lib].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Config

Returns a new instance of Config.



48
49
50
51
52
53
54
55
# File 'lib/vantiv_lite/config.rb', line 48

def initialize(**opts)
  @opts = opts.each_with_object({}) { |(k, v), h| OPTS.include?(k = k.to_sym) && h[k] = v.to_s }
  defaults!
  load_xml_lib
  env_valid?
  proxy_uri!
  @uri = ENVS[@opts[:env]]
end

Instance Attribute Details

#proxy_uriObject (readonly)

Returns the value of attribute proxy_uri.



45
46
47
# File 'lib/vantiv_lite/config.rb', line 45

def proxy_uri
  @proxy_uri
end

#sandboxObject (readonly) Also known as: sandbox?

Returns the value of attribute sandbox.



45
46
47
# File 'lib/vantiv_lite/config.rb', line 45

def sandbox
  @sandbox
end

#uriObject (readonly)

Returns the value of attribute uri.



45
46
47
# File 'lib/vantiv_lite/config.rb', line 45

def uri
  @uri
end

Class Method Details

.build(&blk) ⇒ Object



36
37
38
# File 'lib/vantiv_lite/config.rb', line 36

def build(&blk)
  Config::Builder.(&blk)
end

.with_obj(config) ⇒ Object



40
41
42
# File 'lib/vantiv_lite/config.rb', line 40

def with_obj(config)
  config.is_a?(self) ? config : new(config)
end

Instance Method Details

#optsObject



57
58
59
# File 'lib/vantiv_lite/config.rb', line 57

def opts
  @opts.dup
end

#proxy_argsObject



61
62
63
# File 'lib/vantiv_lite/config.rb', line 61

def proxy_args
  @proxy_uri ? [@proxy_uri.host, @proxy_uri.port, @proxy_uri.user, @proxy_uri.password] : []
end

#with(**opts) ⇒ Object



65
66
67
# File 'lib/vantiv_lite/config.rb', line 65

def with(**opts)
  self.class.new(@opts.merge(opts))
end