Class: Braspag::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/baby-braspag/errors.rb,
lib/baby-braspag/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"
PROTECTED_CARD_PRODUCTION_URL =
"https://cartaoprotegido.braspag.com.br/Services"
PROTECTED_CARD_HOMOLOGATION_URL =
"https://homologacao.braspag.com.br/services/testenvironment"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.

Raises:


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/baby-braspag/connection.rb', line 13

def initialize
  raise InvalidEnv if ENV["BRASPAG_ENV"].nil? || ENV["BRASPAG_ENV"].empty?

  @options = YAML.load_file(Braspag.config_file_path)[ ENV['BRASPAG_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"]

  @braspag_url = @options["pagador_url"] || default_env_configuration[:pagador][@environment]
  @protected_card_url = @options["protected_card_url"] || default_env_configuration[:protected_card][@environment]
end

Instance Attribute Details

#braspag_urlObject (readonly)

Returns the value of attribute braspag_url


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def braspag_url
  @braspag_url
end

#crypto_keyObject (readonly)

Returns the value of attribute crypto_key


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def crypto_key
  @crypto_key
end

#crypto_urlObject (readonly)

Returns the value of attribute crypto_url


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def crypto_url
  @crypto_url
end

#environmentObject (readonly)

Returns the value of attribute environment


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def environment
  @environment
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def merchant_id
  @merchant_id
end

#optionsObject (readonly)

Returns the value of attribute options


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def options
  @options
end

#protected_card_urlObject (readonly)

Returns the value of attribute protected_card_url


11
12
13
# File 'lib/baby-braspag/connection.rb', line 11

def protected_card_url
  @protected_card_url
end

Instance Method Details

#default_env_configurationObject


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/baby-braspag/connection.rb', line 29

def default_env_configuration
  {
    :pagador => {
      "production"   => PRODUCTION_URL,
      "homologation" => HOMOLOGATION_URL
    },
    :protected_card  => {
      "production"   => PROTECTED_CARD_PRODUCTION_URL,
      "homologation" => PROTECTED_CARD_HOMOLOGATION_URL
    }
  }
end

#homologation?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/baby-braspag/connection.rb', line 46

def homologation?
  @environment == 'homologation'
end

#production?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/baby-braspag/connection.rb', line 42

def production?
  @environment == 'production'
end

#savon_client(url, options = {}) ⇒ Object


50
51
52
53
54
55
# File 'lib/baby-braspag/connection.rb', line 50

def savon_client(url, options = {})
  options = options.merge(Braspag.savon_global_options)
  options = options.merge(:proxy  => Braspag::proxy_address) if !Braspag::proxy_address.blank?
  options = options.merge(:wsdl => url)
  Savon.client(options)
end