Class: Braspag::Connection
- Inherits:
-
Object
- Object
- Braspag::Connection
- 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
-
#braspag_url ⇒ Object
readonly
Returns the value of attribute braspag_url.
-
#crypto_key ⇒ Object
readonly
Returns the value of attribute crypto_key.
-
#crypto_url ⇒ Object
readonly
Returns the value of attribute crypto_url.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#merchant_id ⇒ Object
readonly
Returns the value of attribute merchant_id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#protected_card_url ⇒ Object
readonly
Returns the value of attribute protected_card_url.
Instance Method Summary collapse
- #default_env_configuration ⇒ Object
- #homologation? ⇒ Boolean
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #production? ⇒ Boolean
- #savon_client(url, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
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? = YAML.load_file(Braspag.config_file_path)[ ENV['BRASPAG_ENV'] ] @merchant_id = ['merchant_id'] raise InvalidMerchantId unless @merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i @crypto_key = ["crypto_key"] @crypto_url = ["crypto_url"] @environment = ["environment"] @braspag_url = ["pagador_url"] || default_env_configuration[:pagador][@environment] @protected_card_url = ["protected_card_url"] || default_env_configuration[:protected_card][@environment] end |
Instance Attribute Details
#braspag_url ⇒ Object (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_key ⇒ Object (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_url ⇒ Object (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 |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'lib/baby-braspag/connection.rb', line 11 def environment @environment end |
#merchant_id ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/baby-braspag/connection.rb', line 11 def end |
#protected_card_url ⇒ Object (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_configuration ⇒ Object
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
46 47 48 |
# File 'lib/baby-braspag/connection.rb', line 46 def homologation? @environment == 'homologation' end |
#production? ⇒ 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, = {}) = .merge(Braspag.) = .merge(:proxy => Braspag::proxy_address) if !Braspag::proxy_address.blank? = .merge(:wsdl => url) Savon.client() end |