cbraspag 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.md +4 -3
  2. data/cbraspag.gemspec +2 -0
  3. data/coverage/.resultset.json +3445 -0
  4. data/coverage/assets/0.5.3/app.js +88 -0
  5. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  6. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  7. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  8. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  9. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  10. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  11. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  25. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  26. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  27. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  28. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  29. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  30. data/coverage/assets/0.5.3/highlight.css +129 -0
  31. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  32. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  33. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  34. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  35. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  36. data/coverage/assets/0.5.3/loading.gif +0 -0
  37. data/coverage/assets/0.5.3/magnify.png +0 -0
  38. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  39. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  40. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  41. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  42. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  43. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  51. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  52. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  53. data/coverage/index.html +21549 -0
  54. data/lib/cbraspag.rb +1 -1
  55. data/lib/cbraspag/core/connection.rb +25 -20
  56. data/lib/cbraspag/core/converter.rb +22 -119
  57. data/lib/cbraspag/core/customer.rb +0 -24
  58. data/lib/cbraspag/core/order.rb +179 -129
  59. data/lib/cbraspag/payment/billet.rb +38 -17
  60. data/lib/cbraspag/payment/credit_card.rb +86 -112
  61. data/lib/cbraspag/payment/eft.rb +0 -16
  62. data/lib/cbraspag/payment/recurrency_credit_card.rb +99 -0
  63. data/lib/cbraspag/version.rb +1 -1
  64. data/spec/core/connection_spec.rb +56 -2
  65. data/spec/core/converter_spec.rb +49 -10
  66. data/spec/core/order_spec.rb +315 -193
  67. data/spec/integration/billet_spec.rb +38 -0
  68. data/spec/integration/credit_card_spec.rb +0 -0
  69. data/spec/payment/billet_spec.rb +130 -81
  70. data/spec/payment/credit_card_spec.rb +263 -487
  71. data/spec/payment/recurrency_credit_card_spec.rb +479 -0
  72. data/spec/spec_helper.rb +15 -2
  73. metadata +92 -6
  74. data/Guardfile +0 -10
  75. data/lib/cbraspag/core/response.rb +0 -27
  76. data/spec/core/response_spec.rb +0 -5
@@ -1,3 +1,3 @@
1
1
  module Braspag
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -68,7 +68,7 @@ describe Braspag::Connection do
68
68
  connection.url_for(:generate_billet).should == "#{braspag_homologation_url}/webservices/pagador/Boleto.asmx/CreateBoleto"
69
69
  connection.url_for(:generate_eft).should == "#{braspag_homologation_url}/pagador/passthru.asp"
70
70
  connection.url_for(:info_billet).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosBoleto"
71
- connection.url_for(:info_card).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosCartao"
71
+ connection.url_for(:info_credit_card).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosCartao"
72
72
  connection.url_for(:info).should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosPedido"
73
73
  connection.url_for(:encrypt).should == "#{braspag_homologation_url}/BraspagGeneralService/BraspagGeneralService.asmx"
74
74
  connection.url_for(:archive_card).should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx?wsdl"
@@ -84,7 +84,7 @@ describe Braspag::Connection do
84
84
  connection.url_for(:generate_billet).should == "#{braspag_production_url}/webservices/pagador/Boleto.asmx/CreateBoleto"
85
85
  connection.url_for(:generate_eft).should == "#{braspag_production_url}/pagador/passthru.asp"
86
86
  connection.url_for(:info_billet).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosBoleto"
87
- connection.url_for(:info_card).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosCartao"
87
+ connection.url_for(:info_credit_card).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosCartao"
88
88
  connection.url_for(:info).should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosPedido"
89
89
  connection.url_for(:encrypt).should == "#{braspag_production_url}/BraspagGeneralService/BraspagGeneralService.asmx"
90
90
  connection.url_for(:archive_card).should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx?wsdl"
@@ -92,4 +92,58 @@ describe Braspag::Connection do
92
92
  connection.url_for(:recurrency).should == "#{braspag_production_protected_card_url}/CartaoProtegido.asmx?wsdl"
93
93
  end
94
94
  end
95
+
96
+ describe ".post" do
97
+ it "should convert data" do
98
+ connection = Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)
99
+
100
+ mock1 = mock
101
+ mock2 = mock
102
+ resp = mock
103
+ convert_to = mock
104
+
105
+ connection.should_receive(:convert).with(
106
+ :info,
107
+ :to,
108
+ [mock1, mock2]
109
+ ).and_return(convert_to)
110
+
111
+ connection.should_receive(:convert).with(
112
+ :info,
113
+ :from,
114
+ [mock1, mock2, resp]
115
+ )
116
+
117
+ Braspag::Poster.any_instance.should_receive(:do_post).with(
118
+ :info,
119
+ convert_to
120
+ ).and_return(resp)
121
+
122
+ connection.post(:info, mock1, mock2)
123
+ end
124
+ end
125
+
126
+ describe ".convert" do
127
+ let (:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation) }
128
+ {
129
+ :authorize => Braspag::CreditCard,
130
+ :void => Braspag::CreditCard,
131
+ :capture => Braspag::CreditCard,
132
+ :archive_card => Braspag::CreditCard,
133
+ :get_card => Braspag::CreditCard,
134
+ :recurrency => Braspag::CreditCard,
135
+ :generate_billet => Braspag::Billet,
136
+ :generate_eft => Braspag::EFT,
137
+ :info_billet => Braspag::Order,
138
+ :info_credit_card => Braspag::Order,
139
+ :info => Braspag::Order,
140
+ :encrypt => Braspag::Crypto::Webservice
141
+ }.each do |method_name, kclass|
142
+ it "should call method when convert #{method_name} to #{kclass}" do
143
+ args = [mock, mock]
144
+ kclass.should_receive("to_#{method_name}".to_sym).with(connection, args[0], args[1])
145
+ connection.convert(method_name, :to, args)
146
+ end
147
+ end
148
+ end
95
149
  end
@@ -3,17 +3,32 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Braspag::Converter do
4
4
  describe ".decimal_to_string" do
5
5
  it "should convert decimal to string with comma as decimal separator" do
6
- Braspag::Converter.decimal_to_string(10).should == "10,00"
7
- Braspag::Converter.decimal_to_string(1).should == "1,00"
8
- Braspag::Converter.decimal_to_string(0.1).should == "0,10"
9
- Braspag::Converter.decimal_to_string(0.01).should == "0,01"
10
- Braspag::Converter.decimal_to_string(9.99999).should == "10,00" # round up
11
- Braspag::Converter.decimal_to_string(10.9).should == "10,90"
12
- Braspag::Converter.decimal_to_string(9.1111).should == "9,11"
6
+ Braspag::Converter.decimal_to_string(10).should eq("10,00")
7
+ Braspag::Converter.decimal_to_string(1).should eq("1,00")
8
+ Braspag::Converter.decimal_to_string(0.1).should eq("0,10")
9
+ Braspag::Converter.decimal_to_string(0.01).should eq("0,01")
10
+ Braspag::Converter.decimal_to_string(9.99999).should eq("10,00") # round up
11
+ Braspag::Converter.decimal_to_string(10.9).should eq("10,90")
12
+ Braspag::Converter.decimal_to_string(9.1111).should eq("9,11")
13
+ Braspag::Converter.decimal_to_string("10,00").should eq("10,00")
14
+ end
15
+ end
16
+
17
+ describe ".string_to_decimal" do
18
+ it "should string with comma as decimal separator to decimal" do
19
+ Braspag::Converter.string_to_decimal("1000,00").should eq(1000.00)
20
+ Braspag::Converter.string_to_decimal("1.000,00").should eq(1000.00)
21
+ Braspag::Converter.string_to_decimal("10,00").should eq(10.00)
22
+ Braspag::Converter.string_to_decimal("1,00").should eq(1.00)
23
+ Braspag::Converter.string_to_decimal("0,10").should eq(0.1)
24
+ Braspag::Converter.string_to_decimal("0,01").should eq(0.01)
25
+ Braspag::Converter.string_to_decimal("9,99").should eq(9.99)
26
+ Braspag::Converter.string_to_decimal("10,9").should eq(10.90)
27
+ Braspag::Converter.string_to_decimal("9,1111").should eq(9.1111)
13
28
  end
14
29
  end
15
30
 
16
- describe ".to_map" do
31
+ describe ".hash_from_xml" do
17
32
  let(:document) do
18
33
  <<-XML
19
34
  <root>
@@ -29,7 +44,14 @@ describe Braspag::Converter do
29
44
  keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
30
45
  expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
31
46
 
32
- Braspag::Converter::to_map(document, keys).should == expected
47
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
48
+ end
49
+
50
+ it "should return a Hash with invalid key" do
51
+ keys = { :foo => "invalid", :meu_elemento => "bar", :outro_elemento => "baz" }
52
+ expected = { :foo => nil, :meu_elemento => "bleble", :outro_elemento => nil }
53
+
54
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
33
55
  end
34
56
  end
35
57
 
@@ -40,7 +62,7 @@ describe Braspag::Converter do
40
62
  keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
41
63
  expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
42
64
 
43
- Braspag::Converter::to_map(document, keys).should == expected
65
+ Braspag::Converter::hash_from_xml(document, keys).should == expected
44
66
  end
45
67
  end
46
68
  end
@@ -81,4 +103,21 @@ describe Braspag::Converter do
81
103
  end
82
104
  end
83
105
 
106
+ describe "payment_method_type?" do
107
+ it "should response nil when invalid method" do
108
+ Braspag::Converter.payment_method_type?(999).should be(nil)
109
+ end
110
+
111
+ it "should response billet" do
112
+ Braspag::Converter.payment_method_type?(6).should be(:billet)
113
+ end
114
+
115
+ it "should response eft" do
116
+ Braspag::Converter.payment_method_type?(16).should be(:eft)
117
+ end
118
+
119
+ it "should response credit_card" do
120
+ Braspag::Converter.payment_method_type?(997).should be(:credit_card)
121
+ end
122
+ end
84
123
  end
@@ -1,24 +1,220 @@
1
1
  # encoding: utf-8
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
+ describe Braspag::Connection do
5
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
6
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
7
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
8
+
9
+ describe ".get" do
10
+ context "when error" do
11
+ it "should return message for response blank" do
12
+ connection.stub(:post).and_return({})
13
+ response = connection.get(order)
14
+
15
+ response.success?.should eq(false)
16
+ response.message.should eq('')
17
+ response.params.should eq({})
18
+ response.test.should eq(true)
19
+ end
20
+
21
+ it "should return message for error code" do
22
+ order_response = {:error_code => 'bla', :error_message => 'xpto', :status => '223'}
23
+ connection.stub(:post).and_return(order_response)
24
+ response = connection.get(order)
25
+
26
+ response.success?.should eq(false)
27
+ response.message.should eq(order_response[:error_message])
28
+ response.params.should eq({"error_code"=>"bla", "error_message"=>"xpto", "status" => '223'})
29
+ response.test.should eq(true)
30
+ end
31
+
32
+ it "should return message for empty status" do
33
+ connection.stub(:post).and_return({:error_message => 'bla'})
34
+ response = connection.get(order)
35
+
36
+ response.success?.should eq(false)
37
+ response.message.should eq('bla')
38
+ response.params.should eq({"error_message"=>"bla"})
39
+ response.test.should eq(true)
40
+ end
41
+ end
42
+
43
+ it "should return response ok" do
44
+ connection.stub(:post).and_return({:status => '1'})
45
+ response = connection.get(order)
46
+
47
+ response.success?.should eq(true)
48
+ response.message.should eq('OK')
49
+ response.params.should eq({"status" => "1"})
50
+ response.test.should eq(true)
51
+ end
52
+
53
+ it "should get more info for billet" do
54
+ connection.should_receive(:post).and_return({:status => '1'})
55
+ connection.should_receive(:post).with(:info_billet, order)
56
+ order.payment_method = 6 #BILLET BRADESCO
57
+ response = connection.get(order)
58
+
59
+ response.success?.should eq(true)
60
+ response.message.should eq('OK')
61
+ response.params.should eq({"status" => "1"})
62
+ response.test.should eq(true)
63
+ end
64
+
65
+ it "should get more info for credit_card" do
66
+ connection.should_receive(:post).and_return({:status => '1'})
67
+ connection.should_receive(:post).with(:info_credit_card, order)
68
+ order.payment_method = 18 #AMEX
69
+ response = connection.get(order)
70
+
71
+ response.success?.should eq(true)
72
+ response.message.should eq('OK')
73
+ response.params.should eq({"status" => "1"})
74
+ response.test.should eq(true)
75
+ end
76
+ end
77
+ end
78
+
4
79
  describe Braspag::Order do
5
- let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
6
- let(:braspag_production_url) { "https://transaction.pagador.com.br" }
7
- let(:merchant_id) { "um id qualquer" }
80
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
81
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
82
+
83
+ describe ".payment_method_type?" do
84
+ it "should return payment method type" do
85
+ order = subject
86
+ order.payment_method = 6
87
+ order.payment_method_type?.should eq(:billet)
88
+ end
89
+ end
8
90
 
9
-
10
- pending ".info_billet" do
11
- let(:info_url) { "http://braspag/bla" }
91
+ context "on info" do
92
+ let(:valid_xml) do
93
+ <<-EOXML
94
+ <?xml version="1.0" encoding="utf-8"?>
95
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
96
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
97
+ xmlns="http://www.pagador.com.br/">
98
+ <CodigoAutorizacao>885796</CodigoAutorizacao>
99
+ <CodigoPagamento>18</CodigoPagamento>
100
+ <FormaPagamento>American Express 2P</FormaPagamento>
101
+ <NumeroParcelas>1</NumeroParcelas>
102
+ <Status>3</Status>
103
+ <Valor>0.01</Valor>
104
+ <DataCancelamento>7/8/2011 1:19:38 PM</DataCancelamento>
105
+ <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
106
+ <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
107
+ <TransId>398591</TransId>
108
+ <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
109
+ </DadosPedido>
110
+ EOXML
111
+ end
112
+
12
113
  let(:invalid_xml) do
13
114
  <<-EOXML
14
115
  <?xml version="1.0" encoding="utf-8"?>
15
- <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
116
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16
117
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
17
118
  xsi:nil="true"
18
119
  xmlns="http://www.pagador.com.br/" />
19
120
  EOXML
20
121
  end
21
-
122
+
123
+ let(:error_xml) do
124
+ <<-EOXML
125
+ <?xml version="1.0" encoding="utf-8"?>
126
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
127
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
128
+ xmlns="http://www.pagador.com.br/">
129
+ <CodigoErro>885796</CodigoErro>
130
+ <MensagemErro>Deu um erro terrivel</MensagemErro>
131
+ </DadosPedido>
132
+ EOXML
133
+ end
134
+
135
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
136
+
137
+ it "should convert objects to hash" do
138
+ Braspag::Order.to_info(connection, order).should eq({
139
+ "loja" => "#{merchant_id}",
140
+ "numeroPedido" => "#{order.id}"
141
+ })
142
+ end
143
+
144
+ it "should populate data" do
145
+ resp = Braspag::Order.from_info(connection, order, mock(:body => valid_xml))
146
+
147
+ order.authorization.should eq('885796')
148
+ order.payment_method_name.should eq('American Express 2P')
149
+ order.payment_method.should eq('18')
150
+ order.installments.should eq('1')
151
+ order.status.should eq('3')
152
+ order.amount.should eq(0.01)
153
+ order.gateway_cancelled_at.should eq(Time.parse('2011-08-07 13:19:38 -0300'))
154
+ order.gateway_paid_at.should eq(Time.parse('2011-08-07 13:19:38 -0300'))
155
+ order.gateway_created_at.should eq(Time.parse('2011-08-07 13:06:06 -0300'))
156
+ order.transaction_id.should eq('398591')
157
+ order.gateway_id.should eq('5a1d4463-1d11-4571-a877-763aba0ef7ff')
158
+
159
+ resp.should eq({
160
+ :authorization => "885796",
161
+ :error_code => nil,
162
+ :error_message => nil,
163
+ :payment_method => "18",
164
+ :payment_method_name => "American Express 2P",
165
+ :installments => "1",
166
+ :status => "3",
167
+ :amount => "0.01",
168
+ :cancelled_at => Time.parse('2011-08-07 13:19:38 -0300'),
169
+ :paid_at => Time.parse('2011-08-07 13:19:38 -0300'),
170
+ :order_date => Time.parse('2011-08-07 13:06:06 -0300'),
171
+ :transaction_id => "398591",
172
+ :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
173
+ })
174
+ end
175
+
176
+ it "should populate data accepts invalid xml" do
177
+ resp = Braspag::Order.from_info(connection, order, mock(:body => invalid_xml))
178
+
179
+ resp.should eq({
180
+ :authorization => nil,
181
+ :error_code => nil,
182
+ :error_message => nil,
183
+ :payment_method => nil,
184
+ :payment_method_name => nil,
185
+ :installments => nil,
186
+ :status => nil,
187
+ :amount => nil,
188
+ :cancelled_at => nil,
189
+ :paid_at => nil,
190
+ :order_date => nil,
191
+ :transaction_id => nil,
192
+ :tid => nil
193
+ })
194
+ end
195
+
196
+ it "should populate data for error" do
197
+ resp = Braspag::Order.from_info(connection, order, mock(:body => error_xml))
198
+
199
+ resp.should eq({
200
+ :authorization => nil,
201
+ :error_code => "885796",
202
+ :error_message => "Deu um erro terrivel",
203
+ :payment_method => nil,
204
+ :payment_method_name => nil,
205
+ :installments => nil,
206
+ :status => nil,
207
+ :amount => nil,
208
+ :cancelled_at => nil,
209
+ :paid_at => nil,
210
+ :order_date => nil,
211
+ :transaction_id => nil,
212
+ :tid => nil
213
+ })
214
+ end
215
+ end
216
+
217
+ context "on info for billet" do
22
218
  let(:valid_xml) do
23
219
  <<-EOXML
24
220
  <?xml version="1.0" encoding="utf-8"?>
@@ -26,92 +222,112 @@ describe Braspag::Order do
26
222
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
27
223
  xmlns="http://www.pagador.com.br/">
28
224
  <NumeroDocumento>999</NumeroDocumento>
29
- <Sacado/>
225
+ <Sacado>XPTO</Sacado>
30
226
  <NossoNumero>999</NossoNumero>
31
227
  <LinhaDigitavel>35690.00361 03962.070003 00000.009993 4 50160000001000</LinhaDigitavel>
32
228
  <DataDocumento>22/6/2011</DataDocumento>
33
229
  <DataVencimento>2/7/2011</DataVencimento>
34
- <Cedente>Gonow Tecnologia e Acessoria Empresarial Ltda</Cedente>
230
+ <DataCredito>2/7/2011</DataCredito>
231
+ <Cedente>Acessoria Empresarial Ltda</Cedente>
35
232
  <Banco>356-5</Banco>
36
233
  <Agencia>0003</Agencia>
37
234
  <Conta>6039620</Conta>
38
235
  <Carteira>57</Carteira>
39
236
  <ValorDocumento>10,00</ValorDocumento>
237
+ <ValorPago>10,00</ValorPago>
40
238
  </DadosBoleto>
41
239
  EOXML
42
240
  end
43
-
44
- it "should raise an error when order id is not valid" do
45
- Braspag::Bill.should_receive(:valid_order_id?)
46
- .with("bla")
47
- .and_return(false)
48
-
49
- expect {
50
- Braspag::Bill.info "bla"
51
- }.to raise_error(Braspag::InvalidOrderId)
241
+
242
+ let(:invalid_xml) do
243
+ <<-EOXML
244
+ <?xml version="1.0" encoding="utf-8"?>
245
+ <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
247
+ xmlns="http://www.pagador.com.br/">
248
+ </DadosBoleto>
249
+ EOXML
52
250
  end
53
-
54
- it "should raise an error when Braspag returned an invalid xml as response" do
55
- FakeWeb.register_uri(:post, info_url, :body => invalid_xml)
56
-
57
- Braspag::Bill.should_receive(:info_url)
58
- .and_return(info_url)
59
-
60
- expect {
61
- Braspag::Bill.info("orderid")
62
- }.to raise_error(Braspag::UnknownError)
251
+
252
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
253
+
254
+ it "should convert objects to hash" do
255
+ Braspag::Order.to_info_billet(connection, order).should eq({
256
+ "loja" => "#{merchant_id}",
257
+ "numeroPedido" => "#{order.id}"
258
+ })
63
259
  end
260
+
261
+ it "should populate data" do
262
+ resp = Braspag::Order.from_info_billet(connection, order, mock(:body => valid_xml))
64
263
 
65
- it "should return a Hash when Braspag returned a valid xml as response" do
66
- FakeWeb.register_uri(:post, info_url, :body => valid_xml)
67
-
68
- Braspag::Bill.should_receive(:info_url)
69
- .and_return(info_url)
264
+ order.customer.name.should eq('XPTO')
70
265
 
71
- response = Braspag::Bill.info("orderid")
72
- response.should be_kind_of Hash
266
+ order.billet.id.should eq('999')
267
+ order.billet.code.should eq('35690.00361 03962.070003 00000.009993 4 50160000001000')
268
+
269
+ order.billet.created_at.should eq(Date.parse('2011-06-22'))
270
+ order.billet.due_date_on.should eq(Date.parse('2011-07-2'))
271
+
272
+ order.billet.receiver.should eq('Acessoria Empresarial Ltda')
273
+
274
+ order.billet.bank.should eq('356-5')
275
+ order.billet.agency.should eq('0003')
276
+ order.billet.account.should eq('6039620')
277
+ order.billet.wallet.should eq('57')
278
+ order.billet.amount.should eq(10.00)
279
+ order.billet.amount_paid.should eq(10.00)
280
+ order.billet.paid_at.should eq(Date.parse('2011-07-02'))
281
+
282
+ resp.should eq({
283
+ :document_number=>"999",
284
+ :payer=>"XPTO",
285
+ :our_number=>"999",
286
+ :bill_line=>"35690.00361 03962.070003 00000.009993 4 50160000001000",
287
+ :document_date=>Date.parse('2011-06-22'),
288
+ :expiration_date=>Date.parse('2011-07-2'),
289
+ :receiver=>"Acessoria Empresarial Ltda",
290
+ :bank=>"356-5",
291
+ :agency=>"0003",
292
+ :account=>"6039620",
293
+ :wallet=>"57",
294
+ :amount=>"10,00",
295
+ :amount_invoice=>"10,00",
296
+ :invoice_date=> Date.parse('2011-07-02')
297
+ })
298
+ end
299
+
300
+ it "should not raise error for invalid xml" do
301
+ resp = Braspag::Order.from_info_billet(connection, order, mock(:body => invalid_xml))
73
302
 
74
- response.should == {
75
- :document_number => "999",
303
+ resp.should eq({
304
+ :document_number => nil,
76
305
  :payer => nil,
77
- :our_number => "999",
78
- :bill_line => "35690.00361 03962.070003 00000.009993 4 50160000001000",
79
- :document_date => "22/6/2011",
80
- :expiration_date => "2/7/2011",
81
- :receiver => "Gonow Tecnologia e Acessoria Empresarial Ltda",
82
- :bank => "356-5",
83
- :agency => "0003",
84
- :account => "6039620",
85
- :wallet => "57",
86
- :amount => "10,00",
87
- :amount_invoice => nil,
88
- :invoice_date => nil
89
- }
306
+ :our_number => nil,
307
+ :bill_line => nil,
308
+ :document_date => nil,
309
+ :expiration_date => nil,
310
+ :receiver => nil,
311
+ :bank=> nil,
312
+ :agency=> nil,
313
+ :account=> nil,
314
+ :wallet=> nil,
315
+ :amount=> nil,
316
+ :amount_invoice=> nil,
317
+ :invoice_date=> nil
318
+ })
90
319
  end
91
320
  end
92
-
93
- pending ".info" do
94
- let(:info_url) { "http://braspag/bla" }
95
-
96
- let(:invalid_xml) do
97
- <<-EOXML
98
- <DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
100
- xmlns="http://www.pagador.com.br/">
101
- <NumeroComprovante></NumeroComprovante>
102
- <Autenticada>false</Autenticada>
103
- <NumeroAutorizacao>557593</NumeroAutorizacao>
104
- <NumeroCartao>345678*****0007</NumeroCartao>
105
- <NumeroTransacao>101001225645</NumeroTransacao>
106
- </DadosCartao>
107
- EOXML
108
- end
109
321
 
322
+ context "on info for credit card" do
110
323
  let(:valid_xml) do
111
324
  <<-EOXML
112
325
  <DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
113
326
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
114
327
  xmlns="http://www.pagador.com.br/">
328
+ <RetornoAVS>12</RetornoAVS>
329
+ <Emissor>VISA</Emissor>
330
+ <NumeroAutenticacao>12345</NumeroAutenticacao>
115
331
  <NumeroComprovante>11111</NumeroComprovante>
116
332
  <Autenticada>false</Autenticada>
117
333
  <NumeroAutorizacao>557593</NumeroAutorizacao>
@@ -120,134 +336,40 @@ describe Braspag::Order do
120
336
  </DadosCartao>
121
337
  EOXML
122
338
  end
123
-
124
- it "should raise an error when order id is not valid" do
125
- Braspag::CreditCard.should_receive(:valid_order_id?)
126
- .with("bla")
127
- .and_return(false)
128
-
129
- expect {
130
- Braspag::CreditCard.info "bla"
131
- }.to raise_error(Braspag::InvalidOrderId)
132
- end
133
-
134
- it "should raise an error when Braspag returned an invalid xml as response" do
135
- FakeWeb.register_uri(:post, info_url, :body => invalid_xml)
136
-
137
- Braspag::CreditCard.should_receive(:info_url)
138
- .and_return(info_url)
139
-
140
- expect {
141
- Braspag::CreditCard.info("orderid")
142
- }.to raise_error(Braspag::UnknownError)
143
- end
144
-
145
- it "should return a Hash when Braspag returned a valid xml as response" do
146
- FakeWeb.register_uri(:post, info_url, :body => valid_xml)
147
-
148
- Braspag::CreditCard.should_receive(:info_url)
149
- .and_return(info_url)
150
-
151
- response = Braspag::CreditCard.info("orderid")
152
- response.should be_kind_of Hash
153
-
154
- response.should == {
155
- :checking_number => "11111",
156
- :certified => "false",
157
- :autorization_number => "557593",
158
- :card_number => "345678*****0007",
159
- :transaction_number => "101001225645"
160
- }
161
- end
162
- end
163
-
164
- pending ".status" do
165
- let(:order_id) { "um order id qualquer" }
166
- let(:status_url) { "http://foo.com/bar/baz/assererre" }
167
-
168
- context "with invalid order id" do
169
- let(:invalid_xml) do
170
- <<-EOXML
171
- <?xml version="1.0" encoding="utf-8"?>
172
- <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
173
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
174
- xsi:nil="true"
175
- xmlns="http://www.pagador.com.br/" />
176
- EOXML
177
- end
178
-
179
- it "should raise an error when order id is not valid" do
180
- Braspag::PaymentMethod.should_receive(:valid_order_id?)
181
- .with(order_id)
182
- .and_return(false)
183
-
184
- expect {
185
- Braspag::Order.status(order_id)
186
- }.to raise_error(Braspag::InvalidOrderId)
187
- end
188
-
189
- it "should raise an error when Braspag returns an invalid xml" do
190
- FakeWeb.register_uri(:post, status_url, :body => invalid_xml)
191
-
192
- Braspag::Order.should_receive(:status_url)
193
- .and_return(status_url)
194
-
195
- expect {
196
- Braspag::Order.status(order_id)
197
- }.to raise_error(Braspag::Order::InvalidData)
198
- end
339
+
340
+ let(:order) { Braspag::Order.new(:id => "XPTO") }
341
+
342
+ it "should convert objects to hash" do
343
+ Braspag::Order.to_info_credit_card(connection, order).should eq({
344
+ "loja" => "#{merchant_id}",
345
+ "numeroPedido" => "#{order.id}"
346
+ })
199
347
  end
200
-
201
- context "with valid order id" do
202
- let(:valid_xml) do
203
- <<-EOXML
204
- <?xml version="1.0" encoding="utf-8"?>
205
- <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
206
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
207
- xmlns="http://www.pagador.com.br/">
208
- <CodigoAutorizacao>885796</CodigoAutorizacao>
209
- <CodigoPagamento>18</CodigoPagamento>
210
- <FormaPagamento>American Express 2P</FormaPagamento>
211
- <NumeroParcelas>1</NumeroParcelas>
212
- <Status>3</Status>
213
- <Valor>0.01</Valor>
214
- <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
215
- <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
216
- <TransId>398591</TransId>
217
- <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
218
- </DadosPedido>
219
- EOXML
220
- end
221
-
222
- before do
223
- Braspag::Order.should_receive(:status_url)
224
- .and_return(status_url)
225
-
226
- FakeWeb.register_uri(:post, status_url, :body => valid_xml)
227
- @response = Braspag::Order.status(order_id)
228
- end
229
-
230
- it "should return a Hash" do
231
- @response.should be_kind_of Hash
232
- @response.should == {
233
- :authorization => "885796",
234
- :error_code => nil,
235
- :error_message => nil,
236
- :payment_method => "18",
237
- :payment_method_name => "American Express 2P",
238
- :installments => "1",
239
- :status => "3",
240
- :amount => "0.01",
241
- :cancelled_at => nil,
242
- :paid_at => "7/8/2011 1:19:38 PM",
243
- :order_date => "7/8/2011 1:06:06 PM",
244
- :transaction_id => "398591",
245
- :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
246
- }
247
- end
348
+
349
+ it "should populate data" do
350
+ resp = Braspag::Order.from_info_credit_card(connection, order, mock(:body => valid_xml))
351
+
352
+ order.credit_card.checking_number.should eq('11111')
353
+ order.credit_card.avs.should eq('false')
354
+ order.credit_card.autorization_number.should eq('557593')
355
+ order.credit_card.number.should eq('345678*****0007')
356
+ order.credit_card.transaction_number.should eq('101001225645')
357
+ order.credit_card.avs_response.should eq('12')
358
+ order.credit_card.issuing.should eq('VISA')
359
+ order.credit_card.authenticated_number.should eq('12345')
360
+
361
+ resp.should eq({
362
+ :checking_number => "11111",
363
+ :certified => "false",
364
+ :autorization_number => "557593",
365
+ :card_number => "345678*****0007",
366
+ :transaction_number => "101001225645",
367
+ :avs_response => "12",
368
+ :issuing => "VISA",
369
+ :authenticated_number => "12345"
370
+ })
248
371
  end
249
372
  end
250
-
251
373
 
252
374
  [:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |context_type|
253
375
  context "on #{context_type}" do