Module: Veritrans::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/veritrans/config.rb

Instance Method Summary collapse

Instance Method Details

#api_hostObject



49
50
51
# File 'lib/veritrans/config.rb', line 49

def api_host
  @api_host
end

#api_host=(value) ⇒ Object

API Server hostname, this allow to switch between production and sandbox

Should be “api.sandbox.veritrans.co.id” or “api.veritrans.co.id

Default is “api.sandbox.veritrans.co.id



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

def api_host=(value)
  @api_host = value
end

#client_keyObject



21
22
23
# File 'lib/veritrans/config.rb', line 21

def client_key
  @client_key
end

#client_key=(value) ⇒ Object

Merhcant’s Client key, used to make getToken request. (only for VT-Direct)

Can be found in merchant portal: Settings -> Access Keys



16
17
18
# File 'lib/veritrans/config.rb', line 16

def client_key=(value)
  @client_key = value
end

#http_optionsObject



79
80
81
# File 'lib/veritrans/config.rb', line 79

def http_options
  @http_options
end

#http_options=(options) ⇒ Object

This will override http request settings for api calls. http_options should be hash, it will be merged with connection options for every request.

Full list of options: github.com/excon/excon/blob/master/lib/excon/constants.rb

For unsupported key it will raise ArgumentError

Veritrans.config.http_options = {tcp_nodelay: true, ssl_version: 'TLSv1'}


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/veritrans/config.rb', line 63

def http_options=(options)
  unless options.is_a?(Hash)
    raise ArgumentError, "http_options should be a hash"
  end

  # Validate allowed keys
  diff = options.keys.map(&:to_sym) - Excon::VALID_CONNECTION_KEYS
  if diff.size > 0
    raise ArgumentError,
      "http_options contain unsupported keys: #{diff.inspect}\n" +
      "Supported keys are: #{Excon::VALID_CONNECTION_KEYS.inspect}"
  end

  @http_options = options
end

#inspectObject



108
109
110
111
112
113
114
# File 'lib/veritrans/config.rb', line 108

def inspect
  "<Veritrans::Config " +
    "@api_host=#{@api_host.inspect} " +
    "@server_key=#{@server_key.inspect} " +
    "@client_key=#{@client_key.inspect} " +
    "@http_options=#{@http_options.inspect}>"
end

#load_config(filename) ⇒ Object Also known as: load_yml

Loads YAML file and assign config values

Supports #section in filename to choose one section. If you are using Rails, it will try to use Rails.env as a section name

Available config keys: server_key, client_key, api_host, http_options

Veritrans.setup do
  config.load_yml "#{Rails.root.to_s}/config/veritrans.yml#development"
end


95
96
97
98
99
100
101
102
103
104
# File 'lib/veritrans/config.rb', line 95

def load_config(filename)
  yml_file, yml_section = filename.to_s.split('#')
  config_data = YAML.load(File.read(yml_file))

  if defined?(Rails) && !yml_section
    yml_section = Rails.env.to_s
  end

  apply(yml_section ? config_data[yml_section] : config_data)
end

#server_keyObject



34
35
36
# File 'lib/veritrans/config.rb', line 34

def server_key
  @server_key
end

#server_key=(value) ⇒ Object

Merhcant’s Server key, used to sign every http API call.

Can be found in merchant portal: Settings -> Access Keys



30
31
32
# File 'lib/veritrans/config.rb', line 30

def server_key=(value)
  @server_key = value
end