braspag 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ h2. INSTALLATION
2
+
3
+ @sudo gem install gonow-braspag -s http://gems.github.com@
4
+
5
+ h2. LICENSE:
6
+
7
+ (The MIT License)
8
+
9
+ Copyright (c) 2008 FIX
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ 'Software'), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be
20
+ included in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rubygems/specification'
3
+ require 'rake'
4
+ require 'rake/gempackagetask'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "braspag"
8
+ GEM_VERSION = "0.2.0"
9
+ SUMMARY = "Access the Braspag webservices using Ruby"
10
+ AUTHOR = "Gonow"
11
+ EMAIL = "labs@gonow.com.br"
12
+ HOMEPAGE = "http://www.gonow.com.br"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.summary = SUMMARY
19
+ s.require_paths = ['lib']
20
+ s.files = FileList['lib/**/*.rb', '[A-Z]*'].to_a
21
+
22
+ s.add_dependency(%q<rubigen>, [">= 1.3.4"])
23
+
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new do |t|
30
+ t.spec_files = FileList['spec/**/*_spec.rb']
31
+ t.spec_opts = %w(-fs -fh:doc/specs.html --color)
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.gem_spec = spec
36
+ end
37
+
38
+ desc "Install the gem locally"
39
+ task :install => [:package] do
40
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
41
+ end
42
+
43
+ desc "Create a gemspec file"
44
+ task :make_spec do
45
+ File.open("#{GEM}.gemspec", "w") do |file|
46
+ file.puts spec.to_ruby
47
+ end
48
+ end
49
+
50
+ desc "Builds the project"
51
+ task :build => :spec
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'handsoap'
3
+ require 'braspag/service'
4
+ require 'braspag/cryptography'
5
+ require 'braspag/connection'
6
+ require 'braspag/buyer'
7
+ require 'braspag/recorrente'
8
+
9
+ module Braspag
10
+ class Production
11
+ BASE_URL = 'https://www.pagador.com.br'
12
+ end
13
+
14
+ class Test
15
+ BASE_URL = 'https://homologacao.pagador.com.br'
16
+ end
17
+ end
18
+
19
+ module Handsoap
20
+ class Service
21
+
22
+ private
23
+ def invoke_and_parse(method_name, soap_action, &block)
24
+ response = invoke("tns:#{method_name}", soap_action) do |message|
25
+ message.add("tns:merchantId", @connection.merchant_id)
26
+ block.call(message)
27
+ end
28
+ response.document.xpath("//ns:#{method_name}Result").first
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ module Braspag
2
+ class Buyer < Handsoap::Service
3
+ include Braspag::Service
4
+
5
+ def buy!(map)
6
+ document = invoke_and_parse('Authorize', "#{base_action_url}/Authorize") do |message|
7
+ map.each do |key, value|
8
+ message.add("tns:#{key}", "#{value}")
9
+ end
10
+ end
11
+ convert_to_map document
12
+ end
13
+
14
+ def base_action_url
15
+ "https://www.pagador.com.br/webservice/pagador"
16
+ end
17
+
18
+ def uri
19
+ "#{@connection.base_url}/webservices/pagador/Pagador.asmx"
20
+ end
21
+
22
+ def convert_to_map(document)
23
+ map = {"amount" => "", "authorisationNumber" => "", "message" => "", "returnCode" => "", "status" => "", "transactionId" => ""}
24
+ map.each_key do |key|
25
+ document.xpath("//ns:#{key}").each do |text|
26
+ map[key] = text.to_s
27
+ end
28
+ end
29
+ map
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module Braspag
2
+ class Connection
3
+ attr_reader :base_url, :environment, :merchant_id
4
+
5
+ def initialize(merchant_id, environment = :production)
6
+ environment = :test unless environment.eql? :production
7
+ @environment = eval(environment.to_s.capitalize)
8
+ @base_url = @environment::BASE_URL
9
+ @merchant_id = merchant_id
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module Braspag
2
+ class Cryptography < Handsoap::Service
3
+ include Braspag::Service
4
+
5
+ def encrypt(map)
6
+ soap_action = "#{base_action_url}/EncryptRequest"
7
+ invoke_and_parse('EncryptRequest', soap_action) do |message|
8
+ message.add("tns:request") do |sub_message|
9
+ map.each do |key, value|
10
+ sub_message.add("tns:string", "#{key}=#{value}")
11
+ end
12
+ end
13
+ end.to_s
14
+ end
15
+
16
+ def decrypt(encripted_text)
17
+ soap_action = "#{base_action_url}/DecryptRequest"
18
+ document = invoke_and_parse('DecryptRequest', soap_action) do |message|
19
+ message.add("tns:cryptString", encripted_text)
20
+ end
21
+ convert_request_to_map document
22
+ end
23
+
24
+ def base_action_url
25
+ "https://www.pagador.com.br/webservice/BraspagGeneralService"
26
+ end
27
+
28
+ def uri
29
+ "#{@connection.base_url}/BraspagGeneralService/BraspagGeneralService.asmx"
30
+ end
31
+
32
+ private
33
+ def convert_request_to_map(document)
34
+ map = {}
35
+ document.xpath("//ns:string").each do |text|
36
+ values = text.to_s.split("=")
37
+ map[values[0].downcase.to_sym] = values[1]
38
+ end
39
+ map
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Braspag
2
+ class Recorrente < Handsoap::Service
3
+ include Braspag::Service
4
+
5
+ def create_creditcard_order(map)
6
+ soap_action = "#{base_action_url}/CreateCreditCardOrder"
7
+ document = invoke_and_parse('CreateCreditCardOrder', soap_action) do |message|
8
+ map.each do |key, value|
9
+ message.add("tns:#{key}", "#{value}")
10
+ end
11
+ end
12
+ convert_to_map document
13
+ end
14
+
15
+ def base_action_url
16
+ "https://www.pagador.com.br/webservice/recorrente"
17
+ end
18
+
19
+ def uri
20
+ "#{@connection.base_url}/webservice/recorrente.asmx"
21
+ end
22
+
23
+ private
24
+ def convert_to_map(document)
25
+ map = {"code" => "", "description" => ""}
26
+ map.each_key do |key|
27
+ document.xpath("//ns:#{key}").each do |text|
28
+ map[key] = text.to_s
29
+ end
30
+ end
31
+ map
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ module Braspag
2
+ module Service
3
+ def initialize(connection)
4
+ @connection = connection
5
+ configure_endpoint
6
+ end
7
+
8
+ def on_create_document(doc)
9
+ doc.alias 'tns', base_action_url
10
+ end
11
+
12
+ def on_response_document(doc)
13
+ doc.add_namespace 'ns', base_action_url
14
+ end
15
+
16
+ private
17
+ def configure_endpoint
18
+ self.class.endpoint :uri => uri,
19
+ :version => 2
20
+ end
21
+
22
+
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: braspag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gonow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-03 00:00:00 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubigen
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.4
24
+ version:
25
+ description:
26
+ email: labs@gonow.com.br
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/braspag.rb
35
+ - lib/braspag/service.rb
36
+ - lib/braspag/buyer.rb
37
+ - lib/braspag/connection.rb
38
+ - lib/braspag/recorrente.rb
39
+ - lib/braspag/cryptography.rb
40
+ - README.textile
41
+ - Rakefile
42
+ has_rdoc: true
43
+ homepage: http://www.gonow.com.br
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Access the Braspag webservices using Ruby
70
+ test_files: []
71
+