rbraspag 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbraspag (0.0.9)
4
+ rbraspag (0.0.10)
5
5
  cs-httpi (>= 0.9.5.2)
6
6
  json
7
7
  nokogiri
@@ -25,8 +25,8 @@ GEM
25
25
  json (1.5.3)
26
26
  linecache19 (0.5.12)
27
27
  ruby_core_source (>= 0.1.4)
28
- nokogiri (1.5.0)
29
- rack (1.3.0)
28
+ nokogiri (1.4.4)
29
+ rack (1.2.3)
30
30
  rspec (2.6.0)
31
31
  rspec-core (~> 2.6.0)
32
32
  rspec-expectations (~> 2.6.0)
@@ -21,6 +21,7 @@ require 'rbraspag/credit_card'
21
21
  require 'rbraspag/eft'
22
22
  require 'rbraspag/errors'
23
23
  require 'rbraspag/utils'
24
+ require 'rbraspag/order'
24
25
 
25
26
  module Braspag
26
27
  class Production
@@ -30,4 +31,4 @@ module Braspag
30
31
  class Test
31
32
  BASE_URL = 'https://homologacao.pagador.com.br'
32
33
  end
33
- end
34
+ end
@@ -0,0 +1,67 @@
1
+ module Braspag
2
+ class Order
3
+
4
+ class InvalidData < Exception; end
5
+
6
+ def self.status(connection, order_id)
7
+ raise InvalidConnection unless connection.is_a?(Braspag::Connection)
8
+
9
+ raise InvalidOrderId unless order_id.is_a?(String) || order_id.is_a?(Fixnum)
10
+ raise InvalidOrderId unless (1..50).include?(order_id.to_s.size)
11
+
12
+ request = ::HTTPI::Request.new("#{connection.base_url}/pagador/webservice/pedido.asmx/GetDadosPedido")
13
+ request.body = {:loja => connection.merchant_id, :numeroPedido => order_id.to_s}
14
+
15
+ response = ::HTTPI.post(request)
16
+
17
+ response = convert_to_map response.body
18
+
19
+ raise InvalidData if response[:authorization].nil?
20
+ response
21
+
22
+ end
23
+
24
+ def self.convert_to_map(document)
25
+ document = Nokogiri::XML(document)
26
+
27
+ map = {
28
+ :authorization => "CodigoAutorizacao",
29
+ :error_code => "CodigoErro",
30
+ :error_message => "MensagemErro",
31
+ :payment_method => "CodigoPagamento",
32
+ :payment_method_name => "FormaPagamento",
33
+ :installments => "NumeroParcelas",
34
+ :status => "Status",
35
+ :amount => "Valor",
36
+ :cancelled_at => "DataCancelamento",
37
+ :paid_at => "DataPagamento",
38
+ :order_date => "DataPedido",
39
+ :transaction_id => "TransId",
40
+ :tid => "BraspagTid"
41
+ }
42
+
43
+ map.each do |keyForMap , keyValue|
44
+ if keyValue.is_a?(String) || keyValue.nil?
45
+ keyValue = keyForMap if keyValue.nil?
46
+
47
+ value = document.search(keyValue).first
48
+ if !value.nil?
49
+ value = value.content.to_s
50
+ map[keyForMap] = value unless value == ""
51
+ map[keyForMap] = nil if value == ""
52
+ else
53
+ map[keyForMap] = nil
54
+ end
55
+
56
+ elsif keyValue.is_a?(Proc)
57
+ map[keyForMap] = keyValue.call
58
+ end
59
+
60
+ map[keyForMap]
61
+ end
62
+
63
+ map
64
+ end
65
+
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Braspag
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -0,0 +1,118 @@
1
+ #encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe Braspag::Order do
5
+
6
+ let!(:merchant_id) {"{84BE7E7F-698A-6C74-F820-AE359C2A07C2}"}
7
+ let!(:connection) {Braspag::Connection.new(merchant_id, :test)}
8
+
9
+ describe "#status" do
10
+
11
+ it "should raise an error when no connection is given" do
12
+ expect {
13
+ Braspag::Order.status("", nil)
14
+ }.to raise_error(Braspag::InvalidConnection)
15
+ end
16
+
17
+ it "should raise an error when no order_id is given" do
18
+ expect {
19
+ Braspag::Order.status(connection, nil)
20
+ }.to raise_error(Braspag::InvalidOrderId)
21
+ end
22
+
23
+ it "should raise an error when order_id is empty" do
24
+ expect {
25
+ Braspag::Order.status(connection, "")
26
+ }.to raise_error(Braspag::InvalidOrderId)
27
+ end
28
+
29
+ it "should raise an error when order_id is more than 50 characters" do
30
+ expect {
31
+ Braspag::Order.status(connection, "1" * 51)
32
+ }.to raise_error(Braspag::InvalidOrderId)
33
+ end
34
+
35
+ it "should raise an error for incorrect data" do
36
+ xml = <<-EOXML
37
+ <?xml version="1.0" encoding="utf-8"?>
38
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
39
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
40
+ xsi:nil="true"
41
+ xmlns="http://www.pagador.com.br/" />
42
+ EOXML
43
+
44
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/pagador/webservice/pedido.asmx/GetDadosPedido",
45
+ :body => xml)
46
+
47
+ expect {
48
+ Braspag::Order.status(connection, "sadpoakjspodqdouq09wduwq")
49
+ }.to raise_error(Braspag::Order::InvalidData)
50
+
51
+ new_connection = Braspag::Connection.new("{12345678-1234-1234-1234-123456789012}", :test)
52
+
53
+ expect {
54
+ Braspag::Order.status(new_connection, "asdnasdniousa")
55
+ }.to raise_error(Braspag::Order::InvalidData)
56
+
57
+ FakeWeb.clean_registry
58
+ end
59
+
60
+ context "with correct data" do
61
+
62
+ let(:order_info) {
63
+ xml = <<-EOXML
64
+ <?xml version="1.0" encoding="utf-8"?>
65
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
67
+ xmlns="http://www.pagador.com.br/">
68
+ <CodigoAutorizacao>885796</CodigoAutorizacao>
69
+ <CodigoPagamento>18</CodigoPagamento>
70
+ <FormaPagamento>American Express 2P</FormaPagamento>
71
+ <NumeroParcelas>1</NumeroParcelas>
72
+ <Status>3</Status>
73
+ <Valor>0.01</Valor>
74
+ <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
75
+ <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
76
+ <TransId>398591</TransId>
77
+ <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
78
+ </DadosPedido>
79
+ EOXML
80
+
81
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/pagador/webservice/pedido.asmx/GetDadosPedido",
82
+ :body => xml)
83
+ order_info = Braspag::Order.status(connection, "12345")
84
+ FakeWeb.clean_registry
85
+ order_info
86
+ }
87
+
88
+ it "should return a Hash" do
89
+ order_info.should be_kind_of Hash
90
+ end
91
+
92
+ {
93
+ :authorization => "885796",
94
+ :error_code => nil,
95
+ :error_message => nil,
96
+ :payment_method => "18",
97
+ :payment_method_name => "American Express 2P",
98
+ :installments => "1",
99
+ :status => "3",
100
+ :amount => "0.01",
101
+ :cancelled_at => nil,
102
+ :paid_at => "7/8/2011 1:19:38 PM",
103
+ :order_date => "7/8/2011 1:06:06 PM",
104
+ :transaction_id => "398591",
105
+ :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
106
+ }.each do |key, value|
107
+
108
+ it "should return a Hash with :#{key.to_s} key" do
109
+ order_info[key].should == value
110
+ end
111
+
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbraspag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,12 +14,12 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2011-07-27 00:00:00.000000000 -03:00
17
+ date: 2011-07-29 00:00:00.000000000 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cs-httpi
22
- requirement: &74919890 !ruby/object:Gem::Requirement
22
+ requirement: &76986620 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ! '>='
@@ -27,10 +27,10 @@ dependencies:
27
27
  version: 0.9.5.2
28
28
  type: :runtime
29
29
  prerelease: false
30
- version_requirements: *74919890
30
+ version_requirements: *76986620
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: json
33
- requirement: &74919680 !ruby/object:Gem::Requirement
33
+ requirement: &76986410 !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
36
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '0'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *74919680
41
+ version_requirements: *76986410
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nokogiri
44
- requirement: &74919450 !ruby/object:Gem::Requirement
44
+ requirement: &77028800 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ! '>='
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '0'
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *74919450
52
+ version_requirements: *77028800
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rspec
55
- requirement: &74919240 !ruby/object:Gem::Requirement
55
+ requirement: &77028590 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0'
61
61
  type: :development
62
62
  prerelease: false
63
- version_requirements: *74919240
63
+ version_requirements: *77028590
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: fakeweb
66
- requirement: &74919030 !ruby/object:Gem::Requirement
66
+ requirement: &77028380 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ! '>='
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *74919030
74
+ version_requirements: *77028380
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: shoulda-matchers
77
- requirement: &74918820 !ruby/object:Gem::Requirement
77
+ requirement: &77028170 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ! '>='
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '0'
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *74918820
85
+ version_requirements: *77028170
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: guard-rspec
88
- requirement: &74918610 !ruby/object:Gem::Requirement
88
+ requirement: &77027960 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ! '>='
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: '0'
94
94
  type: :development
95
95
  prerelease: false
96
- version_requirements: *74918610
96
+ version_requirements: *77027960
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-bundler
99
- requirement: &74918400 !ruby/object:Gem::Requirement
99
+ requirement: &77027750 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ! '>='
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
- version_requirements: *74918400
107
+ version_requirements: *77027750
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: ruby-debug19
110
- requirement: &74918190 !ruby/object:Gem::Requirement
110
+ requirement: &77027540 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ! '>='
@@ -115,7 +115,7 @@ dependencies:
115
115
  version: '0'
116
116
  type: :development
117
117
  prerelease: false
118
- version_requirements: *74918190
118
+ version_requirements: *77027540
119
119
  description: rbraspag gem to use Braspag gateway
120
120
  email:
121
121
  - tinorj@gmail.com
@@ -143,6 +143,7 @@ files:
143
143
  - lib/rbraspag/crypto/webservice.rb
144
144
  - lib/rbraspag/eft.rb
145
145
  - lib/rbraspag/errors.rb
146
+ - lib/rbraspag/order.rb
146
147
  - lib/rbraspag/payment_method.rb
147
148
  - lib/rbraspag/utils.rb
148
149
  - lib/rbraspag/version.rb
@@ -153,6 +154,7 @@ files:
153
154
  - spec/crypto/jar_webservice_spec.rb
154
155
  - spec/crypto/webservice_spec.rb
155
156
  - spec/eft_spec.rb
157
+ - spec/order_spec.rb
156
158
  - spec/spec_helper.rb
157
159
  - spec/utils_spec.rb
158
160
  has_rdoc: true