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
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe Braspag::Connection do
5
+ it "should generate a billet", :billet_integration => true do
6
+ gateway = Braspag::Connection.new(
7
+ :merchant_id => ENV['BRASPAG_MERCHANT_ID'],
8
+ :environment => :homologation
9
+ )
10
+
11
+ billet = Braspag::Billet.new(
12
+ :instructions => 'does not accepted after due date', # (optional)
13
+ :due_date_on => Date.today + 2
14
+ )
15
+
16
+ customer = Braspag::Customer.new(
17
+ :document => '21473696240', # (OPTIONAL)
18
+ :name => 'Bob Dela Bobsen',
19
+ :email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
20
+ )
21
+
22
+ order = Braspag::Order.new(
23
+ :payment_method => Braspag::PAYMENT_METHOD[:billet_santader],
24
+ :id => 11,
25
+ :amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
26
+ :customer => customer
27
+ )
28
+
29
+ # Validating the card automatically detects the card type
30
+ if billet.valid?(:generate) && customer.valid?(:generate) && order.valid?(:generate)
31
+ response = gateway.generate_billet(order, billet)
32
+ response.success?.should eq(true)
33
+ puts "Successfully created billet, open in:#{billet.url}"
34
+ else
35
+ fail "Invalid Params"
36
+ end
37
+ end
38
+ end
File without changes
@@ -6,6 +6,89 @@ describe Braspag::Connection do
6
6
  let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
7
7
 
8
8
  context ".generate_billet" do
9
+ it "should return response" do
10
+ generate_billet = {
11
+ :status => "1",
12
+ :message => "BLA",
13
+ :number => "12345"
14
+ }
15
+
16
+ connection.should_receive(:post).and_return(generate_billet)
17
+
18
+ response = connection.generate_billet(mock, mock)
19
+
20
+ response.success?.should eq(false)
21
+ response.message.should eq(generate_billet[:message])
22
+ response.authorization.should eq(generate_billet[:number])
23
+ response.params.should eq({"status"=>"1", "message"=>"BLA", "number"=>"12345"})
24
+ response.test.should eq(true)
25
+ end
26
+
27
+ it "should return success when status is zero" do
28
+ generate_billet = {
29
+ :status => "0",
30
+ :message => "BLA",
31
+ :number => "12345"
32
+ }
33
+
34
+ connection.should_receive(:post).and_return(generate_billet)
35
+
36
+ response = connection.generate_billet(mock, mock)
37
+
38
+ response.success?.should eq(true)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe Braspag::Billet do
44
+ context "on generate" do
45
+ it "should allow blank for id" do
46
+ subject.id = ''
47
+ subject.valid?(:generate)
48
+ subject.errors.messages[:id].should be(nil)
49
+ end
50
+
51
+ it "should validate maximum 255 length of id" do
52
+ subject.id = '*' * 260
53
+ subject.valid?(:generate)
54
+ subject.errors.messages[:id].should include("is too long (maximum is 255 characters)")
55
+ end
56
+
57
+ it "should allow blank for instructions" do
58
+ subject.instructions = ''
59
+ subject.valid?(:generate)
60
+ subject.errors.messages[:instructions].should be(nil)
61
+ end
62
+
63
+ it "should validate maximum 512 length of instructions" do
64
+ subject.instructions = '*' * 520
65
+ subject.valid?(:generate)
66
+ subject.errors.messages[:instructions].should include("is too long (maximum is 512 characters)")
67
+ end
68
+
69
+ it "should not allow blank for due_date_on" do
70
+ subject.due_date_on = ''
71
+ subject.valid?(:generate)
72
+ subject.errors.messages[:due_date_on].should include("can't be blank")
73
+ end
74
+
75
+ it "should not allow invalid date for due_date_on" do
76
+ subject.due_date_on = '12345'
77
+ subject.valid?(:generate)
78
+ subject.errors.messages[:due_date_on].should include("invalid date")
79
+ end
80
+
81
+ it "should allow date for due_date_on" do
82
+ subject.due_date_on = Date.parse('07/03/1988')
83
+ subject.valid?(:generate)
84
+ subject.errors.messages[:due_date_on].should be(nil)
85
+ end
86
+ end
87
+
88
+ context "on generate billet" do
89
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
90
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
91
+
9
92
  let(:customer) do
10
93
  Braspag::Customer.new(
11
94
  :document => '21473696240', # (OPTIONAL)
@@ -13,7 +96,7 @@ describe Braspag::Connection do
13
96
  :email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
14
97
  )
15
98
  end
16
-
99
+
17
100
  let(:order) do
18
101
  Braspag::Order.new(
19
102
  :id => "um order id",
@@ -22,7 +105,7 @@ describe Braspag::Connection do
22
105
  :customer => customer
23
106
  )
24
107
  end
25
-
108
+
26
109
  let(:billet) do
27
110
  Braspag::Billet.new(
28
111
  :id => '123456',
@@ -31,6 +114,8 @@ describe Braspag::Connection do
31
114
  )
32
115
  end
33
116
 
117
+ let(:url) { "https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=722934be-6756-477a-87ab-42115ee1424d" }
118
+
34
119
  let(:valid_xml) do
35
120
  <<-EOXML
36
121
  <?xml version="1.0" encoding="utf-8"?>
@@ -62,94 +147,58 @@ describe Braspag::Connection do
62
147
  EOXML
63
148
  end
64
149
 
65
-
66
- it "should call gateway with correct data" do
67
- Braspag::Poster.any_instance.should_receive(:do_post).with(:generate_billet, {
68
- "merchantId" => "#{merchant_id}",
69
- "orderId" => "#{order.id}",
70
- "customerName" => "#{customer.name}",
71
- "customerIdNumber" => "#{customer.document}",
72
- "amount" => "100,00",
73
- "paymentMethod" => 6,
74
- "boletoNumber" => "#{billet.id}",
75
- "expirationDate" => "01/01/12",
76
- "instructions" => "#{billet.instructions}",
77
- "emails" => "#{customer.email}"
78
- }
79
- ).and_return(mock(:body => valid_xml))
80
- connection.generate_billet(order, billet)
150
+ it "should convert objects to hash" do
151
+ Braspag::Billet.to_generate_billet(connection, order, billet).should eq({
152
+ "merchantId" => connection.merchant_id,
153
+ "boletoNumber" => billet.id.to_s,
154
+ "instructions" => billet.instructions.to_s,
155
+ "expirationDate" => billet.due_date_on.strftime("%d/%m/%y"),
156
+ "customerName" => order.customer.name.to_s,
157
+ "customerIdNumber" => order.customer.document.to_s,
158
+ "emails" => order.customer.email.to_s,
159
+ "orderId" => order.id.to_s,
160
+ "amount" => Braspag::Converter::decimal_to_string(order.amount),
161
+ "paymentMethod" => order.payment_method
162
+ })
81
163
  end
82
164
 
83
- it "should populate data" do
84
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
85
- connection.generate_billet(order, billet)
86
-
87
- billet.url.should eq('https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=722934be-6756-477a-87ab-42115ee1424d')
165
+
166
+ it "should convert response from xml" do
167
+ resp = Braspag::Billet.from_generate_billet(connection, order, billet, mock(:body => valid_xml))
168
+
169
+ billet.url.should eq(url)
88
170
  order.gateway_return_code.should eq('0')
89
171
  order.gateway_status.should eq('0')
90
172
  order.gateway_amount.should eq(3.00)
173
+
174
+ resp.should eq({
175
+ :url => url,
176
+ :amount => "3.00",
177
+ :number => "123123",
178
+ :expiration_date => Date.parse('2012-01-08'),
179
+ :return_code => "0",
180
+ :status => "0",
181
+ :message => nil
182
+ })
91
183
  end
92
184
 
93
- it "should return response object" do
94
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
95
- response = connection.generate_billet(order, billet)
185
+ it "should convert response from xml with invalid date" do
186
+ resp = Braspag::Billet.from_generate_billet(connection, order, billet, mock(:body => invalid_xml))
96
187
 
97
- response.success?.should be(true)
98
- end
99
-
100
- it "should return error in response" do
101
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => invalid_xml))
102
- response = connection.generate_billet(order, billet)
188
+ billet.url.should eq(nil)
189
+ order.gateway_return_code.should eq('1')
190
+ order.gateway_status.should eq(nil)
191
+ order.gateway_amount.should eq(nil)
103
192
 
104
- response.success?.should be(false)
105
- response.message.should eq('Invalid merchantId')
106
- response.params.should eq({"url"=>nil, "amount"=>nil, "number"=>nil, "expiration_date"=>nil, "return_code"=>"1", "status"=>nil, "message"=>"Invalid merchantId"})
107
- end
108
- end
109
- end
110
-
111
- describe Braspag::Billet do
112
- context "on generate" do
113
- it "should allow blank for id" do
114
- subject.id = ''
115
- subject.valid?(:generate)
116
- subject.errors.messages[:id].should be(nil)
117
- end
118
-
119
- it "should validate maximum 255 length of id" do
120
- subject.id = '*' * 260
121
- subject.valid?(:generate)
122
- subject.errors.messages[:id].should include("is too long (maximum is 255 characters)")
123
- end
124
-
125
- it "should allow blank for instructions" do
126
- subject.instructions = ''
127
- subject.valid?(:generate)
128
- subject.errors.messages[:instructions].should be(nil)
129
- end
130
-
131
- it "should validate maximum 512 length of instructions" do
132
- subject.instructions = '*' * 520
133
- subject.valid?(:generate)
134
- subject.errors.messages[:instructions].should include("is too long (maximum is 512 characters)")
135
- end
136
-
137
- it "should not allow blank for due_date_on" do
138
- subject.due_date_on = ''
139
- subject.valid?(:generate)
140
- subject.errors.messages[:due_date_on].should include("can't be blank")
141
- end
142
-
143
- it "should not allow invalid date for due_date_on" do
144
- subject.due_date_on = '12345'
145
- subject.valid?(:generate)
146
- subject.errors.messages[:due_date_on].should include("invalid date")
147
- end
148
-
149
- it "should allow date for due_date_on" do
150
- subject.due_date_on = Date.parse('07/03/1988')
151
- subject.valid?(:generate)
152
- subject.errors.messages[:due_date_on].should be(nil)
193
+ resp.should eq({
194
+ :url => nil,
195
+ :amount => nil,
196
+ :number => nil,
197
+ :expiration_date => nil,
198
+ :return_code => "1",
199
+ :status => nil,
200
+ :message => "Invalid merchantId"
201
+ })
153
202
  end
154
203
  end
155
204
  end
@@ -4,518 +4,131 @@ describe Braspag::Connection do
4
4
  let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
5
5
  let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
6
6
 
7
- context ".authorize" do
8
- let(:customer) do
9
- Braspag::Customer.new(:name => "W" * 21)
10
- end
11
-
12
- let(:order) do
13
- Braspag::Order.new(
14
- :id => "um order id",
15
- :amount => 1000.00,
16
- :payment_method => Braspag::PAYMENT_METHOD[:redecard],
17
- :installments => 1,
18
- :installments_type => Braspag::INTEREST[:no],
19
- :customer => customer
20
- )
21
- end
22
-
23
- let(:credit_card) do
24
- Braspag::CreditCard.new(
25
- :holder_name => "Joao Maria Souza",
26
- :number => "9" * 10,
27
- :month => "10",
28
- :year => "12",
29
- :verification_value => "123"
30
- )
7
+ context ".purchase" do
8
+ it "should return authorize when authroize response failed" do
9
+ auth = mock(:success? => false)
10
+ connection.stub(:authorize).and_return(auth)
11
+ connection.purchase(mock, mock).should eq(auth)
31
12
  end
32
13
 
33
- let(:valid_xml) do
34
- <<-EOXML
35
- <?xml version="1.0" encoding="utf-8"?>
36
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
38
- xmlns="https://www.pagador.com.br/webservice/pagador">
39
- <amount>1.000,00</amount>
40
- <message>Transaction Successful</message>
41
- <authorisationNumber>733610</authorisationNumber>
42
- <returnCode>0</returnCode>
43
- <status>1</status>
44
- <transactionId>01231234</transactionId>
45
- </PagadorReturn>
46
- EOXML
14
+ it "should return capture when authorize response success" do
15
+ cap = mock(:success? => true)
16
+ connection.stub(:authorize).and_return(mock(:success? => true))
17
+ connection.stub(:capture).and_return(cap)
18
+ connection.purchase(mock, mock).should eq(cap)
47
19
  end
48
-
49
- let(:invalid_xml) do
50
- <<-EOXML
51
- <?xml version="1.0" encoding="utf-8"?>
52
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
54
- xmlns="https://www.pagador.com.br/webservice/pagador">
55
- <amount>100</amount>
56
- <authorisationNumber>null</authorisationNumber>
57
- <message>Payment Server detected an error</message>
58
- <returnCode>7</returnCode>
59
- <status>2</status>
60
- <transactionId>0</transactionId>
61
- </PagadorReturn>
62
- EOXML
63
- end
64
-
65
-
66
- it "should call gateway with correct data" do
67
- Braspag::Poster.any_instance.should_receive(:do_post).with(:authorize, {
68
- "merchantId" => "#{merchant_id}",
69
- "orderId" => "#{order.id}",
70
- "customerName" => "#{customer.name}",
71
- "amount" => "1000,00",
72
- "paymentMethod" => 20,
73
- "holder" => "#{credit_card.holder_name}",
74
- "cardNumber" => "#{credit_card.number}",
75
- "expiration" => "10/12",
76
- "securityCode" => "123",
77
- "numberPayments" => order.installments,
78
- "typePayment" => order.installments_type
79
- }
80
- ).and_return(mock(:body => valid_xml))
81
- connection.authorize(order, credit_card)
82
- end
83
-
84
- it "should populate data" do
85
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
86
- connection.authorize(order, credit_card)
20
+ end
21
+
22
+ context ".authorize" do
23
+ it "should return response" do
24
+ authorize = {
25
+ :status => "2",
26
+ :message => "BLA",
27
+ :number => "12345"
28
+ }
87
29
 
88
- order.gateway_authorization.should eq('733610')
89
- order.gateway_id.should eq('01231234')
90
- order.gateway_return_code.should eq('0')
91
- order.gateway_status.should eq('1')
92
- order.gateway_message.should eq('Transaction Successful')
93
- order.gateway_amount.should eq(1000.00)
30
+ connection.should_receive(:post).and_return(authorize)
31
+
32
+ response = connection.authorize(mock, mock)
33
+
34
+ response.success?.should eq(false)
35
+ response.message.should eq(authorize[:message])
36
+ response.authorization.should eq(authorize[:number])
37
+ response.params.should eq({"status"=>"2", "message"=>"BLA", "number"=>"12345"})
38
+ response.test.should eq(true)
39
+ end
40
+
41
+ it "should return success when status is zero" do
42
+ authorize = {
43
+ :status => "0",
44
+ :message => "BLA",
45
+ :number => "12345"
46
+ }
47
+
48
+ connection.should_receive(:post).and_return(authorize)
49
+
50
+ response = connection.authorize(mock, mock)
51
+
52
+ response.success?.should eq(true)
94
53
  end
95
54
 
96
- it "should return response object" do
97
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
98
- response = connection.authorize(order, credit_card)
55
+ it "should return success when status is one" do
56
+ authorize = {
57
+ :status => "1",
58
+ :message => "BLA",
59
+ :number => "12345"
60
+ }
99
61
 
100
- response.success?.should be(true)
101
- response.message.should eq('Transaction Successful')
102
- end
103
-
104
- it "should return error in response" do
105
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => invalid_xml))
106
- response = connection.authorize(order, credit_card)
62
+ connection.should_receive(:post).and_return(authorize)
63
+
64
+ response = connection.authorize(mock, mock)
107
65
 
108
- response.success?.should be(false)
109
- response.message.should eq('Payment Server detected an error')
110
- response.params.should eq({"amount"=>"100", "number"=>"null", "message"=>"Payment Server detected an error", "return_code"=>"7", "status"=>"2", "transaction_id"=>"0"})
66
+ response.success?.should eq(true)
111
67
  end
112
68
  end
113
69
 
114
70
  context ".capture" do
115
- let(:order) do
116
- Braspag::Order.new(
117
- :id => "um order id"
118
- )
119
- end
120
-
121
- let(:valid_xml) do
122
- <<-EOXML
123
- <?xml version="1.0" encoding="utf-8"?>
124
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
125
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
126
- xmlns="https://www.pagador.com.br/webservice/pagador">
127
- <amount>2</amount>
128
- <message>Approved</message>
129
- <returnCode>0</returnCode>
130
- <status>0</status>
131
- </PagadorReturn>
132
- EOXML
133
- end
134
-
135
- let(:invalid_xml) do
136
- <<-EOXML
137
- <?xml version="1.0" encoding="utf-8"?>
138
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
139
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
140
- xmlns="https://www.pagador.com.br/webservice/pagador">
141
- <amount>100</amount>
142
- <message>Payment Server detected an error</message>
143
- <returnCode>7</returnCode>
144
- <status>2</status>
145
- <transactionId>0</transactionId>
146
- </PagadorReturn>
147
- EOXML
148
- end
149
-
150
-
151
- it "should call gateway with correct data" do
152
- Braspag::Poster.any_instance.should_receive(:do_post).with(:capture, {
153
- "merchantId" => "#{merchant_id}",
154
- "orderId" => "#{order.id}"
155
- }
156
- ).and_return(mock(:body => valid_xml))
157
- connection.capture(order)
158
- end
159
-
160
- it "should populate data" do
161
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
162
- connection.capture(order)
71
+ it "should return response" do
72
+ capture = {
73
+ :status => "1",
74
+ :message => "BLA",
75
+ :number => "12345"
76
+ }
163
77
 
164
- order.gateway_capture_return_code.should eq('0')
165
- order.gateway_capture_status.should eq('0')
166
- order.gateway_capture_message.should eq('Approved')
167
- order.gateway_capture_amount.should eq(2.00)
168
- end
169
-
170
- it "should return response object" do
171
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
172
- response = connection.capture(order)
78
+ connection.should_receive(:post).and_return(capture)
173
79
 
174
- response.success?.should be(true)
175
- response.message.should eq('Approved')
176
- end
177
-
178
- it "should return error in response" do
179
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => invalid_xml))
180
- response = connection.capture(order)
80
+ response = connection.capture(mock)
181
81
 
182
- response.success?.should be(false)
183
- response.message.should eq('Payment Server detected an error')
184
- response.params.should eq({"amount"=>"100", "message"=>"Payment Server detected an error", "return_code"=>"7", "status"=>"2", "transaction_id"=>"0"})
82
+ response.success?.should eq(false)
83
+ response.message.should eq(capture[:message])
84
+ response.authorization.should eq(capture[:number])
85
+ response.params.should eq({"status"=>"1", "message"=>"BLA", "number"=>"12345"})
86
+ response.test.should eq(true)
87
+ end
88
+
89
+ it "should return success when status is zero" do
90
+ capture = {
91
+ :status => "0",
92
+ :message => "BLA",
93
+ :number => "12345"
94
+ }
95
+
96
+ connection.should_receive(:post).and_return(capture)
97
+
98
+ response = connection.capture(mock)
99
+
100
+ response.success?.should eq(true)
185
101
  end
186
102
  end
187
103
 
188
104
  context ".void" do
189
- let(:order) do
190
- Braspag::Order.new(
191
- :id => "um order id"
192
- )
193
- end
194
-
195
- let(:valid_xml) do
196
- <<-EOXML
197
- <?xml version="1.0" encoding="utf-8"?>
198
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
199
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
200
- xmlns="https://www.pagador.com.br/webservice/pagador">
201
- <orderId>1234</orderId>
202
- <transactionId>0</transactionId>
203
- <amount>100</amount>
204
- <message>Approved</message>
205
- <returnCode>0</returnCode>
206
- <status>0</status>
207
- </PagadorReturn>
208
- EOXML
209
- end
210
-
211
- let(:invalid_xml) do
212
- <<-EOXML
213
- <?xml version="1.0" encoding="utf-8"?>
214
- <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
215
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
216
- xmlns="https://www.pagador.com.br/webservice/pagador">
217
- <orderId>1234</orderId>
218
- <amount>100</amount>
219
- <message>Payment Server detected an error</message>
220
- <returnCode>7</returnCode>
221
- <status>2</status>
222
- <transactionId>0</transactionId>
223
- </PagadorReturn>
224
- EOXML
225
- end
226
-
227
-
228
- it "should call gateway with correct data" do
229
- Braspag::Poster.any_instance.should_receive(:do_post).with(:void, {
230
- "merchantId" => "#{merchant_id}",
231
- "orderId" => "#{order.id}"
232
- }
233
- ).and_return(mock(:body => valid_xml))
234
- connection.void(order)
235
- end
236
-
237
- it "should populate data" do
238
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
239
- connection.void(order)
105
+ it "should return response" do
106
+ void = {
107
+ :status => "1",
108
+ :message => "BLA"
109
+ }
240
110
 
241
- order.gateway_void_return_code.should eq('0')
242
- order.gateway_void_status.should eq('0')
243
- order.gateway_void_message.should eq('Approved')
244
- order.gateway_void_amount.should eq(100.00)
245
- end
246
-
247
- it "should return response object" do
248
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => valid_xml))
249
- response = connection.void(order)
111
+ connection.should_receive(:post).and_return(void)
250
112
 
251
- response.success?.should be(true)
252
- response.message.should eq('Approved')
253
- end
254
-
255
- it "should return error in response" do
256
- Braspag::Poster.any_instance.should_receive(:do_post).and_return(mock(:body => invalid_xml))
257
- response = connection.void(order)
113
+ response = connection.void(mock)
258
114
 
259
- response.success?.should be(false)
260
- response.message.should eq('Payment Server detected an error')
261
- response.params.should eq({"order_id"=>"1234", "amount"=>"100", "message"=>"Payment Server detected an error", "return_code"=>"7", "status"=>"2", "transaction_id"=>"0"})
262
- end
263
- end
264
-
265
- pending ".save" do
266
- let(:params) do
267
- {
268
- :customer_name => "W" * 21,
269
- :holder => "Joao Maria Souza",
270
- :card_number => "9" * 10,
271
- :expiration => "10/12",
272
- :order_id => "um order id",
273
- :request_id => "00000000-0000-0000-0000-000000000044"
274
- }
275
- end
276
-
277
- let(:params_with_merchant_id) do
278
- params.merge!(:merchant_id => merchant_id)
279
- end
280
-
281
- let(:save_protected_card_url) { "http://braspag.com/bla" }
282
-
283
- let(:savon_double) { double('Savon') }
284
-
285
- before do
286
- @connection.should_receive(:merchant_id)
287
- end
288
-
289
- context "with valid params" do
290
- let(:valid_hash) do
291
- {
292
- :save_credit_card_response => {
293
- :save_credit_card_result => {
294
- :just_click_key => 'SAVE-PROTECTED-CARD-TOKEN',
295
- :success => true
296
- }
297
- }
298
- }
299
- end
300
-
301
- let(:response) do
302
- double('Response', :to_hash => valid_hash)
303
- end
304
-
305
- before do
306
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
307
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
308
- .and_return(true)
309
- Savon::Client.should_receive(:new).and_return(savon_double)
310
- savon_double.should_receive(:request).and_return(response)
311
-
312
- @response = Braspag::ProtectedCreditCard.save(params)
313
- end
314
-
315
- it "should return a Hash" do
316
- @response.should be_kind_of Hash
317
- @response.should == {
318
- :just_click_key => "SAVE-PROTECTED-CARD-TOKEN",
319
- :success => true
320
- }
321
- end
322
- end
323
-
324
- context "with invalid params" do
325
- let(:invalid_hash) do
326
- {
327
- :save_credit_card_response => {
328
- :save_credit_card_result => {
329
- :just_click_key => nil,
330
- :success => false
331
- }
332
- }
333
- }
334
- end
335
-
336
- let(:response) do
337
- double('Response', :to_hash => invalid_hash)
338
- end
339
-
340
- before do
341
- Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
342
- .and_return(true)
343
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
344
- .and_return(save_protected_card_url)
345
- Savon::Client.should_receive(:new).and_return(savon_double)
346
- savon_double.should_receive(:request).and_return(response)
347
-
348
- @response = Braspag::ProtectedCreditCard.save(params)
349
- end
350
-
351
- it "should return a Hash" do
352
- @response.should be_kind_of Hash
353
- @response.should == {
354
- :just_click_key => nil,
355
- :success => false
356
- }
357
- end
358
- end
359
- end
360
-
361
- pending ".get" do
362
- let(:get_protected_card_url) { "http://braspag/bla" }
363
-
364
- let(:invalid_xml) do
365
- <<-EOXML
366
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
367
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
368
- xmlns="http://www.pagador.com.br/">
369
- <CardHolder>Joao Maria Souza</CardHolder>
370
- <CardNumber></CardNumber>
371
- <CardExpiration>10/12</CardExpiration>
372
- <MaskedCardNumber>******9999</MaskedCardNumber>
373
- </CartaoProtegidoReturn>
374
- EOXML
375
- end
376
-
377
- let(:valid_xml) do
378
- <<-EOXML
379
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
380
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
381
- xmlns="http://www.pagador.com.br/">
382
- <CardHolder>Joao Maria Souza</CardHolder>
383
- <CardNumber>9999999999</CardNumber>
384
- <CardExpiration>10/12</CardExpiration>
385
- <MaskedCardNumber>******9999</MaskedCardNumber>
386
- </CartaoProtegidoReturn>
387
- EOXML
115
+ response.success?.should eq(false)
116
+ response.message.should eq(void[:message])
117
+ response.params.should eq({"status"=>"1", "message"=>"BLA"})
118
+ response.test.should eq(true)
388
119
  end
389
120
 
390
- it "should raise an error when just click key is not valid" do
391
- Braspag::ProtectedCreditCard.should_receive(:valid_just_click_key?)
392
- .with("bla")
393
- .and_return(false)
394
-
395
- expect {
396
- Braspag::ProtectedCreditCard.get "bla"
397
- }.to raise_error(Braspag::InvalidJustClickKey)
398
- end
399
-
400
- it "should raise an error when Braspag returned an invalid xml as response" do
401
- FakeWeb.register_uri(:post, get_protected_card_url, :body => invalid_xml)
402
-
403
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
404
- .and_return(get_protected_card_url)
405
-
406
- expect {
407
- Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
408
- }.to raise_error(Braspag::UnknownError)
409
- end
410
-
411
- it "should return a Hash when Braspag returned a valid xml as response" do
412
- FakeWeb.register_uri(:post, get_protected_card_url, :body => valid_xml)
413
-
414
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
415
- .and_return(get_protected_card_url)
416
-
417
- response = Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
418
- response.should be_kind_of Hash
419
-
420
- response.should == {
421
- :holder => "Joao Maria Souza",
422
- :expiration => "10/12",
423
- :card_number => "9" * 10,
424
- :masked_card_number => "*" * 6 + "9" * 4
121
+ it "should return success when status is zero" do
122
+ void = {
123
+ :status => "0",
124
+ :message => "BLA"
425
125
  }
426
- end
427
-
428
- end
429
-
430
- pending ".just_click_shop" do
431
- context "body" do
432
- let(:params) { {
433
- :request_id => "123",
434
- :customer_name => "Joao Silva",
435
- :order_id => "999",
436
- :amount => 10.50,
437
- :payment_method => :redecard,
438
- :number_installments => 3,
439
- :payment_type => "test",
440
- :just_click_key => "key",
441
- :security_code => "123"
442
- } }
443
-
444
- class SavonClientTest
445
- attr_accessor :response
446
- attr_reader :method
447
-
448
- def request(web, method, &block)
449
- @method = method
450
- instance_eval &block
451
-
452
- @response
453
- end
454
-
455
- def soap
456
- @soap ||= OpenStruct.new
457
- end
458
- end
459
-
460
- before :each do
461
- @savon_client_test = SavonClientTest.new
462
- @savon_client_test.response = {:just_click_shop_response => {}}
463
- Savon::Client.stub(:new).with('https://www.cartaoprotegido.com.br/Services/TestEnvironment/CartaoProtegido.asmx?wsdl').and_return(@savon_client_test)
464
- end
465
-
466
- after :each do
467
- Savon::Client.unstub(:new)
468
- end
469
-
470
- it "should have RequestId" do
471
- described_class.just_click_shop(params)
472
- @savon_client_test.soap.body['justClickShopRequestWS']['RequestId'].should eq '123'
473
- end
474
-
475
- it "should have MerchantKey" do
476
- described_class.just_click_shop(params)
477
- @savon_client_test.soap.body['justClickShopRequestWS']['MerchantKey'].should eq 'um id qualquer'
478
- end
479
-
480
- it "should have CustomerName" do
481
- described_class.just_click_shop(params)
482
- @savon_client_test.soap.body['justClickShopRequestWS']['CustomerName'].should eq 'Joao Silva'
483
- end
484
-
485
- it "should have OrderId" do
486
- described_class.just_click_shop(params)
487
- @savon_client_test.soap.body['justClickShopRequestWS']['OrderId'].should eq '999'
488
- end
489
-
490
- it "should have Amount" do
491
- described_class.just_click_shop(params)
492
- @savon_client_test.soap.body['justClickShopRequestWS']['Amount'].should eq 10.50
493
- end
494
-
495
- it "should have PaymentMethod" do
496
- described_class.just_click_shop(params)
497
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentMethod'].should eq 20
498
- end
499
-
500
- it "should have PaymentType" do
501
- described_class.just_click_shop(params)
502
- @savon_client_test.soap.body['justClickShopRequestWS']['PaymentType'].should eq 'test'
503
- end
504
-
505
- it "should have NumberInstallments" do
506
- described_class.just_click_shop(params)
507
- @savon_client_test.soap.body['justClickShopRequestWS']['NumberInstallments'].should eq 3
508
- end
509
-
510
- it "should have JustClickKey" do
511
- described_class.just_click_shop(params)
512
- @savon_client_test.soap.body['justClickShopRequestWS']['JustClickKey'].should eq 'key'
513
- end
514
-
515
- it "should have SecurityCode" do
516
- described_class.just_click_shop(params)
517
- @savon_client_test.soap.body['justClickShopRequestWS']['SecurityCode'].should eq '123'
518
- end
126
+
127
+ connection.should_receive(:post).and_return(void)
128
+
129
+ response = connection.void(mock)
130
+
131
+ response.success?.should eq(true)
519
132
  end
520
133
  end
521
134
  end
@@ -606,4 +219,167 @@ describe Braspag::CreditCard do
606
219
  end
607
220
  end
608
221
 
222
+ let(:customer) do
223
+ Braspag::Customer.new(:name => "W" * 21)
224
+ end
225
+
226
+ let(:order) do
227
+ Braspag::Order.new(
228
+ :id => "um order id",
229
+ :amount => 1000.00,
230
+ :payment_method => Braspag::PAYMENT_METHOD[:redecard],
231
+ :installments => 1,
232
+ :installments_type => Braspag::INTEREST[:no],
233
+ :customer => customer
234
+ )
235
+ end
236
+
237
+ let(:credit_card) do
238
+ Braspag::CreditCard.new(
239
+ :holder_name => "Joao Maria Souza",
240
+ :number => "9" * 10,
241
+ :month => "10",
242
+ :year => "12",
243
+ :verification_value => "123"
244
+ )
245
+ end
246
+
247
+ context "on authorize credit card" do
248
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
249
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
250
+
251
+ let(:valid_xml) do
252
+ <<-EOXML
253
+ <?xml version="1.0" encoding="utf-8"?>
254
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
255
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
256
+ xmlns="https://www.pagador.com.br/webservice/pagador">
257
+ <amount>1.000,00</amount>
258
+ <message>Transaction Successful</message>
259
+ <authorisationNumber>733610</authorisationNumber>
260
+ <returnCode>0</returnCode>
261
+ <status>1</status>
262
+ <transactionId>01231234</transactionId>
263
+ </PagadorReturn>
264
+ EOXML
265
+ end
266
+
267
+ it "should convert objects to hash" do
268
+ Braspag::CreditCard.to_authorize(connection, order, credit_card).should eq({
269
+ "merchantId" => "#{merchant_id}",
270
+ "orderId" => "#{order.id}",
271
+ "customerName" => "#{customer.name}",
272
+ "amount" => "1000,00",
273
+ "paymentMethod" => 20,
274
+ "holder" => "#{credit_card.holder_name}",
275
+ "cardNumber" => "#{credit_card.number}",
276
+ "expiration" => "10/12",
277
+ "securityCode" => "123",
278
+ "numberPayments" => order.installments,
279
+ "typePayment" => order.installments_type
280
+ })
281
+ end
282
+
283
+ it "should populate data" do
284
+ resp = Braspag::CreditCard.from_authorize(connection, order, credit_card, mock(:body => valid_xml))
285
+
286
+ order.gateway_authorization.should eq('733610')
287
+ order.gateway_id.should eq('01231234')
288
+ order.gateway_return_code.should eq('0')
289
+ order.gateway_status.should eq('1')
290
+ order.gateway_message.should eq('Transaction Successful')
291
+ order.gateway_amount.should eq(1000.00)
292
+
293
+ resp.should eq({
294
+ :amount=>"1.000,00",
295
+ :number=>"733610",
296
+ :message=>"Transaction Successful",
297
+ :return_code=>"0",
298
+ :status=>"1",
299
+ :transaction_id=>"01231234"})
300
+ end
301
+ end
302
+
303
+ context "on capture credit card" do
304
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
305
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
306
+
307
+ let(:valid_xml) do
308
+ <<-EOXML
309
+ <?xml version="1.0" encoding="utf-8"?>
310
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
311
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
312
+ xmlns="https://www.pagador.com.br/webservice/pagador">
313
+ <amount>2</amount>
314
+ <message>Approved</message>
315
+ <returnCode>0</returnCode>
316
+ <status>0</status>
317
+ </PagadorReturn>
318
+ EOXML
319
+ end
320
+
321
+ it "should convert objects to hash" do
322
+ Braspag::CreditCard.to_capture(connection, order).should eq({
323
+ "merchantId" => "#{merchant_id}",
324
+ "orderId" => "#{order.id}"
325
+ })
326
+ end
327
+
328
+ it "should populate data" do
329
+ resp = Braspag::CreditCard.from_capture(connection, order, mock(:body => valid_xml))
330
+
331
+ order.gateway_capture_return_code.should eq('0')
332
+ order.gateway_capture_status.should eq('0')
333
+ order.gateway_capture_message.should eq('Approved')
334
+ order.gateway_capture_amount.should eq(2.00)
335
+
336
+
337
+ resp.should eq({
338
+ :amount=>"2",
339
+ :message=>"Approved",
340
+ :return_code=>"0",
341
+ :status=>"0",
342
+ :transaction_id=>nil
343
+ })
344
+ end
345
+ end
346
+
347
+ context "on void credit card" do
348
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
349
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
350
+
351
+ let(:valid_xml) do
352
+ <<-EOXML
353
+ <?xml version="1.0" encoding="utf-8"?>
354
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
355
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
356
+ xmlns="https://www.pagador.com.br/webservice/pagador">
357
+ <orderId>1234</orderId>
358
+ <transactionId>0</transactionId>
359
+ <amount>100</amount>
360
+ <message>Approved</message>
361
+ <returnCode>0</returnCode>
362
+ <status>0</status>
363
+ </PagadorReturn>
364
+ EOXML
365
+ end
366
+
367
+ it "should convert objects to hash" do
368
+ Braspag::CreditCard.to_void(connection, order).should eq({
369
+ "merchantId" => "#{merchant_id}",
370
+ "order" => "#{order.id}"
371
+ })
372
+ end
373
+
374
+ it "should populate data" do
375
+ resp = Braspag::CreditCard.from_void(connection, order, mock(:body => valid_xml))
376
+
377
+ order.gateway_void_return_code.should eq('0')
378
+ order.gateway_void_status.should eq('0')
379
+ order.gateway_void_message.should eq('Approved')
380
+ order.gateway_void_amount.should eq(100.00)
381
+
382
+ resp.should eq({:order_id=>"1234", :amount=>"100", :message=>"Approved", :return_code=>"0", :status=>"0", :transaction_id=>"0"})
383
+ end
384
+ end
609
385
  end