Class: OpenPayU::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/openpayu/configuration.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.algorithmObject

Returns the value of attribute algorithm.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def algorithm
  @algorithm
end

.client_idObject

Returns the value of attribute client_id.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def client_secret
  @client_secret
end

.continue_urlObject

Returns the value of attribute continue_url.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def continue_url
  @continue_url
end

.countryObject

Returns the value of attribute country.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def country
  @country
end

.data_formatObject

Returns the value of attribute data_format.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def data_format
  @data_format
end

.envObject

Returns the value of attribute env.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def env
  @env
end

.merchant_pos_idObject

Returns the value of attribute merchant_pos_id.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def merchant_pos_id
  @merchant_pos_id
end

.notify_urlObject

Returns the value of attribute notify_url.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def notify_url
  @notify_url
end

.order_urlObject

Returns the value of attribute order_url.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def order_url
  @order_url
end

.pos_auth_keyObject

Returns the value of attribute pos_auth_key.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def pos_auth_key
  @pos_auth_key
end

.protocolObject

Returns the value of attribute protocol.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def protocol
  @protocol
end

.service_domainObject

Returns the value of attribute service_domain.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def service_domain
  @service_domain
end

.signature_keyObject

Returns the value of attribute signature_key.



11
12
13
# File 'lib/openpayu/configuration.rb', line 11

def signature_key
  @signature_key
end

Class Method Details

.configure(file_path = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/openpayu/configuration.rb', line 15

def configure(file_path = nil)
  set_defaults
  if block_given?
    yield self
  else
    file = File.open(file_path) if file_path && File.exists?(file_path)
    env = defined?(Rails) ? Rails.env : ENV['RACK_ENV']
    config = YAML.load(file)[env]
    if config.present?
      config.each_pair do |key, value|
        send("#{key}=", value)
      end
    end
  end
  valid?
end

.get_base_urlObject



53
54
55
# File 'lib/openpayu/configuration.rb', line 53

def get_base_url
  "#{@protocol}://#{@env}.#{@service_domain}/api/v2/"
end

.required_parametersObject



40
41
42
# File 'lib/openpayu/configuration.rb', line 40

def required_parameters
  [:merchant_pos_id, :signature_key]
end

.set_defaultsObject



32
33
34
35
36
37
38
# File 'lib/openpayu/configuration.rb', line 32

def set_defaults
  @service_domain = 'payu.com'
  @env    = 'sandbox'
  @country = 'pl'
  @algorithm = 'MD5'
  @data_format = 'json'
end

.use_ssl?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/openpayu/configuration.rb', line 57

def use_ssl?
  @protocol == 'https'
end

.valid?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/openpayu/configuration.rb', line 44

def valid?
  required_parameters.each do |parameter|
    if send(parameter).nil? || send(parameter).blank?
      raise WrongConfigurationError, "Parameter #{parameter} is invalid."
    end
  end
  true
end