rbraspag 0.0.19 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ describe Braspag::Crypto::JarWebservice do
14
14
  it "should return a string" do
15
15
  FakeWeb.register_uri(
16
16
  :post,
17
- "http://localhost:9292/v1/encrypt.json",
17
+ "http://localhost:9292/v1/encrypt.json",
18
18
  :body => <<-EOJSON
19
19
  {"encrypt":"5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7"}
20
20
  EOJSON
@@ -22,63 +22,63 @@ describe Braspag::Crypto::JarWebservice do
22
22
 
23
23
  crypt.encrypt(:nome => "Chapulin", :sobrenome => "Colorado").should == key
24
24
  end
25
-
25
+
26
26
  it "should raise a error with invalid params" do
27
27
  expect {
28
28
  crypt.encrypt(9999)
29
29
  }.to raise_error(Braspag::IncompleteParams)
30
30
  end
31
-
31
+
32
32
  it "should raise an error with invalid params after process" do
33
33
  FakeWeb.register_uri(
34
34
  :post,
35
- "http://localhost:9292/v1/encrypt.json",
35
+ "http://localhost:9292/v1/encrypt.json",
36
36
  :body => <<-EOJSON
37
37
  {
38
38
  "msg" : "INVALID FORMAT"
39
39
  }
40
40
  EOJSON
41
41
  )
42
-
42
+
43
43
  expect {
44
44
  crypt.encrypt(:venda => "value")
45
45
  }.to raise_error(Braspag::IncompleteParams)
46
46
  end
47
-
47
+
48
48
  it "should raise an error with invalid params after process" do
49
49
  FakeWeb.register_uri(
50
50
  :post,
51
- "http://localhost:9292/v1/encrypt.json",
51
+ "http://localhost:9292/v1/encrypt.json",
52
52
  :body => <<-EOJSON
53
53
  INVALIDO
54
54
  EOJSON
55
55
  )
56
-
56
+
57
57
  expect {
58
58
  crypt.encrypt(:venda => "value")
59
59
  }.to raise_error(Braspag::UnknownError)
60
60
  end
61
-
61
+
62
62
  it "should raise an error with invalid params after process" do
63
63
  FakeWeb.register_uri(
64
64
  :post,
65
- "http://localhost:9292/v1/encrypt.json",
65
+ "http://localhost:9292/v1/encrypt.json",
66
66
  :body => <<-EOJSON
67
67
  {
68
68
  "msg" : "INVALID FIELDS"
69
69
  }
70
70
  EOJSON
71
71
  )
72
-
72
+
73
73
  expect {
74
74
  crypt.encrypt(:venda => nil)
75
75
  }.to raise_error(Braspag::IncompleteParams)
76
76
  end
77
-
77
+
78
78
  it "should raise an error with invalid crypt key" do
79
79
  FakeWeb.register_uri(
80
80
  :post,
81
- "http://localhost:9292/v1/encrypt.json",
81
+ "http://localhost:9292/v1/encrypt.json",
82
82
  :body => <<-EOJSON
83
83
  {
84
84
  "msg" : "INVALID KEY"
@@ -90,15 +90,15 @@ INVALIDO
90
90
  crypt.encrypt(:venda => "value")
91
91
  }.to raise_error(Braspag::InvalidCryptKey)
92
92
  end
93
-
93
+
94
94
  end
95
95
 
96
96
  context "when decrypt data" do
97
-
97
+
98
98
  it "should return a hash" do
99
99
  FakeWeb.register_uri(
100
- :post,
101
- "http://localhost:9292/v1/decrypt.json",
100
+ :post,
101
+ "http://localhost:9292/v1/decrypt.json",
102
102
  :body => <<-EOJSON
103
103
  {"fields":{"nome":"Chapulin","sobrenome":"Colorado"}}
104
104
  EOJSON
@@ -106,11 +106,11 @@ INVALIDO
106
106
 
107
107
  crypt.decrypt(key, [:nome, :sobrenome])[:nome].should eql("Chapulin")
108
108
  end
109
-
109
+
110
110
  it "should raise a error with invalid encrypted key" do
111
111
  FakeWeb.register_uri(
112
112
  :post,
113
- "http://localhost:9292/v1/decrypt.json",
113
+ "http://localhost:9292/v1/decrypt.json",
114
114
  :body => <<-EOJSON
115
115
  {
116
116
  "msg" : "INVALID ENCRYPTED STRING"
@@ -122,24 +122,24 @@ INVALIDO
122
122
  crypt.decrypt("1", [:nome, :sobrenome])
123
123
  }.to raise_error(Braspag::InvalidEncryptedKey)
124
124
  end
125
-
125
+
126
126
  it "should raise a error with invalid encrypted key" do
127
127
  expect {
128
128
  crypt.decrypt(1, [:nome, :sobrenome])
129
129
  }.to raise_error(Braspag::InvalidEncryptedKey)
130
130
  end
131
-
132
-
131
+
132
+
133
133
  it "should raise a error with invalid fields" do
134
134
  expect {
135
135
  crypt.decrypt(key, 9999)
136
136
  }.to raise_error(Braspag::IncompleteParams)
137
137
  end
138
-
138
+
139
139
  it "should raise a error with invalid fields" do
140
140
  FakeWeb.register_uri(
141
141
  :post,
142
- "http://localhost:9292/v1/decrypt.json",
142
+ "http://localhost:9292/v1/decrypt.json",
143
143
  :body => <<-EOJSON
144
144
  {
145
145
  "msg" : "INVALID FIELDS"
@@ -151,11 +151,11 @@ INVALIDO
151
151
  crypt.decrypt(key, [:nome, :sobrenome])
152
152
  }.to raise_error(Braspag::IncompleteParams)
153
153
  end
154
-
154
+
155
155
  it "should raise an error with invalid params after process" do
156
156
  FakeWeb.register_uri(
157
157
  :post,
158
- "http://localhost:9292/v1/decrypt.json",
158
+ "http://localhost:9292/v1/decrypt.json",
159
159
  :body => <<-EOJSON
160
160
  INVALIDO
161
161
  EOJSON
@@ -166,22 +166,22 @@ INVALIDO
166
166
  crypt.decrypt(key, [:nome, :sobrenome])
167
167
  }.to raise_error(Braspag::UnknownError)
168
168
  end
169
-
169
+
170
170
  it "should raise an error with invalid crypt key" do
171
171
  FakeWeb.register_uri(
172
172
  :post,
173
- "http://localhost:9292/v1/decrypt.json",
173
+ "http://localhost:9292/v1/decrypt.json",
174
174
  :body => <<-EOJSON
175
175
  {
176
176
  "msg" : "INVALID KEY"
177
177
  }
178
178
  EOJSON
179
179
  )
180
-
180
+
181
181
  expect {
182
182
  crypt.decrypt(key, [:nome, :sobrenome])
183
183
  }.to raise_error(Braspag::InvalidCryptKey)
184
184
  end
185
-
185
+
186
186
  end
187
187
  end
@@ -2,10 +2,10 @@
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
4
  describe Braspag::Crypto::Webservice do
5
-
5
+
6
6
  context "encrypt" do
7
7
  let!(:key) {"XXXXX"}
8
-
8
+
9
9
  context "consistencies" do
10
10
  it "should return error with invalid data" do
11
11
  expect {
@@ -17,8 +17,8 @@ describe Braspag::Crypto::Webservice do
17
17
  body_invalid = <<-EOXML
18
18
  SERVER was unable to process
19
19
  EOXML
20
- FakeWeb.register_uri(:post,
21
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
20
+ FakeWeb.register_uri(:post,
21
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
22
22
  :body => body_invalid )
23
23
  expect {
24
24
  Braspag::Crypto::Webservice.encrypt(:key => "INVALID DATA")
@@ -34,15 +34,15 @@ EOXML
34
34
  <EncryptRequestResult>Erro BP 011</EncryptRequestResult></EncryptRequestResponse>
35
35
  </soap:Body></soap:Envelope>
36
36
  EOXML
37
- FakeWeb.register_uri(:post,
38
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
37
+ FakeWeb.register_uri(:post,
38
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
39
39
  :body => body_invalid )
40
40
  expect {
41
41
  Braspag::Crypto::Webservice.encrypt(:key => "value")
42
42
  }.to raise_error(Braspag::InvalidMerchantId)
43
43
  FakeWeb.clean_registry
44
44
  end
45
-
45
+
46
46
  it "should return error with invalid ip" do
47
47
  body_invalid = <<-EOXML
48
48
  <?xml version="1.0" encoding="utf-8"?>
@@ -51,8 +51,8 @@ EOXML
51
51
  <EncryptRequestResult>Erro BP 067</EncryptRequestResult></EncryptRequestResponse>
52
52
  </soap:Body></soap:Envelope>
53
53
  EOXML
54
- FakeWeb.register_uri(:post,
55
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
54
+ FakeWeb.register_uri(:post,
55
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
56
56
  :body => body_invalid )
57
57
  expect {
58
58
  Braspag::Crypto::Webservice.encrypt(:key => "value")
@@ -62,8 +62,8 @@ EOXML
62
62
  end
63
63
 
64
64
  it "should return a string" do
65
- FakeWeb.register_uri(:post,
66
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
65
+ FakeWeb.register_uri(:post,
66
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
67
67
  :body => <<-EOXML
68
68
  <?xml version='1.0' encoding='utf-8'?>
69
69
  <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'>
@@ -80,20 +80,20 @@ EOXML
80
80
  end
81
81
 
82
82
  context "when decrypt data" do
83
-
83
+
84
84
  context "consistencies" do
85
85
  it "should return error with invalid data" do
86
86
  expect {
87
87
  Braspag::Crypto::Webservice.decrypt(1213123)
88
88
  }.to raise_error(Braspag::IncompleteParams)
89
89
  end
90
-
90
+
91
91
  it "should return error with invalid data" do
92
92
  body_invalid = <<-EOXML
93
93
  SERVER was unable to process
94
94
  EOXML
95
- FakeWeb.register_uri(:post,
96
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
95
+ FakeWeb.register_uri(:post,
96
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
97
97
  :body => body_invalid )
98
98
  expect {
99
99
  Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")
@@ -109,8 +109,8 @@ EOXML
109
109
  <DecryptRequestResult><string>Erro BP 068</string></DecryptRequestResult>
110
110
  </DecryptRequestResponse></soap:Body></soap:Envelope>
111
111
  EOXML
112
- FakeWeb.register_uri(:post,
113
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
112
+ FakeWeb.register_uri(:post,
113
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
114
114
  :body => body_invalid )
115
115
  expect {
116
116
  Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")
@@ -120,8 +120,8 @@ EOXML
120
120
  end
121
121
 
122
122
  it "should return a string" do
123
- FakeWeb.register_uri(:post,
124
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
123
+ FakeWeb.register_uri(:post,
124
+ "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
125
125
  :body => <<-EOXML
126
126
  <?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'>
127
127
  <soap:Body><DecryptRequestResponse xmlns='https://www.pagador.com.br/webservice/BraspagGeneralService'>
@@ -138,6 +138,6 @@ EOXML
138
138
  Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")[:parcelas].should eql("1")
139
139
  FakeWeb.clean_registry
140
140
  end
141
-
141
+
142
142
  end
143
143
  end
@@ -1,229 +1,209 @@
1
- #encoding: utf-8
2
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
2
 
4
3
  describe Braspag::Eft do
5
- let!(:key) { "1234561246" }
6
- describe ".payment_method_from_id" do
7
- it 'Eft' do
8
- Braspag::Eft.payment_method_from_id(31).should == :unibanco
9
- Braspag::Eft.payment_method_from_id(31).should be_kind_of Symbol
10
- end
4
+ let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
5
+ let(:braspag_production_url) { "https://transaction.pagador.com.br" }
6
+ let(:merchant_id) { "um id qualquer" }
7
+
8
+ before do
9
+ @connection = mock(:merchant_id => merchant_id)
10
+ Braspag::Connection.stub(:instance => @connection)
11
11
  end
12
12
 
13
13
  describe ".generate" do
14
- context "consistencies" do
14
+ let(:params) do
15
+ {
16
+ :order_id => 11,
17
+ :amount => 3,
18
+ :payment_method => :bradesco,
19
+ :installments => 1,
20
+ :has_interest => 0
21
+ }
22
+ end
15
23
 
16
- it "should raise an error when :order_id is not present" do
17
- expect {
18
- Braspag::Eft.generate({
19
- :amount => "100.00",
20
- :payment_method => :bradesco
21
- })
22
- }.to raise_error(Braspag::IncompleteParams)
23
- end
24
+ let(:params_with_merchant_id) do
25
+ params.merge!(:merchant_id => merchant_id)
26
+ end
24
27
 
25
- it "should raise an error when :amount is not present" do
26
- expect {
27
- Braspag::Eft.generate({
28
- :order_id => "12",
29
- :payment_method => :bradesco
30
- })
31
- }.to raise_error(Braspag::IncompleteParams)
32
- end
28
+ let(:action_url) { "https://bla.com/foo/bar/baz" }
33
29
 
34
- it "should raise an error when :payment_method is not present" do
35
- expect {
36
- Braspag::Eft.generate({
37
- :order_id => "13",
38
- :amount => "120.00"
39
- })
40
- }.to raise_error(Braspag::IncompleteParams)
41
- end
30
+ before do
31
+ @connection.should_receive(:merchant_id)
42
32
 
43
- it "should raise an error when :order_id is less than 1 character" do
44
- expect {
45
- Braspag::Eft.generate({
46
- :order_id => "",
47
- :amount => "123.00",
48
- :payment_method => :bradesco
49
- })
50
- }.to raise_error(Braspag::InvalidOrderId)
51
- end
33
+ Braspag::Eft.should_receive(:action_url)
34
+ .and_return(action_url)
52
35
 
53
- it "should raise an error when :order_id is more than 50 characters" do
54
- expect {
55
- Braspag::Eft.generate({
56
- :order_id => "1" * 51,
57
- :amount => "12.00",
58
- :payment_method => :bradesco
59
- })
60
- }.to raise_error(Braspag::InvalidOrderId)
61
- end
36
+ Braspag::Eft.should_receive(:normalize_params)
37
+ .with(params_with_merchant_id)
38
+ .and_return(params_with_merchant_id)
62
39
 
63
- it "should raise an error when :customer_name is less than 1 character" do
64
- expect {
65
- Braspag::Eft.generate({
66
- :order_id => "102",
67
- :amount => "42.00",
68
- :payment_method => :bradesco,
69
- :customer_name => ""
70
- })
71
- }.to raise_error(Braspag::InvalidCustomerName)
72
- end
40
+ Braspag::Eft.should_receive(:check_params)
41
+ .and_return(true)
42
+ end
73
43
 
74
- it "should raise an error when :customer_name is more than 255 characters" do
75
- expect {
76
- Braspag::Eft.generate({
77
- :order_id => "112",
78
- :amount => "121.00",
79
- :payment_method => :bradesco,
80
- :customer_name => "A" * 256
81
- })
82
- }.to raise_error(Braspag::InvalidCustomerName)
83
- end
44
+ it "should return a html form" do
45
+ html = "<form id=\"form_tef_11\" name=\"form_tef_11\" action=\"#{action_url}\" method=\"post\">" +
46
+ "<input type=\"text\" name=\"Id_Loja\" value=\"#{merchant_id}\" />" +
47
+ '<input type="text" name="VENDAID" value="11" />' +
48
+ '<input type="text" name="nome" value="" />' +
49
+ '<input type="text" name="CPF" value="" />' +
50
+ '<input type="text" name="VALOR" value="3,00" />' +
51
+ '<input type="text" name="CODPAGAMENTO" value="11" />' +
52
+ '<input type="text" name="PARCELAS" value="1" />' +
53
+ '<input type="text" name="TIPOPARCELADO" value="0" />' +
54
+ '</form>' +
55
+ '<script type="text/javascript" charset="utf-8">document.forms["form_tef_11"].submit();</script>'
56
+
57
+ Braspag::Eft.generate(params).should == html
58
+ end
84
59
 
85
- it "should raise an error when :customer_id is less than 11 characters" do
86
- expect {
87
- Braspag::Eft.generate({
88
- :order_id => "23",
89
- :amount => "251.00",
90
- :payment_method => :bradesco,
91
- :customer_id => "2" * 10
92
- })
93
- }.to raise_error(Braspag::InvalidCustomerId)
94
- end
60
+ it "should return a html form when crypto strategy is given" do
61
+ crypto = mock
62
+ crypto.should_receive(:encrypt)
63
+ .with(a_kind_of(Hash))
64
+ .and_return("vei na boa")
95
65
 
96
- it "should raise an error when :customer_id is more than 18 characters" do
97
- expect {
98
- Braspag::Eft.generate({
99
- :order_id => "90",
100
- :amount => "90.00",
101
- :payment_method => :bradesco,
102
- :customer_id => "3" * 19
103
- })
104
- }.to raise_error(Braspag::InvalidCustomerId)
105
- end
66
+ html = "<form id=\"form_tef_11\" name=\"form_tef_11\" action=\"#{action_url}\" method=\"post\">" +
67
+ "<input type=\"text\" name=\"Id_Loja\" value=\"#{merchant_id}\" />" +
68
+ '<input type="text" name="crypt" value="vei na boa" />' +
69
+ '</form>' +
70
+ '<script type="text/javascript" charset="utf-8">document.forms["form_tef_11"].submit();</script>'
106
71
 
107
- it "should raise an error when :installments is less than 1 character" do
108
- expect {
109
- Braspag::Eft.generate({
110
- :order_id => "900",
111
- :amount => "92.00",
112
- :payment_method => :bradesco,
113
- :installments => ""
114
- })
115
- }.to raise_error(Braspag::InvalidInstallments)
116
- end
72
+ Braspag::Eft.generate(params, crypto).should == html
73
+ end
74
+ end
117
75
 
118
- it "should raise an error when :installments is more than 2 characters" do
119
- expect {
120
- Braspag::Eft.generate({
121
- :order_id => "91",
122
- :amount => "80.00",
123
- :payment_method => :bradesco,
124
- :installments => "5" * 3
125
- })
126
- }.to raise_error(Braspag::InvalidInstallments)
127
- end
76
+ describe ".normalize_params" do
77
+ it "should convert amount to BigDecimal" do
78
+ result = Braspag::Eft.normalize_params({ :amount => "100.2" })
79
+ result.should be_kind_of Hash
128
80
 
129
- it "should raise an error when :installments is not a number" do
130
- expect {
131
- Braspag::Eft.generate({
132
- :order_id => "91",
133
- :amount => "80.00",
134
- :payment_method => :bradesco,
135
- :installments => "A" * 2
136
- })
137
- }.to raise_error(Braspag::InvalidInstallments)
138
- end
81
+ result[:amount].should be_kind_of BigDecimal
82
+ end
139
83
 
140
- it "should raise an error when :has_interest is not boolean" do
84
+ it "should transform installments to Integer" do
85
+ result = Braspag::Eft.normalize_params({ :installments => "12" })
86
+ result.should be_kind_of Hash
87
+
88
+ result[:installments].should be_kind_of Integer
89
+ result[:installments].should == 12
90
+ end
91
+
92
+ it "should assign 1 to installments if installments is not present" do
93
+ result = Braspag::Eft.normalize_params({})
94
+ result.should be_kind_of Hash
95
+
96
+ result[:installments].should == 1
97
+ end
98
+
99
+ it "should transform has_interest into String" do
100
+ result = Braspag::Eft.normalize_params({ :has_interest => true })
101
+ result.should be_kind_of Hash
102
+
103
+ result[:has_interest].should == "1"
104
+
105
+ result = Braspag::Eft.normalize_params({ :has_interest => false })
106
+ result.should be_kind_of Hash
107
+
108
+ result[:has_interest].should == "0"
109
+ end
110
+ end
111
+
112
+ describe ".check_params" do
113
+ let(:params) do
114
+ {
115
+ :order_id => "111",
116
+ :amount => 100.0,
117
+ :payment_method => :bradesco
118
+ }
119
+ end
120
+
121
+ [:order_id, :amount, :payment_method].each do |param|
122
+ it "should raise an error when #{param} is not present" do
141
123
  expect {
142
- Braspag::Eft.generate({
143
- :order_id => "76",
144
- :amount => "50.00",
145
- :payment_method => :bradesco,
146
- :has_interest => []
147
- })
148
- }.to raise_error(Braspag::InvalidHasInterest)
124
+ params[param] = nil
125
+ Braspag::Eft.check_params(params)
126
+ }.to raise_error Braspag::IncompleteParams
149
127
  end
150
128
  end
151
129
 
152
- it "should return form fields in strategy without crypto" do
153
- html = <<-EOHTML
154
- <form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
155
- <input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
156
- <input type="text" name="VENDAID" value="1234123125" />
157
- <input type="text" name="nome" value="" />
158
- <input type="text" name="CPF" value="" />
159
- <input type="text" name="VALOR" value="123,00" />
160
- <input type="text" name="CODPAGAMENTO" value="11" />
161
- <input type="text" name="PARCELAS" value="1" />
162
- <input type="text" name="TIPOPARCELADO" value="0" />
163
- </form>
164
- <script type="text/javascript" charset="utf-8">
165
- document.forms["form_tef_1234123125"].submit();
166
- </script>
167
- EOHTML
168
-
169
- Braspag::Eft.generate({
170
- :order_id => "1234123125",
171
- :amount => "123.00",
172
- :payment_method => :bradesco
173
- }).should == html
174
- end
175
-
176
- it "should return form fields in strategy with braspag.jar crypto service" do
177
- FakeWeb.register_uri(:post,
178
- "http://localhost:9292/v1/encrypt.json",
179
- :body => <<-EOJSON
180
- {"encrypt":"5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7"}
181
- EOJSON
182
- )
183
-
184
- html = <<-EOHTML
185
- <form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
186
- <input type="text" name="crypt" value="5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7" />
187
- <input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
188
- </form>
189
- <script type="text/javascript" charset="utf-8">
190
- document.forms["form_tef_1234123125"].submit();
191
- </script>
192
- EOHTML
193
-
194
- Braspag::Eft.generate({
195
- :order_id => "1234123125",
196
- :amount => "123.00",
197
- :payment_method => :bradesco
198
- } , Braspag::Crypto::JarWebservice ).should == html
199
-
200
- FakeWeb.clean_registry
201
-
202
- end
203
-
204
- it "should return form fields in strategy with braspag crypto webservice" do
205
-
206
- FakeWeb.register_uri(:post,
207
- "https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
208
- :body => "<?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><EncryptRequestResponse xmlns='https://www.pagador.com.br/webservice/BraspagGeneralService'><EncryptRequestResult>#{key}</EncryptRequestResult></EncryptRequestResponse></soap:Body></soap:Envelope>" )
209
-
210
- html = <<-EOHTML
211
- <form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
212
- <input type="text" name="crypt" value="#{key}" />
213
- <input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
214
- </form>
215
- <script type="text/javascript" charset="utf-8">
216
- document.forms["form_tef_1234123125"].submit();
217
- </script>
218
- EOHTML
219
-
220
- Braspag::Eft.generate({
221
- :order_id => "1234123125",
222
- :amount => "123.00",
223
- :payment_method => :bradesco
224
- } , Braspag::Crypto::Webservice ).should == html
225
-
226
- FakeWeb.clean_registry
130
+ it "should raise an error when order_id is not valid" do
131
+ Braspag::Eft.should_receive(:valid_order_id?)
132
+ .with(params[:order_id])
133
+ .and_return(false)
134
+
135
+ expect {
136
+ Braspag::Eft.check_params(params)
137
+ }.to raise_error Braspag::InvalidOrderId
138
+ end
139
+
140
+ it "should raise an error when customer_name is present and is greater than 255 chars" do
141
+ expect {
142
+ params[:customer_name] = "b" * 256
143
+ Braspag::Eft.check_params(params)
144
+ }.to raise_error Braspag::InvalidCustomerName
145
+ end
146
+
147
+ it "should raise an error when customer_id is present and is greater than 18 chars" do
148
+ expect {
149
+ params[:customer_id] = "1" * 19
150
+ Braspag::Eft.check_params(params)
151
+ }.to raise_error Braspag::InvalidCustomerId
152
+ end
153
+
154
+ it "should raise an error when customer_id is present and is less than 11 chars" do
155
+ expect {
156
+ params[:customer_id] = "1" * 10
157
+ Braspag::Eft.check_params(params)
158
+ }.to raise_error Braspag::InvalidCustomerId
159
+ end
160
+
161
+ it "should raise an error when installments is present and is greater than 99" do
162
+ expect {
163
+ params[:installments] = 100
164
+ Braspag::Eft.check_params(params)
165
+ }.to raise_error Braspag::InvalidInstallments
166
+ end
167
+
168
+ it "should raise an error when installments is present and is less than 99" do
169
+ expect {
170
+ params[:installments] = 0
171
+ Braspag::Eft.check_params(params)
172
+ }.to raise_error Braspag::InvalidInstallments
173
+
174
+ expect {
175
+ params[:installments] = 1
176
+ Braspag::Eft.check_params(params)
177
+ }.to_not raise_error Braspag::InvalidInstallments
178
+ end
179
+
180
+ it "should raise an error when has_interest is present and is invalid" do
181
+ expect {
182
+ params[:has_interest] = "string"
183
+ Braspag::Eft.check_params(params)
184
+ }.to raise_error Braspag::InvalidHasInterest
185
+
186
+ expect {
187
+ params[:has_interest] = "1"
188
+ Braspag::Eft.check_params(params)
189
+ }.to_not raise_error Braspag::InvalidHasInterest
190
+
191
+ expect {
192
+ params[:has_interest] = "0"
193
+ Braspag::Eft.check_params(params)
194
+ }.to_not raise_error Braspag::InvalidHasInterest
195
+ end
196
+ end
197
+
198
+ describe ".action_url" do
199
+ it "should return the correct eft creation url when connection environment is homologation" do
200
+ @connection.stub(:braspag_url => braspag_homologation_url)
201
+ Braspag::Eft.action_url.should == "#{braspag_homologation_url}/pagador/passthru.asp"
202
+ end
203
+
204
+ it "should return the correct eft creation url when connection environment is production" do
205
+ @connection.stub(:braspag_url => braspag_production_url)
206
+ Braspag::Eft.action_url.should == "#{braspag_production_url}/pagador/passthru.asp"
227
207
  end
228
208
  end
229
209
  end