Class: AtPay::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



24
25
26
27
28
29
30
31
32
# File 'lib/atpay/config.rb', line 24

def initialize(options)
  options.each do |k,v|
    self.send("#{k.to_s}=", v)
  end

  unless options[:environment] or (atpay_private_key and atpay_public_key)
    self.environment = :sandbox
  end
end

Instance Attribute Details

#partner_idObject

Returns the value of attribute partner_id.



17
18
19
# File 'lib/atpay/config.rb', line 17

def partner_id
  @partner_id
end

Class Method Details

.base64_decoding_attr_accessor(*names) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/atpay/config.rb', line 6

def base64_decoding_attr_accessor(*names)
  names.each do |name|
    attr_reader name

    define_method "#{name}=" do |v|
      instance_variable_set("@#{name}", Base64.decode64(v))
    end
  end
end

Instance Method Details

#environment=(v) ⇒ Object

Raises:

  • (ValueError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/atpay/config.rb', line 38

def environment=(v)
  @environment = v

  raise ValueError unless [:production, :sandbox, :development, :test].include? v

  @atpay_public_key = Base64.decode64({
    production: "QZuSjGhUz2DKEvjule1uRuW+N6vCOoMuR2PgCl57vB0=",
    sandbox: "x3iJge6NCMx9cYqxoJHmFgUryVyXqCwapGapFURYh18=",
    development: "x3iJge6NCMx9cYqxoJHmFgUryVyXqCwapGapFURYh18=",
    test: '8LkeQ7BDO8+e+WRFLWV6Ac4Aq8Ev0odtWOiR1adDYyI='
  }[v])

  if @environment == :test
    @atpay_private_key ||= Base64.decode64('bSyQWtGrWsYfJSZisrZ5eKHKcjtZQv1RO299tJ9bqIg=')
  end
end