Class: TransactPro::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/transact_pro/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Gateway

Returns a new instance of Gateway.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/transact_pro/gateway.rb', line 4

def initialize(options)
  test = TransactPro::DEFAULTS[:TEST] || !!options[:TEST]
  verbose = !!options[:VERBOSE]

  env_key = (test ? :TEST_ENV : :PRODUCTION_ENV)

  @options = {
    pwd: Digest::SHA1.hexdigest(options[:PASSWORD].to_s),
    guid: options[:GUID].to_s
  }.merge(TransactPro::DEFAULTS[env_key])

  @options.merge!(options.merge(TEST: test, VERBOSE: verbose))

  unless @options[:GUID].to_s[%r'\A(?:\w){4}-(?:\w){4}-(?:\w){4}-(?:\w){4}\z']
    raise ArgumentError.new(
      "'#{@options[:GUID]}' is not a valid GUID for a gateway"
    )
  end

  unless @options[:PASSWORD].to_s.size > 0
    raise ArgumentError.new(
      "'#{@options[:PASSWORD]}' is not a valid PASSWORD for a gateway"
    )
  end

  if @options[:ACCOUNT_3D].to_s.size < 1 && @options[:ACCOUNT_NON3D].to_s.size < 1
    raise ArgumentError.new(
      "As a minimum specify a ACCOUNT_3D or a ACCOUNT_NON3D for a gateway"
    )
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/transact_pro/gateway.rb', line 2

def options
  @options
end

Instance Method Details

#request(request_options) ⇒ Object



36
37
38
# File 'lib/transact_pro/gateway.rb', line 36

def request(request_options)
  TransactPro::Request.new(options.merge(request_options))
end