rbraspag 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbraspag (0.0.3)
4
+ rbraspag (0.0.5)
5
5
  cs-httpi (>= 0.9.5.2)
6
6
  json
7
7
  nokogiri
data/lib/rbraspag.rb CHANGED
@@ -19,6 +19,7 @@ require 'rbraspag/bill'
19
19
  require 'rbraspag/credit_card'
20
20
  require 'rbraspag/eft'
21
21
  require 'rbraspag/errors'
22
+ require 'rbraspag/utils'
22
23
 
23
24
  module Braspag
24
25
  class Production
data/lib/rbraspag/bill.rb CHANGED
@@ -87,7 +87,7 @@ module Braspag
87
87
  if k[0] == :payment_method
88
88
  memo[k[1]] = PAYMENT_METHOD[@params[:payment_method]]
89
89
  elsif k[0] == :amount
90
- memo[k[1]] = convert_decimal_to_string(@params[:amount])
90
+ memo[k[1]] = Utils.convert_decimal_to_string(@params[:amount])
91
91
  else
92
92
  memo[k[1]] = @params[k[0]] || "";
93
93
  end
@@ -113,12 +113,7 @@ module Braspag
113
113
  end
114
114
 
115
115
  protected
116
- def convert_decimal_to_string(value)
117
- cents = "0#{((value - value.to_i) * 100).to_i}".slice(-2,2)
118
- integer = (value - (value - value.to_i)).to_i
119
- "#{integer},#{cents}"
120
- end
121
-
116
+
122
117
  def uri
123
118
  "#{@connection.base_url}/webservices/pagador/Boleto.asmx/CreateBoleto"
124
119
  end
@@ -1,41 +1,119 @@
1
1
  module Braspag
2
2
  class CreditCard
3
3
 
4
- %w(authorize capture).each do |method|
5
- eval <<-METHOD
6
- def #{method}!(map)
7
- invoke! "#{method.capitalize}", map
8
- end
9
- METHOD
4
+ MAPPING = {
5
+ :merchant_id => "merchantId",
6
+ :order_id => "orderId",
7
+ :customer_name => "customerName",
8
+ :amount => "amount",
9
+ :payment_method => "paymentMethod",
10
+ :holder => "holder",
11
+ :card_number => "cardNumber",
12
+ :expiration => "expiration",
13
+ :security_code => "securityCode",
14
+ :number_payments => "numberPayments",
15
+ :type => "typePayment",
16
+ }
17
+
18
+ def initialize(connection)
19
+ raise InvalidConnection unless connection.is_a?(Braspag::Connection)
20
+ @connection = connection
21
+ @merchant_id = connection.merchant_id
22
+ end
23
+
24
+
25
+ def uri_authorize
26
+ "#{@connection.base_url}/webservices/pagador/Pagador.asmx/Authorize"
27
+ end
28
+
29
+ def uri_capture
30
+ "#{@connection.base_url}/webservices/pagador/Pagador.asmx/Capture"
10
31
  end
11
32
 
12
- protected
13
33
 
14
- def invoke!(method, map)
15
- document = invoke_and_parse(method, "#{base_action_url}/#{method}") do |message|
16
- map.each do |key, value|
17
- message.add("tns:#{key}", "#{value}")
34
+
35
+ def authorize params
36
+
37
+ [:order_id, :customer_name, :amount, :payment_method, :holder,
38
+ :card_number, :expiration, :security_code, :number_payments, :type].each do |param|
39
+ raise IncompleteParams unless params.include?(param)
40
+ end
41
+
42
+ raise InvalidOrderId unless (1..20).include?(params[:order_id].to_s.size)
43
+ raise InvalidCustomerName unless (1..100).include?(params[:customer_name].to_s.size)
44
+ raise InvalidAmount unless (1..10).include?(params[:amount].to_s.size)
45
+ raise InvalidHolder unless (1..100).include?(params[:holder].to_s.size)
46
+ raise InvalidExpirationDate unless (1..7).include?(params[:expiration].to_s.size)
47
+ raise InvalidSecurityCode unless (1..4).include?(params[:security_code].to_s.size)
48
+ raise InvalidNumberPayments unless (1..2).include?(params[:number_payments].to_s.size)
49
+ raise InvalidType unless (1..2).include?(params[:type].to_s.size)
50
+
51
+
52
+ data = MAPPING.inject({}) do |memo, k|
53
+ if k[0] == :amount
54
+ memo[k[1]] = Utils.convert_decimal_to_string(params[:amount])
55
+ else
56
+ memo[k[1]] = params[k[0]] || "";
18
57
  end
58
+
59
+ memo
19
60
  end
20
- convert_to_map document
61
+
62
+ request = ::HTTPI::Request.new uri_authorize
63
+ request.body = data
64
+ response = ::HTTPI.post request
65
+ response = convert_to_map response.body
66
+
21
67
  end
22
68
 
23
- def base_action_url
24
- "https://www.pagador.com.br/webservice/pagador"
25
- end
69
+ def capture order_id
70
+ raise InvalidOrderId unless (1..20).include?(order_id.to_s.size)
71
+
72
+ data = {MAPPING[:order_id] => order_id, "merchantId" => @merchant_id }
73
+ request = ::HTTPI::Request.new uri_capture
74
+
75
+ request.body = data
76
+ response = ::HTTPI.post request
77
+
78
+ # require "ruby-debug"
79
+ # debugger
80
+
81
+ response = convert_to_map response.body
26
82
 
27
- def uri
28
- "#{@connection.base_url}/webservices/pagador/Pagador.asmx"
29
83
  end
30
84
 
85
+
31
86
  def convert_to_map(document)
32
- map = { "amount" => "", "authorisationNumber" => "", "message" => "", "returnCode" => "", "status" => "", "transactionId" => "" }
33
- map.each_key do |key|
34
- document.xpath("//ns:#{key}").each do |text|
35
- map[key] = text.to_s
87
+ document = Nokogiri::XML(document)
88
+
89
+ map = {
90
+ :amount => nil,
91
+ :number => "authorisationNumber",
92
+ :message => 'message',
93
+ :return_code => 'returnCode',
94
+ :status => 'status',
95
+ :return_code => "returnCode"
96
+ }
97
+
98
+ map.each do |keyForMap , keyValue|
99
+ if keyValue.is_a?(String) || keyValue.nil?
100
+ keyValue = keyForMap if keyValue.nil?
101
+
102
+ value = document.search(keyValue).first
103
+ if !value.nil?
104
+ value = value.content.to_s
105
+ map[keyForMap] = value unless value == ""
106
+ end
107
+
108
+ elsif keyValue.is_a?(Proc)
109
+ map[keyForMap] = keyValue.call
36
110
  end
111
+
112
+ map[keyForMap]
37
113
  end
114
+
38
115
  map
39
116
  end
117
+
40
118
  end
41
119
  end
@@ -18,5 +18,10 @@ module Braspag
18
18
  class InvalidIP < Exception; end
19
19
  class InvalidCryptKey < Exception; end
20
20
  class InvalidEncryptedKey < Exception; end
21
+ class InvalidHolder < Exception ; end
22
+ class InvalidExpirationDate < Exception ; end
23
+ class InvalidSecurityCode < Exception ; end
24
+ class InvalidType < Exception ; end
25
+ class InvalidNumberPayments < Exception ; end
21
26
  class UnknownError < Exception ; end
22
27
  end
@@ -0,0 +1,10 @@
1
+ module Braspag
2
+
3
+ class Utils
4
+ def self.convert_decimal_to_string(value)
5
+ cents = "0#{((value - value.to_i) * 100).to_i}".slice(-2,2)
6
+ integer = (value - (value - value.to_i)).to_i
7
+ "#{integer},#{cents}"
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Braspag
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
data/rbraspag.gemspec CHANGED
@@ -5,8 +5,8 @@ require "rbraspag/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rbraspag"
7
7
  s.version = Braspag::VERSION
8
- s.authors = ["Celestino Gomes", "Renato Elias", "Luca Bastos", "Lenon Marcel", "Madson Cardoso"]
9
- s.email = %w[tinorj@gmail.com renato.elias@gmail.com lucabastos@gmail.com lenon.marcel@gmail.com madsonmac@gmail.com]
8
+ s.authors = ["Celestino Gomes", "Renato Elias", "Luca Bastos", "Lenon Marcel", "Madson Cardoso", "Marcelo Linhares"]
9
+ s.email = %w[tinorj@gmail.com renato.elias@gmail.com lucabastos@gmail.com lenon.marcel@gmail.com madsonmac@gmail.com marcelolinhares@gmail.com]
10
10
  s.homepage = "http://github.com/concretesolutions/rbraspag"
11
11
  s.summary = "rbraspag gem to use Braspag gateway"
12
12
  s.description = "rbraspag gem to use Braspag gateway"
@@ -1,68 +1,470 @@
1
+ #encoding: utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
3
 
3
4
  describe Braspag::CreditCard do
4
- before do
5
- @merchant_id = "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}"
6
- @connection = Braspag::Connection.new(@merchant_id, :test)
7
- @gateway = Braspag::CreditCard.new(@connection)
8
- # respond_with "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><AuthorizeResponse xmlns='https://www.pagador.com.br/webservice/pagador'><AuthorizeResult><amount>1</amount><authorisationNumber>418270</authorisationNumber><message>Transaction Successful</message><returnCode>0</returnCode><status>1</status><transactionId>128199</transactionId></AuthorizeResult></AuthorizeResponse></soap:Body></soap:Envelope>"
5
+
6
+ let!(:merchant_id) { "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" }
7
+ let!(:connection) { Braspag::Connection.new(merchant_id, :test) }
8
+
9
+ describe ".new" do
10
+
11
+ it "should raise an error when no connection is given" do
12
+ expect {
13
+ Braspag::CreditCard.new(Object.new)
14
+ }.to raise_error(Braspag::InvalidConnection)
15
+ end
16
+
9
17
  end
10
18
 
11
- context "on authorize!" do
12
- before :each do
13
- #respond_with "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><AuthorizeResponse xmlns='https://www.pagador.com.br/webservice/pagador'><AuthorizeResult><amount>1</amount><authorisationNumber>418270</authorisationNumber><message>Transaction Successful</message><returnCode>0</returnCode><status>1</status><transactionId>128199</transactionId></AuthorizeResult></AuthorizeResponse></soap:Body></soap:Envelope>"
14
- end
15
-
16
- pending "deve enviar dados para webservice de autorizacao" do
17
- expected = <<STRING
18
- <?xml version='1.0' ?>
19
- <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
20
- <env:Header />
21
- <env:Body>
22
- <tns:Authorize xmlns:tns="https://www.pagador.com.br/webservice/pagador">
23
- <tns:merchantId>#{@merchant_id}</tns:merchantId>
24
- <tns:orderId>teste564</tns:orderId>
25
- <tns:customerName>comprador de teste</tns:customerName>
26
- <tns:amount>1,00</tns:amount>
27
- </tns:Authorize>
28
- </env:Body>
29
- </env:Envelope>
30
- STRING
31
- # request_should_contain(expected)
32
- # @gateway.authorize! :orderId => "teste564", :customerName => "comprador de teste", :amount => "1,00"
33
- end
34
-
35
- pending "deve devolver o resultado em um mapa" do
36
- # map = {"amount" =>"1", "authorisationNumber" => "418270", "message" => "Transaction Successful", "returnCode" => "0", "status" => "1", "transactionId" => "128199"}
37
- # @gateway.authorize!(:orderId => "teste564", :customerName => "comprador de teste", :amount => "1,00").should == map
19
+ describe ".authorize" do
20
+
21
+ it "should raise an error when :order_id is not present" do
22
+ expect {
23
+ Braspag::CreditCard.new(connection).authorize({
24
+ :customer_name => "W" * 21,
25
+ :amount => "100.00",
26
+ :payment_method => 20,
27
+ :holder => "Joao Maria Souza",
28
+ :card_number => "9" * 10,
29
+ :expiration => "10/12",
30
+ :security_code => "123",
31
+ :number_payments => 1,
32
+ :type => 0
33
+ })
34
+ }.to raise_error(Braspag::IncompleteParams)
35
+ end
36
+
37
+ it "should raise an error when :customer_name is not present" do
38
+ expect {
39
+ Braspag::CreditCard.new(connection).authorize({
40
+ :order_id => "1" * 5,
41
+ :amount => "100.00",
42
+ :payment_method => 20,
43
+ :holder => "Joao Maria Souza",
44
+ :card_number => "9" * 10,
45
+ :expiration => "10/12",
46
+ :security_code => "123",
47
+ :number_payments => 1,
48
+ :type => 0
49
+ })
50
+ }.to raise_error(Braspag::IncompleteParams)
51
+ end
52
+
53
+ it "should raise an error when :amount is not present" do
54
+ expect {
55
+ Braspag::CreditCard.new(connection).authorize({
56
+ :order_id => "1" * 5,
57
+ :customer_name => "",
58
+ :payment_method => 20,
59
+ :holder => "Joao Maria Souza",
60
+ :card_number => "9" * 10,
61
+ :expiration => "10/12",
62
+ :security_code => "123",
63
+ :number_payments => 1,
64
+ :type => 0
65
+ })
66
+ }.to raise_error(Braspag::IncompleteParams)
67
+ end
68
+
69
+ it "should raise an error when :payment_method is not present" do
70
+ expect {
71
+ Braspag::CreditCard.new(connection).authorize({
72
+ :order_id => "1" * 5,
73
+ :customer_name => "",
74
+ :amount => "100.00",
75
+ :holder => "Joao Maria Souza",
76
+ :card_number => "9" * 10,
77
+ :expiration => "10/12",
78
+ :security_code => "123",
79
+ :number_payments => 1,
80
+ :type => 0
81
+ })
82
+ }.to raise_error(Braspag::IncompleteParams)
83
+ end
84
+
85
+ it "should raise an error when :holder is not present" do
86
+ expect {
87
+ Braspag::CreditCard.new(connection).authorize({
88
+ :order_id => "1" * 5,
89
+ :customer_name => "",
90
+ :payment_method => 20,
91
+ :amount => "100.00",
92
+ :card_number => "9" * 10,
93
+ :expiration => "10/12",
94
+ :security_code => "123",
95
+ :number_payments => 1,
96
+ :type => 0
97
+ })
98
+ }.to raise_error(Braspag::IncompleteParams)
99
+ end
100
+
101
+ it "should raise an error when :card_number is not present" do
102
+ expect {
103
+ Braspag::CreditCard.new(connection).authorize({
104
+ :order_id => "1" * 5,
105
+ :customer_name => "",
106
+ :payment_method => 20,
107
+ :amount => "100.00",
108
+ :holder => "Joao Maria Souza",
109
+ :expiration => "10/12",
110
+ :security_code => "123",
111
+ :number_payments => 1,
112
+ :type => 0
113
+ })
114
+ }.to raise_error(Braspag::IncompleteParams)
115
+ end
116
+
117
+ it "should raise an error when :expiration is not present" do
118
+ expect {
119
+ Braspag::CreditCard.new(connection).authorize({
120
+ :order_id => "1" * 5,
121
+ :customer_name => "",
122
+ :payment_method => 20,
123
+ :amount => "100.00",
124
+ :holder => "Joao Maria Souza",
125
+ :card_number => "9" * 10,
126
+ :security_code => "123",
127
+ :number_payments => 1,
128
+ :type => 0
129
+ })
130
+ }.to raise_error(Braspag::IncompleteParams)
131
+ end
132
+
133
+ it "should raise an error when :security_code is not present" do
134
+ expect {
135
+ Braspag::CreditCard.new(connection).authorize({
136
+ :order_id => "1" * 5,
137
+ :customer_name => "AAAAAAAA",
138
+ :payment_method => 20,
139
+ :amount => "100.00",
140
+ :holder => "Joao Maria Souza",
141
+ :expiration => "10/12",
142
+ :card_number => "9" * 10,
143
+ :number_payments => 1,
144
+ :type => 0
145
+ })
146
+ }.to raise_error(Braspag::IncompleteParams)
147
+ end
148
+
149
+ it "should raise an error when :number_payments is not present" do
150
+ expect {
151
+ Braspag::CreditCard.new(connection).authorize({
152
+ :order_id => "1" * 5,
153
+ :customer_name => "AAAAAAAA",
154
+ :payment_method => 20,
155
+ :amount => "100.00",
156
+ :holder => "Joao Maria Souza",
157
+ :expiration => "10/12",
158
+ :card_number => "9" * 10,
159
+ :type => 0
160
+ })
161
+ }.to raise_error(Braspag::IncompleteParams)
162
+ end
163
+
164
+ it "should raise an error when :type is not present" do
165
+ expect {
166
+ Braspag::CreditCard.new(connection).authorize({
167
+ :order_id => "1" * 5,
168
+ :customer_name => "AAAAAAAA",
169
+ :payment_method => 20,
170
+ :amount => "100.00",
171
+ :holder => "Joao Maria Souza",
172
+ :expiration => "10/12",
173
+ :card_number => "9" * 10,
174
+ :number_payments => 1
175
+ })
176
+ }.to raise_error(Braspag::IncompleteParams)
38
177
  end
178
+
179
+ let!(:valid_params) {
180
+ {
181
+ :order_id => "1" * 5,
182
+ :customer_name => "AAAAAAAA",
183
+ :payment_method => 20,
184
+ :amount => "100.00",
185
+ :holder => "Joao Maria Souza",
186
+ :expiration => "10/12",
187
+ :card_number => "9" * 10,
188
+ :security_code => "123",
189
+ :number_payments => 1,
190
+ :type => 0
191
+ }
192
+ }
193
+
194
+ it "should raise an error when :order_id is more than 20 characters" do
195
+ expect {
196
+ params = valid_params
197
+ params[:order_id] = "A" * 21
198
+ Braspag::CreditCard.new(connection).authorize(params)
199
+ }.to raise_error(Braspag::InvalidOrderId)
200
+ end
201
+
202
+ it "should raise an error when :customer_name is more than 100 characters" do
203
+ expect {
204
+ params = valid_params
205
+ params[:customer_name] = "B" * 101
206
+ Braspag::CreditCard.new(connection).authorize(params)
207
+ }.to raise_error(Braspag::InvalidCustomerName)
208
+ end
209
+
210
+ it "should raise an error when :amount is more than 10 characters" do
211
+ expect {
212
+ params = valid_params
213
+ params[:amount] = "1234567890,00"
214
+ Braspag::CreditCard.new(connection).authorize(params)
215
+ }.to raise_error(Braspag::InvalidAmount)
216
+ end
217
+
218
+ it "should raise an error when :holder is more than 100 characters" do
219
+ expect {
220
+ params = valid_params
221
+ params[:holder] = "E" * 101
222
+ Braspag::CreditCard.new(connection).authorize(params)
223
+ }.to raise_error(Braspag::InvalidHolder)
224
+ end
225
+
226
+ it "should raise an error when :expiration is more than 7 characters" do
227
+ expect {
228
+ params = valid_params
229
+ params[:expiration] = "7" * 8
230
+ Braspag::CreditCard.new(connection).authorize(params)
231
+ }.to raise_error(Braspag::InvalidExpirationDate)
232
+ end
233
+
234
+ it "should raise an error when :security_code is more than 4 characters" do
235
+ expect {
236
+ params = valid_params
237
+ params[:security_code] = "9" * 5
238
+ Braspag::CreditCard.new(connection).authorize(params)
239
+ }.to raise_error(Braspag::InvalidSecurityCode)
240
+ end
241
+
242
+ it "should raise an error when :number_payments is more than 2 characters" do
243
+ expect {
244
+ params = valid_params
245
+ params[:number_payments] = "123"
246
+ Braspag::CreditCard.new(connection).authorize(params)
247
+ }.to raise_error(Braspag::InvalidNumberPayments)
248
+ end
249
+
250
+ it "should raise an error when :type is more than 1 character" do
251
+ expect {
252
+ params = valid_params
253
+ params[:type] = "123"
254
+ Braspag::CreditCard.new(connection).authorize(params)
255
+ }.to raise_error(Braspag::InvalidType)
256
+ end
257
+
258
+ let!(:params) {
259
+ {
260
+ :order_id => "123456",
261
+ :customer_name => "Teste",
262
+ :payment_method => 18,
263
+ :amount => 1.3,
264
+ :holder => "teste",
265
+ :expiration => "05/13",
266
+ :card_number => "345678000000007",
267
+ :security_code => "1234",
268
+ :number_payments => "1",
269
+ :type => "0"
270
+ }
271
+ }
272
+
273
+ context "with a successful transaction" do
274
+
275
+ it "should return an array with :status => 1" do
276
+ xml = <<-EOXML
277
+ <?xml version="1.0" encoding="utf-8"?>
278
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
279
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
280
+ xmlns="https://www.pagador.com.br/webservice/pagador">
281
+ <amount>2</amount>
282
+ <authorisationNumber>733610</authorisationNumber>
283
+ <message>Transaction Successful</message>
284
+ <returnCode>0</returnCode>
285
+ <status>1</status>
286
+ <transactionId>398662</transactionId>
287
+ </PagadorReturn>
288
+ EOXML
289
+
290
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
291
+
292
+ result = Braspag::CreditCard.new(connection).authorize(params)
293
+ result[:status].should == "1"
294
+
295
+ FakeWeb.clean_registry
296
+ end
297
+
298
+ end
299
+
300
+ context "with a unsuccessful transaction" do
301
+
302
+ it "should return an array with :status => 2" do
303
+ invalid_params = params
304
+ invalid_params[:security_code] = 1
305
+
306
+ xml = <<-EOXML
307
+ <?xml version="1.0" encoding="utf-8"?>
308
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
309
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://www.pagador.com.br/webservice/pagador">
310
+ <amount>5</amount>
311
+ <message>Payment Server detected an error</message>
312
+ <returnCode>7</returnCode>
313
+ <status>2</status>
314
+ <transactionId>0</transactionId>
315
+ </PagadorReturn>
316
+ EOXML
317
+
318
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
319
+
320
+ result = Braspag::CreditCard.new(connection).authorize(invalid_params)
321
+ result[:status].should == "2"
322
+
323
+ FakeWeb.clean_registry
324
+ end
325
+
326
+ end
327
+
328
+ context "when a internal server error occurs on the gateway" do
329
+
330
+ it "should return an array with :status => null" do
331
+ invalid_params = params
332
+ invalid_params[:security_code] = "1"
333
+
334
+ xml = <<-EOXML
335
+ <?xml version="1.0" encoding="utf-8"?>
336
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
337
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
338
+ xmlns="https://www.pagador.com.br/webservice/pagador">
339
+ <amount>5</amount>
340
+ <message>Payment Server detected an error</message>
341
+ <returnCode>7</returnCode>
342
+ <status>null</status>
343
+ <transactionId>0</transactionId>
344
+ </PagadorReturn>
345
+ EOXML
346
+
347
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
348
+
349
+ result = Braspag::CreditCard.new(connection).authorize(invalid_params)
350
+ result[:status].should == "null"
351
+
352
+ FakeWeb.clean_registry
353
+ end
354
+
355
+ end
356
+
39
357
  end
40
358
 
41
- context "on capture!" do
42
- before :each do
43
- # respond_with "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><CaptureResponse xmlns='https://www.pagador.com.br/webservice/pagador'><CaptureResult><amount>1</amount><authorisationNumber>418270</authorisationNumber><message>Transaction Successful</message><returnCode>0</returnCode><status>1</status><transactionId>128199</transactionId></CaptureResult></CaptureResponse></soap:Body></soap:Envelope>"
359
+ describe ".capture" do
360
+
361
+ it "should raise an error when :order_id is more than 20 characters" do
362
+ expect {
363
+ Braspag::CreditCard.new(connection).capture(("A" * 21))
364
+ }.to raise_error(Braspag::InvalidOrderId)
365
+ end
366
+
367
+ it "should parse all the XML fields" do
368
+ xml = <<-EOXML
369
+ <?xml version="1.0" encoding="utf-8"?>
370
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
371
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
372
+ xmlns="https://www.pagador.com.br/webservice/pagador">
373
+ <amount>0.01</amount>
374
+ <message>Capture Successful</message>
375
+ <returnCode>07</returnCode>
376
+ <status>0</status>
377
+ </PagadorReturn>
378
+ EOXML
379
+
380
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
381
+
382
+ result = Braspag::CreditCard.new(connection).capture('123456')
383
+
384
+ result[:amount].should_not be_nil
385
+ result[:message].should_not be_nil
386
+ result[:return_code].should_not be_nil
387
+ result[:status].should_not be_nil
388
+
389
+ FakeWeb.clean_registry
44
390
  end
45
391
 
46
- pending "deve enviar dados para webservice de captura" do
47
- expected = <<STRING
48
- <?xml version='1.0' ?>
49
- <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
50
- <env:Header />
51
- <env:Body>
52
- <tns:Capture xmlns:tns="https://www.pagador.com.br/webservice/pagador">
53
- <tns:merchantId>#{@merchant_id}</tns:merchantId>
54
- <tns:orderId>teste564</tns:orderId>
55
- </tns:Capture>
56
- </env:Body>
57
- </env:Envelope>
58
- STRING
59
- # request_should_contain(expected)
60
- # @gateway.capture! :orderId => "teste564"
392
+ context "with a successful capture" do
393
+
394
+ it "should return an array with :status => 0" do
395
+ xml = <<-EOXML
396
+ <?xml version="1.0" encoding="utf-8"?>
397
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
398
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
399
+ xmlns="https://www.pagador.com.br/webservice/pagador">
400
+ <amount>2</amount>
401
+ <message>Approved</message>
402
+ <returnCode>0</returnCode>
403
+ <status>0</status>
404
+ </PagadorReturn>
405
+ EOXML
406
+
407
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
408
+
409
+ result = Braspag::CreditCard.new(connection).capture('123456')
410
+ result[:status].should == "0"
411
+
412
+ FakeWeb.clean_registry
413
+ end
414
+
61
415
  end
62
416
 
63
- pending "deve devolver o resultado em um mapa" do
64
- # map = {"amount" =>"1", "authorisationNumber" => "418270", "message" => "Transaction Successful", "returnCode" => "0", "status" => "1", "transactionId" => "128199"}
65
- # @gateway.capture!(:orderId => "teste564").should == map
417
+ context "with an unsuccessful capture" do
418
+
419
+ it "should return an array with :status => 2" do
420
+ xml = <<-EOXML
421
+ <?xml version="1.0" encoding="utf-8"?>
422
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
423
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
424
+ xmlns="https://www.pagador.com.br/webservice/pagador">
425
+ <amount>0.01</amount>
426
+ <message>Payment Server detected an error</message>
427
+ <returnCode>7</returnCode>
428
+ <status>2</status>
429
+ </PagadorReturn>
430
+ EOXML
431
+
432
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
433
+
434
+ result = Braspag::CreditCard.new(connection).capture("1")
435
+ result[:status].should == "2"
436
+
437
+ FakeWeb.clean_registry
438
+ end
439
+
66
440
  end
441
+
442
+ context "when an internal server error occurs on the gateway" do
443
+
444
+ it "should return an array with :status => null" do
445
+ xml = <<-EOXML
446
+ <?xml version="1.0" encoding="utf-8"?>
447
+ <PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
448
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
449
+ xmlns="https://www.pagador.com.br/webservice/pagador">
450
+ <amount>0.01</amount>
451
+ <message>Payment Server detected an error</message>
452
+ <returnCode>7</returnCode>
453
+ <status>null</status>
454
+ </PagadorReturn>
455
+ EOXML
456
+
457
+ FakeWeb.register_uri(:post, "#{Braspag::Test::BASE_URL}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
458
+
459
+ result = Braspag::CreditCard.new(connection).capture("1234")
460
+ result[:status].should == "null"
461
+
462
+ FakeWeb.clean_registry
463
+ end
464
+
465
+ end
466
+
67
467
  end
468
+
68
469
  end
470
+
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.4
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,14 +10,16 @@ authors:
10
10
  - Luca Bastos
11
11
  - Lenon Marcel
12
12
  - Madson Cardoso
13
+ - Marcelo Linhares
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
- date: 2011-07-06 00:00:00.000000000Z
17
+ date: 2011-07-11 00:00:00.000000000 -03:00
18
+ default_executable:
17
19
  dependencies:
18
20
  - !ruby/object:Gem::Dependency
19
21
  name: cs-httpi
20
- requirement: &15019380 !ruby/object:Gem::Requirement
22
+ requirement: &70094060 !ruby/object:Gem::Requirement
21
23
  none: false
22
24
  requirements:
23
25
  - - ! '>='
@@ -25,10 +27,10 @@ dependencies:
25
27
  version: 0.9.5.2
26
28
  type: :runtime
27
29
  prerelease: false
28
- version_requirements: *15019380
30
+ version_requirements: *70094060
29
31
  - !ruby/object:Gem::Dependency
30
32
  name: json
31
- requirement: &15018960 !ruby/object:Gem::Requirement
33
+ requirement: &70093160 !ruby/object:Gem::Requirement
32
34
  none: false
33
35
  requirements:
34
36
  - - ! '>='
@@ -36,10 +38,10 @@ dependencies:
36
38
  version: '0'
37
39
  type: :runtime
38
40
  prerelease: false
39
- version_requirements: *15018960
41
+ version_requirements: *70093160
40
42
  - !ruby/object:Gem::Dependency
41
43
  name: nokogiri
42
- requirement: &15018500 !ruby/object:Gem::Requirement
44
+ requirement: &70092550 !ruby/object:Gem::Requirement
43
45
  none: false
44
46
  requirements:
45
47
  - - ! '>='
@@ -47,10 +49,10 @@ dependencies:
47
49
  version: '0'
48
50
  type: :runtime
49
51
  prerelease: false
50
- version_requirements: *15018500
52
+ version_requirements: *70092550
51
53
  - !ruby/object:Gem::Dependency
52
54
  name: rspec
53
- requirement: &15018080 !ruby/object:Gem::Requirement
55
+ requirement: &70091530 !ruby/object:Gem::Requirement
54
56
  none: false
55
57
  requirements:
56
58
  - - ! '>='
@@ -58,10 +60,10 @@ dependencies:
58
60
  version: '0'
59
61
  type: :development
60
62
  prerelease: false
61
- version_requirements: *15018080
63
+ version_requirements: *70091530
62
64
  - !ruby/object:Gem::Dependency
63
65
  name: fakeweb
64
- requirement: &15017660 !ruby/object:Gem::Requirement
66
+ requirement: &70049170 !ruby/object:Gem::Requirement
65
67
  none: false
66
68
  requirements:
67
69
  - - ! '>='
@@ -69,10 +71,10 @@ dependencies:
69
71
  version: '0'
70
72
  type: :development
71
73
  prerelease: false
72
- version_requirements: *15017660
74
+ version_requirements: *70049170
73
75
  - !ruby/object:Gem::Dependency
74
76
  name: shoulda-matchers
75
- requirement: &15017240 !ruby/object:Gem::Requirement
77
+ requirement: &70047820 !ruby/object:Gem::Requirement
76
78
  none: false
77
79
  requirements:
78
80
  - - ! '>='
@@ -80,10 +82,10 @@ dependencies:
80
82
  version: '0'
81
83
  type: :development
82
84
  prerelease: false
83
- version_requirements: *15017240
85
+ version_requirements: *70047820
84
86
  - !ruby/object:Gem::Dependency
85
87
  name: guard-rspec
86
- requirement: &15048380 !ruby/object:Gem::Requirement
88
+ requirement: &70046940 !ruby/object:Gem::Requirement
87
89
  none: false
88
90
  requirements:
89
91
  - - ! '>='
@@ -91,10 +93,10 @@ dependencies:
91
93
  version: '0'
92
94
  type: :development
93
95
  prerelease: false
94
- version_requirements: *15048380
96
+ version_requirements: *70046940
95
97
  - !ruby/object:Gem::Dependency
96
98
  name: guard-bundler
97
- requirement: &15047960 !ruby/object:Gem::Requirement
99
+ requirement: &70045930 !ruby/object:Gem::Requirement
98
100
  none: false
99
101
  requirements:
100
102
  - - ! '>='
@@ -102,10 +104,10 @@ dependencies:
102
104
  version: '0'
103
105
  type: :development
104
106
  prerelease: false
105
- version_requirements: *15047960
107
+ version_requirements: *70045930
106
108
  - !ruby/object:Gem::Dependency
107
109
  name: ruby-debug19
108
- requirement: &15047540 !ruby/object:Gem::Requirement
110
+ requirement: &70045000 !ruby/object:Gem::Requirement
109
111
  none: false
110
112
  requirements:
111
113
  - - ! '>='
@@ -113,7 +115,7 @@ dependencies:
113
115
  version: '0'
114
116
  type: :development
115
117
  prerelease: false
116
- version_requirements: *15047540
118
+ version_requirements: *70045000
117
119
  description: rbraspag gem to use Braspag gateway
118
120
  email:
119
121
  - tinorj@gmail.com
@@ -121,6 +123,7 @@ email:
121
123
  - lucabastos@gmail.com
122
124
  - lenon.marcel@gmail.com
123
125
  - madsonmac@gmail.com
126
+ - marcelolinhares@gmail.com
124
127
  executables: []
125
128
  extensions: []
126
129
  extra_rdoc_files: []
@@ -140,6 +143,7 @@ files:
140
143
  - lib/rbraspag/crypto/webservice.rb
141
144
  - lib/rbraspag/eft.rb
142
145
  - lib/rbraspag/errors.rb
146
+ - lib/rbraspag/utils.rb
143
147
  - lib/rbraspag/version.rb
144
148
  - rbraspag.gemspec
145
149
  - spec/bill_spec.rb
@@ -149,6 +153,7 @@ files:
149
153
  - spec/crypto/webservice_spec.rb
150
154
  - spec/eft_spec.rb
151
155
  - spec/spec_helper.rb
156
+ has_rdoc: true
152
157
  homepage: http://github.com/concretesolutions/rbraspag
153
158
  licenses: []
154
159
  post_install_message:
@@ -169,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
174
  version: '0'
170
175
  requirements: []
171
176
  rubyforge_project: rbraspag
172
- rubygems_version: 1.8.1
177
+ rubygems_version: 1.6.2
173
178
  signing_key:
174
179
  specification_version: 3
175
180
  summary: rbraspag gem to use Braspag gateway