Class: Datatrans::Config

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

Constant Summary collapse

ENVIRONMENTS =
[:development, :production].freeze
DEFAULT_ENVIRONMENT =
:development
DEFAULT_SIGN_KEY =
false
SUBDOMAINS =
{
  payment_page: 'pay',
  server_to_server_api: 'api'
}
DOMAIN =
'datatrans.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Configure with following options

  • :merchant_id (required)

  • :sign_key (defaults to false)

  • :environment (defaults to :development, available environments are defined in ENVIRONMENTS)

  • :proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass)

Raises:

  • (ArgumentError)

21
22
23
24
25
26
27
# File 'lib/datatrans/config.rb', line 21

def initialize(options = {})
  @merchant_id = options[:merchant_id]
  raise ArgumentError.new(":merchant_id is required") unless self.merchant_id
  self.environment = options[:environment] || DEFAULT_ENVIRONMENT
  @sign_key = options[:sign_key] || DEFAULT_SIGN_KEY
  @proxy = options[:proxy] || {}
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.


14
15
16
# File 'lib/datatrans/config.rb', line 14

def environment
  @environment
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.


14
15
16
# File 'lib/datatrans/config.rb', line 14

def merchant_id
  @merchant_id
end

#proxyObject (readonly)

Returns the value of attribute proxy.


14
15
16
# File 'lib/datatrans/config.rb', line 14

def proxy
  @proxy
end

#sign_keyObject (readonly)

Returns the value of attribute sign_key.


14
15
16
# File 'lib/datatrans/config.rb', line 14

def sign_key
  @sign_key
end

Instance Method Details

#url(what) ⇒ Object

Access a url, is automatically scoped to environment


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datatrans/config.rb', line 39

def url(what)
  case what
  when :web_authorize_url
    subdomain = SUBDOMAINS[:payment_page]
    path = '/upp/jsp/upStart.jsp'
  when :xml_authorize_url
    subdomain = SUBDOMAINS[:server_to_server_api]
    path = '/upp/jsp/XML_authorize.jsp'
  when :xml_settlement_url
    subdomain = SUBDOMAINS[:server_to_server_api]
    path = '/upp/jsp/XML_processor.jsp'
  when :xml_status_url
    subdomain = SUBDOMAINS[:server_to_server_api]
    path = '/upp/jsp/XML_status.jsp'
  else
    raise "Unknown wanted action '#{what}'."
  end
  subdomain += '.sandbox' unless self.environment == :production
  "https://#{subdomain}.#{DOMAIN}#{path}"
end

#web_transaction(*args) ⇒ Object


60
61
62
# File 'lib/datatrans/config.rb', line 60

def web_transaction(*args)
  Web::Transaction.new(self, *args)
end

#xml_transaction(*args) ⇒ Object


64
65
66
# File 'lib/datatrans/config.rb', line 64

def xml_transaction(*args)
  XML::Transaction.new(self, *args)
end