Class: Braspag::Connection

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

Defined Under Namespace

Classes: InvalidBraspagUrl, InvalidEnv, InvalidMerchantId

Constant Summary collapse

PRODUCTION_URL =
"https://transaction.pagador.com.br"
HOMOLOGATION_URL =
"https://homologacao.pagador.com.br"

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
# 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')[ ENV['RACK_ENV'] ]
  @merchant_id = @options['merchant_id']

  raise InvalidMerchantId unless @merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i

  @crypto_key  = @options["crypto_key"]
  @crypto_url  = @options["crypto_url"]
  @environment = @options["environment"] == 'production' ? 'production' : 'homologation'

  @braspag_url = self.production? ? PRODUCTION_URL : HOMOLOGATION_URL
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

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
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

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#homologation?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rbraspag/connection.rb', line 29

def homologation?
  @environment == 'homologation'
end

#production?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rbraspag/connection.rb', line 25

def production?
  @environment == 'production'
end