Class: Braspag::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rbraspag/connection.rb

Defined Under Namespace

Classes: InvalidBraspagUrl, InvalidEnv, InvalidMerchantId

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbraspag/connection.rb', line 10

def initialize
  raise InvalidEnv if ENV["RACK_ENV"].nil? || ENV["RACK_ENV"].empty?
  options = YAML.load_file("config/braspag.yml")
  options = options[ENV["RACK_ENV"]]

  merchant_id = options["merchant_id"]

  raise InvalidMerchantId unless merchant_id.length == 38
  raise InvalidMerchantId unless merchant_id.match /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i
  raise InvalidBraspagUrl if options["braspag_url"].nil? || options["braspag_url"].empty?

  @crypto_key = options["crypto_key"]
  @crypto_url = options["crypto_url"]
  @braspag_url = options["braspag_url"]
  @merchant_id = merchant_id
end

Instance Attribute Details

#braspag_urlObject (readonly)

Returns the value of attribute braspag_url.



8
9
10
# File 'lib/rbraspag/connection.rb', line 8

def braspag_url
  @braspag_url
end

#crypto_keyObject (readonly)

Returns the value of attribute crypto_key.



8
9
10
# File 'lib/rbraspag/connection.rb', line 8

def crypto_key
  @crypto_key
end

#crypto_urlObject (readonly)

Returns the value of attribute crypto_url.



8
9
10
# File 'lib/rbraspag/connection.rb', line 8

def crypto_url
  @crypto_url
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



8
9
10
# File 'lib/rbraspag/connection.rb', line 8

def merchant_id
  @merchant_id
end