This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
forked from vinibaggio/braspag
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refatorando para suportar o ambiente de produção da Braspag
- Loading branch information
Showing
12 changed files
with
167 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
development: | ||
environment: "homologation" | ||
merchant_id: "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" | ||
braspag_url: "https://homologacao.pagador.com.br" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" | ||
|
||
test: | ||
environment: "homologation" | ||
merchant_id: "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" | ||
braspag_url: "https://homologacao.pagador.com.br" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" | ||
|
||
production: | ||
environment: "production" | ||
merchant_id: "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ def copy_config_file | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
development: | ||
environment: "homologation" | ||
merchant_id: "{YOUR_MERCHANT_ID_ON_BRASPAG}" | ||
braspag_url: "https://homologacao.pagador.com.br" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" | ||
|
||
test: | ||
environment: "homologation" | ||
merchant_id: "{YOUR_MERCHANT_ID_ON_BRASPAG}" | ||
braspag_url: "https://homologacao.pagador.com.br" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" | ||
|
||
production: | ||
environment: "production" | ||
merchant_id: "{YOUR_MERCHANT_ID_ON_BRASPAG}" | ||
braspag_url: "https://www.pagador.com.br" | ||
crypto_url: "http://localhost:9292" | ||
crypto_key: "1234561246" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
module Braspag | ||
class Connection | ||
include Singleton | ||
|
||
class InvalidMerchantId < Exception ; end | ||
class InvalidEnv < Exception ; end | ||
class InvalidBraspagUrl < Exception ; end | ||
|
||
attr_reader :braspag_url, :merchant_id, :crypto_url, :crypto_key | ||
PRODUCTION_URL = "https://transaction.pagador.com.br" | ||
HOMOLOGATION_URL = "https://homologacao.pagador.com.br" | ||
|
||
PRODUCTION_QUERY_URL = "https://query.pagador.com.br/webservices/pagador/pedido.asmx" | ||
HOMOLOGATION_QUERY_URL = "https://homologacao.pagador.com.br/pagador/webservice/pedido.asmx" | ||
|
||
attr_reader :braspag_url, :braspag_query_url, :merchant_id, :crypto_url, :crypto_key, :options, :environment | ||
|
||
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"] | ||
@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 | ||
|
||
@environment = @options["environment"] == 'production' ? 'production' : 'homologation' | ||
|
||
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? | ||
@braspag_url = self.production? ? PRODUCTION_URL : HOMOLOGATION_URL | ||
@braspag_query_url = self.production? ? PRODUCTION_QUERY_URL : HOMOLOGATION_QUERY_URL | ||
|
||
@crypto_key = @options["crypto_key"] | ||
@crypto_url = @options["crypto_url"] | ||
end | ||
|
||
def production? | ||
@environment == 'production' | ||
end | ||
|
||
@crypto_key = options["crypto_key"] | ||
@crypto_url = options["crypto_url"] | ||
@braspag_url = options["braspag_url"] | ||
@merchant_id = merchant_id | ||
def homologation? | ||
@environment == 'homologation' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.