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
BASE_URL_PRODUCTION =
'https://payment.datatrans.biz'.freeze
BASE_URL_DEVELOPMENT =
'https://pilot.datatrans.biz'.freeze
URLS =
{
  :development => {
    :web_authorize_url  => "#{BASE_URL_DEVELOPMENT}/upp/jsp/upStart.jsp".freeze,
    :xml_authorize_url  => "#{BASE_URL_DEVELOPMENT}/upp/jsp/XML_authorize.jsp".freeze,
    :xml_settlement_url => "#{BASE_URL_DEVELOPMENT}/upp/jsp/XML_processor.jsp".freeze,
    :xml_status_url     => "#{BASE_URL_DEVELOPMENT}/upp/jsp/XML_status.jsp".freeze,
  },
  :production => {
    :web_authorize_url  => "#{BASE_URL_PRODUCTION}/upp/jsp/upStart.jsp".freeze,
    :xml_authorize_url  => "#{BASE_URL_PRODUCTION}/upp/jsp/XML_authorize.jsp".freeze,
    :xml_settlement_url => "#{BASE_URL_PRODUCTION}/upp/jsp/XML_processor.jsp".freeze,
    :xml_status_url     => "#{BASE_URL_PRODUCTION}/upp/jsp/XML_status.jsp".freeze,
  }.freeze
}.freeze

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)


33
34
35
36
37
38
39
# File 'lib/datatrans/config.rb', line 33

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.



26
27
28
# File 'lib/datatrans/config.rb', line 26

def environment
  @environment
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



26
27
28
# File 'lib/datatrans/config.rb', line 26

def merchant_id
  @merchant_id
end

#proxyObject (readonly)

Returns the value of attribute proxy.



26
27
28
# File 'lib/datatrans/config.rb', line 26

def proxy
  @proxy
end

#sign_keyObject (readonly)

Returns the value of attribute sign_key.



26
27
28
# File 'lib/datatrans/config.rb', line 26

def sign_key
  @sign_key
end

Instance Method Details

#url(what) ⇒ Object

Access a url, is automatically scoped to environment



51
52
53
# File 'lib/datatrans/config.rb', line 51

def url(what)
  URLS[self.environment][what]
end

#web_transaction(*args) ⇒ Object



55
56
57
# File 'lib/datatrans/config.rb', line 55

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

#xml_transaction(*args) ⇒ Object



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

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