rents 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Contributing.md +203 -0
- data/Gemfile +3 -2
- data/README.md +1 -0
- data/lib/generators/templates/rents.rb +3 -3
- data/lib/rents/array.rb +6 -0
- data/lib/rents/config/enums/brands.yml +45 -0
- data/lib/rents/config/enums/currencies.yml +35 -0
- data/lib/rents/config/enums/payment_methods.yml +20 -0
- data/lib/rents/config/enums/recurrence_periods.yml +18 -0
- data/lib/rents/config/enums/transaction_codes.yml +31 -0
- data/lib/rents/config/proxy.example.yml +4 -0
- data/lib/rents/connection.rb +87 -12
- data/lib/rents/transaction.rb +61 -5
- data/lib/rents/version.rb +1 -1
- data/lib/rents.rb +43 -5
- data/modeling/API Routes.png +0 -0
- data/rents.gemspec +1 -1
- data/spec/file_helper.rb +42 -0
- data/spec/helpers.rb +12 -0
- data/spec/rents/status_spec.rb +3 -0
- data/spec/rents/transaction_spec.rb +662 -247
- metadata +22 -11
- /data/{modelagem → modeling}/Sequence - APIClient.asta +0 -0
- /data/{modelagem → modeling}/Structure - ClassDiagram.asta +0 -0
- /data/{modelagem → modeling}/WorkFlow - LocalGEM.asta +0 -0
- /data/{modelagem → modeling}/WorkFlow - LocalGEM.png +0 -0
- /data/{modelagem → modeling}/useful_files/card_operators/cielo/test_cards.txt +0 -0
- /data/{modelagem → modeling}/useful_files/card_operators/cielo/test_keys.txt +0 -0
@@ -1,265 +1,680 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rents::Transaction do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Rents.debugger=true
|
10
|
-
base_url = 'http://localhost:7000'
|
11
|
-
|
12
|
-
@api_status = Rents::Status.new
|
13
|
-
@page_transaction = Rents::Transaction.new({
|
14
|
-
card:{flag:'visa'},
|
15
|
-
amount: Random.rand(99999), # TODO: no error por rand menor que 99 (* mandatory) Amount in cents (1000 = R$ 10,00)
|
16
|
-
redirect_link: "#{base_url}/api/redirect_receiver" # (* optional) used only for CieloPage
|
17
|
-
})
|
18
|
-
|
19
|
-
# Fake SoldItems added
|
20
|
-
@page_transaction.sold_items = fake_sold_items
|
21
|
-
|
22
|
-
# Send BuyPage
|
23
|
-
@page_resp = @page_transaction.charge_page
|
24
|
-
end
|
25
|
-
|
26
|
-
# ================ Tests/Expects/Should ================
|
27
|
-
it 'resp should not be null' do
|
28
|
-
expect(@page_resp).to_not be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should setup the rid accessible method' do
|
32
|
-
expect(@page_transaction.rid).to_not be_nil
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should setup the purchase_url accessible method' do
|
36
|
-
expect(@page_transaction.purchase_url).to_not be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'resp should not have any error' do
|
40
|
-
error = @page_resp[:error]
|
41
|
-
error = @page_resp['error'] if error.nil?
|
42
|
-
expect(error).to be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'resp should be an accessible Operator URL' do
|
46
|
-
url = @page_transaction.purchase_url
|
47
|
-
|
48
|
-
expect(url).to_not be_nil
|
49
|
-
expect(accessible?(url)).to be_truthy
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'must be verifiable' do
|
53
|
-
# SetUps
|
54
|
-
verify_resp = @page_transaction.verify
|
55
|
-
error = verify_resp[:error]
|
56
|
-
error = verify_resp['error'] if error.nil?
|
57
|
-
|
58
|
-
# Validations
|
59
|
-
expect(verify_resp).to_not be_nil
|
60
|
-
expect(error).to be_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'must have a get accessible URL request' do
|
64
|
-
url = @page_transaction.url_requested+@page_transaction.request_params.it_keys_to_get_param
|
65
|
-
expect(be_accessible(url)).to be_truthy
|
66
|
-
end
|
4
|
+
before(:all) do
|
5
|
+
@protocol = 'http://'
|
6
|
+
@domain = 'localhost:7000'
|
7
|
+
@base_url = "#{@protocol}#{@domain}"
|
8
|
+
@global_subscription_rid = get_json("#{@base_url}/api/v1/global_subscription")[:rid]
|
67
9
|
end
|
68
10
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
11
|
+
context 'BuyOperatorPage' do
|
12
|
+
# OK Operator Page tests
|
13
|
+
describe '(SUCCESS REQUEST)' do
|
14
|
+
# ================ SetUp/Config ================
|
15
|
+
before(:all) do
|
16
|
+
Rents.debug=true
|
17
|
+
Rents.test_env=true
|
18
|
+
|
19
|
+
@api_status = Rents::Status.new
|
20
|
+
@page_transaction = Rents::Transaction.new({
|
21
|
+
card:{brand:'visa'},
|
22
|
+
amount: Random.rand(99999),
|
23
|
+
redirect_link: "#{@base_url}/api/redirect_receiver" # (* optional) used only for CieloPage
|
24
|
+
})
|
25
|
+
|
26
|
+
# Fake SoldItems added
|
27
|
+
@page_transaction.sold_items = fake_sold_items
|
28
|
+
|
29
|
+
# Send BuyPage
|
30
|
+
@page_resp = @page_transaction.charge_page
|
31
|
+
end
|
32
|
+
|
33
|
+
# ================ Tests/Expects/Should ================
|
34
|
+
it 'resp should not be null' do
|
35
|
+
expect(@page_resp).to_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'resp should contain the RequestID' do
|
39
|
+
request_id = @page_resp[:request_id]
|
40
|
+
expect(request_id).to_not be_nil
|
41
|
+
expect(request_id).to be_a Integer
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should setup the rid accessible method' do
|
45
|
+
expect(@page_transaction.rid).to_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should setup the purchase_url accessible method' do
|
49
|
+
expect(@page_transaction.purchase_url).to_not be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'resp should not have any error' do
|
53
|
+
error = @page_resp[:error]
|
54
|
+
error = @page_resp['error'] if error.nil?
|
55
|
+
expect(error).to be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'resp should be an accessible Operator URL' do
|
59
|
+
url = @page_transaction.purchase_url
|
60
|
+
|
61
|
+
expect(url).to_not be_nil
|
62
|
+
expect(accessible?(url)).to be_truthy
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'must be verifiable' do
|
66
|
+
# SetUps
|
67
|
+
verify_resp = @page_transaction.verify
|
68
|
+
error = verify_resp[:error]
|
69
|
+
error = verify_resp['error'] if error.nil?
|
70
|
+
|
71
|
+
# Validations
|
72
|
+
expect(error).to be_nil
|
73
|
+
expect(verify_resp).to_not be_nil
|
74
|
+
|
75
|
+
# It is just created status
|
76
|
+
expect(0..1).to cover(verify_resp[:status][:code])
|
77
|
+
expect(verify_resp[:status][:name]).to eq('pending')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'must have a get accessible URL request' do
|
81
|
+
url = @page_transaction.url_requested+@page_transaction.request_params.it_keys_to_get_param
|
82
|
+
expect(be_accessible(url)).to be_truthy
|
83
|
+
end
|
88
84
|
end
|
89
85
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
86
|
+
# NOT_OK Operator Page tests
|
87
|
+
describe '(BAD REQUEST)' do
|
88
|
+
# SetUp/Config
|
89
|
+
before(:each) do
|
90
|
+
Rents.debug = false
|
91
|
+
Rents.test_env = false
|
92
|
+
Rents.app_id = 1
|
93
|
+
Rents.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
94
|
+
|
95
|
+
# Not using test_env (so using a app passed not the global app)
|
96
|
+
@page_transaction = Rents::Transaction.new({
|
97
|
+
test: true,
|
98
|
+
card:{brand:'visa'},
|
99
|
+
amount: Random.rand(99999), # TODO: no error por rand menor que 99 (* mandatory) Amount in cents (1000 = R$ 10,00)
|
100
|
+
redirect_link: "#{@base_url}/api/redirect_receiver" # (* optional) used only for CieloPage
|
101
|
+
})
|
102
|
+
|
103
|
+
# Send BuyPage
|
104
|
+
@page_resp = @page_transaction.charge_page(full_resp=true)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'resp should contain the RequestID' do
|
108
|
+
request_id = JSON.parse(@page_resp).it_keys_to_sym[:request_id]
|
109
|
+
expect(request_id).to_not be_nil
|
110
|
+
expect(request_id).to be_a Integer
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'must have some error' do
|
114
|
+
# SetUp vars
|
115
|
+
json_resp = JSON.parse(@page_resp)
|
116
|
+
error = json_resp[:error]
|
117
|
+
error = json_resp['error'] if error.nil?
|
118
|
+
|
119
|
+
# Check what expected
|
120
|
+
expect(json_resp).to be_a Hash
|
121
|
+
expect(@page_resp.code).to eq(200)
|
122
|
+
expect(error).to_not be_nil
|
123
|
+
end
|
100
124
|
end
|
101
125
|
end
|
102
126
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
127
|
+
context 'BuyStorePage' do
|
128
|
+
# correct Request/Params
|
129
|
+
context 'SUCCESS' do
|
130
|
+
context 'Permitted request' do
|
131
|
+
# OK StorePage tests
|
132
|
+
describe 'Transaction charged' do
|
133
|
+
# ================ SetUp/Config ================
|
134
|
+
before(:all) do
|
135
|
+
Rents.debug=true
|
136
|
+
Rents.test_env=true
|
137
|
+
|
138
|
+
# To test it as CAPTURED it mustn't have cents or invalid credit card number!?
|
139
|
+
amount = Random.rand(99999).to_s
|
140
|
+
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
141
|
+
|
142
|
+
# Forcing formatted amount to check if the GEM is sending it with Operator format
|
143
|
+
amount.insert amount.length-2, ','
|
144
|
+
|
145
|
+
@store_transaction = Rents::Transaction.new({
|
146
|
+
card:{
|
147
|
+
brand: 'visa',
|
148
|
+
cvv: '123',
|
149
|
+
expiration_month: '05',
|
150
|
+
expiration_year: '2018',
|
151
|
+
number: '4012001037141112',
|
152
|
+
holder: Faker::Name.name,
|
153
|
+
},
|
154
|
+
|
155
|
+
amount: amount
|
156
|
+
})
|
157
|
+
|
158
|
+
# Fake SoldItems added
|
159
|
+
@store_transaction.sold_items = fake_sold_items
|
160
|
+
|
161
|
+
# Send StoreCharge
|
162
|
+
@resp = @store_transaction.charge_store
|
163
|
+
end
|
164
|
+
|
165
|
+
# ================ Tests/Expects/Should ================
|
166
|
+
it 'resp should not be null' do
|
167
|
+
expect(@resp).to_not be_nil
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'resp should contain the RequestID' do
|
171
|
+
request_id = @resp[:request_id]
|
172
|
+
expect(request_id).to_not be_nil
|
173
|
+
expect(request_id).to be_a Integer
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'resp should have a full SUCCESSFUL transaction status' do
|
177
|
+
status = @resp[:status]
|
178
|
+
expect(status[:name]).to eq('charged')
|
179
|
+
expect(status[:code]).to eq(6) # TODO change it to ENUM
|
180
|
+
expect(status[:msg].index('Capturada').nil?).to_not be_truthy
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
|
184
|
+
card = @resp[:card]
|
185
|
+
expect(card[:rid]).to be_a Integer
|
186
|
+
expect(card[:rid] == 0).to_not be_truthy
|
187
|
+
expect(card[:brand]).to eq('visa')
|
188
|
+
expect(card[:truncated].index('***')).to_not be_nil
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'resp should have the remote reference (TransactionRID)' do
|
192
|
+
rid = @resp[:rid]
|
193
|
+
expect(rid).to_not be_nil
|
194
|
+
expect(rid).to be_a Integer
|
195
|
+
expect(rid != 0).to be_truthy
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# TRANSACTION DENIED example
|
200
|
+
describe 'Transaction denied' do
|
201
|
+
# ================ SetUp/Config ================
|
202
|
+
before(:all) do
|
203
|
+
Rents.debug=true
|
204
|
+
Rents.test_env=true
|
205
|
+
|
206
|
+
# To test it as DENIED it must have cents or invalid credit card number!?
|
207
|
+
amount = Random.rand(99999).to_s
|
208
|
+
amount = "#{amount}71" if amount[amount.length-2, amount.length] == '00'
|
209
|
+
|
210
|
+
@store_transaction = Rents::Transaction.new({
|
211
|
+
card:{
|
212
|
+
brand: 'visa',
|
213
|
+
cvv: '321',
|
214
|
+
expiration_month: '05',
|
215
|
+
expiration_year: '2018',
|
216
|
+
number: '9999999999999999',
|
217
|
+
holder: Faker::Name.name,
|
218
|
+
},
|
219
|
+
recurrence_period_id: Rents.enum[:recurrence_periods][:daily],
|
220
|
+
amount: amount
|
221
|
+
})
|
222
|
+
|
223
|
+
# Fake SoldItems added
|
224
|
+
@store_transaction.sold_items = fake_sold_items
|
225
|
+
|
226
|
+
# Send StoreCharge
|
227
|
+
@resp = @store_transaction.charge_store
|
228
|
+
end
|
229
|
+
|
230
|
+
# ================ Tests/Expects/Should ================
|
231
|
+
it 'resp should not be null' do
|
232
|
+
expect(@resp).to_not be_nil
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'resp should contain the RequestID' do
|
236
|
+
request_id = @resp[:request_id]
|
237
|
+
expect(request_id).to_not be_nil
|
238
|
+
expect(request_id).to be_a Integer
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'resp should have a full SUCCESSFUL transaction status' do
|
242
|
+
status = @resp[:status]
|
243
|
+
expect(status[:name]).to eq('error')
|
244
|
+
expect(status[:code]).to eq(5) # TODO change it to ENUM
|
245
|
+
expect(status[:msg].index('não').nil?).to_not be_truthy
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
|
249
|
+
card = @resp[:card]
|
250
|
+
expect(card[:rid]).to be_nil
|
251
|
+
expect(card[:brand]).to eq('visa')
|
252
|
+
expect(card[:truncated].index('***')).to_not be_nil
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'resp should have the remote reference (TransactionRID)' do
|
256
|
+
rid = @resp[:rid]
|
257
|
+
expect(rid).to_not be_nil
|
258
|
+
expect(rid).to be_a Integer
|
259
|
+
expect(rid != 0).to be_truthy
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# Create a Subscription (Recurrent charges)
|
264
|
+
describe 'Sign a recurrent subscription' do
|
265
|
+
# ================ SetUp/Config ================
|
266
|
+
before(:all) do
|
267
|
+
Rents.debug=true
|
268
|
+
Rents.test_env=true
|
269
|
+
|
270
|
+
# To test it as CAPTURED it mustn't have cents or invalid credit card number!?
|
271
|
+
amount = Random.rand(99999).to_s
|
272
|
+
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
273
|
+
|
274
|
+
@store_transaction = Rents::Transaction.new({
|
275
|
+
card:{
|
276
|
+
brand: 'visa',
|
277
|
+
cvv: '123',
|
278
|
+
expiration_month: '05',
|
279
|
+
expiration_year: '2018',
|
280
|
+
number: '4012001037141112',
|
281
|
+
holder: Faker::Name.name
|
282
|
+
},
|
283
|
+
recurrence_period_id: Rents.enum[:recurrence_periods][:daily],
|
284
|
+
amount: amount
|
285
|
+
})
|
286
|
+
|
287
|
+
# Fake SoldItems added
|
288
|
+
@store_transaction.sold_items = fake_sold_items
|
289
|
+
|
290
|
+
# Send StoreCharge
|
291
|
+
@resp = @store_transaction.charge_store
|
292
|
+
end
|
293
|
+
|
294
|
+
# ================ Tests/Expects/Should ================
|
295
|
+
it 'resp should not be null' do
|
296
|
+
expect(@resp).to_not be_nil
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'resp should contain the RequestID' do
|
300
|
+
request_id = @resp[:request_id]
|
301
|
+
expect(request_id).to_not be_nil
|
302
|
+
expect(request_id).to be_a Integer
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'resp should have a full SUCCESSFUL transaction status' do
|
306
|
+
status = @resp[:status]
|
307
|
+
expect(status[:name]).to eq('charged')
|
308
|
+
expect(status[:code]).to eq(6) # TODO change it to ENUM
|
309
|
+
expect(status[:msg].index('Capturada').nil?).to_not be_truthy
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
|
313
|
+
card = @resp[:card]
|
314
|
+
expect(card[:rid]).to be_a Integer
|
315
|
+
expect(card[:rid] == 0).to_not be_truthy
|
316
|
+
expect(card[:brand]).to eq('visa')
|
317
|
+
expect(card[:truncated].index('***')).to_not be_nil
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'resp should have the remote reference (TransactionRID)' do
|
321
|
+
rid = @resp[:rid]
|
322
|
+
expect(rid).to_not be_nil
|
323
|
+
expect(rid).to be_a Integer
|
324
|
+
expect(rid != 0).to be_truthy
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
# Update a Subscription (Recurrent charges updated)
|
329
|
+
describe 'Update the recurrent subscription AMOUNT' do
|
330
|
+
# ================ SetUp/Config ================
|
331
|
+
before(:all) do
|
332
|
+
Rents.debug=true
|
333
|
+
Rents.test_env=true
|
334
|
+
|
335
|
+
# Force the amount to be random & to be exact
|
336
|
+
amount = Random.rand(99999).to_s
|
337
|
+
@amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
338
|
+
@amount = @amount.to_i
|
339
|
+
@recurrence_period = Rents.enum[:recurrence_periods][:monthly]
|
340
|
+
|
341
|
+
# Test passing no RID & passing specific RID
|
342
|
+
transaction_params = {amount: @amount, recurrence_period: @recurrence_period}
|
343
|
+
@empty_transaction = Rents::Transaction.new transaction_params
|
344
|
+
transaction_params[:rid] = @global_subscription_rid
|
345
|
+
@transaction_with_rid = Rents::Transaction.new transaction_params
|
346
|
+
|
347
|
+
# Send subscription update
|
348
|
+
@empty_transaction_resp = @empty_transaction.update_subscription
|
349
|
+
@rid_transaction_resp = @transaction_with_rid.update_subscription
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should be Hash' do
|
353
|
+
expect(@empty_transaction_resp).to be_a Hash
|
354
|
+
expect(@rid_transaction_resp).to be_a Hash
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'should be performed the unsubscribe' do
|
358
|
+
# SetUpVars
|
359
|
+
empty_subscription_resp = @empty_transaction_resp[:subscription]
|
360
|
+
resp_amount = empty_subscription_resp[:amount]
|
361
|
+
resp_recurrence_period = empty_subscription_resp[:recurrence_period_id]
|
362
|
+
|
363
|
+
# test those attrs
|
364
|
+
expect(resp_amount).to eq(@amount)
|
365
|
+
expect(resp_recurrence_period).to eq(@recurrence_period)
|
366
|
+
|
367
|
+
# SetUpVars
|
368
|
+
rid_subscription_resp = @rid_transaction_resp[:subscription]
|
369
|
+
resp_amount = rid_subscription_resp[:amount]
|
370
|
+
resp_recurrence_period = rid_subscription_resp[:recurrence_period_id]
|
371
|
+
|
372
|
+
# test those attrs
|
373
|
+
expect(resp_amount).to eq(@amount)
|
374
|
+
expect(resp_recurrence_period).to eq(@recurrence_period)
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'should not have any error' do
|
378
|
+
expect(@empty_transaction_resp).to_not include :error
|
379
|
+
expect(@rid_transaction_resp).to_not include :error
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# Unsubscribe a recurrence payment / signature
|
384
|
+
describe 'Unsubscribe a recurrent subscription' do
|
385
|
+
# ================ SetUp/Config ================
|
386
|
+
before(:all) do
|
387
|
+
Rents.debug=true
|
388
|
+
Rents.test_env=true
|
389
|
+
|
390
|
+
# Test passing no RID & passing specific RID
|
391
|
+
@empty_transaction = Rents::Transaction.new
|
392
|
+
@transaction_with_rid = Rents::Transaction.new rid: @global_subscription_rid
|
393
|
+
|
394
|
+
# Send Unsubscribe
|
395
|
+
@empty_transaction_resp = @empty_transaction.unsubscribe
|
396
|
+
@rid_transaction_resp = @transaction_with_rid.unsubscribe
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'should be Hash' do
|
400
|
+
expect(@empty_transaction_resp).to be_a Hash
|
401
|
+
expect(@rid_transaction_resp).to be_a Hash
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'should be performed the unsubscribe' do
|
405
|
+
expect(@empty_transaction_resp[:did_unsubscribe]).to be_truthy
|
406
|
+
expect(@rid_transaction_resp[:did_unsubscribe]).to be_truthy
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'should not have any error' do
|
410
|
+
expect(@empty_transaction_resp).to_not include :error
|
411
|
+
expect(@rid_transaction_resp).to_not include :error
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
# Should return all the bank transaction payments done
|
416
|
+
describe 'Subscription payment history' do
|
417
|
+
# ================ SetUp/Config ================
|
418
|
+
before(:all) do
|
419
|
+
Rents.debug=true
|
420
|
+
Rents.test_env=true
|
421
|
+
|
422
|
+
# Test passing no RID & passing specific RID
|
423
|
+
@transaction = Rents::Transaction.new
|
424
|
+
|
425
|
+
# Send Unsubscribe
|
426
|
+
@transaction_resp = @transaction.payment_history
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'should be an array' do
|
430
|
+
expect(@transaction_resp).to be_a Array
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should not have any error' do
|
434
|
+
expect(@transaction_resp.first).to_not include :error
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'should have the valid bank_transactions_payment format on it array' do
|
438
|
+
transaction = @transaction_resp.first
|
439
|
+
valid_keys = [
|
440
|
+
:amount, :active, :brand,
|
441
|
+
:currency_iso, :status_code, :status_message,
|
442
|
+
:next_transaction_at, :created_at, :updated_at
|
443
|
+
]
|
444
|
+
|
445
|
+
valid_keys.each {|key| expect(transaction[key]).to_not be_nil}
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
# Should retrieve it only bank transaction done
|
450
|
+
describe 'Non-subscription payment history' do
|
451
|
+
# ================ SetUp/Config ================
|
452
|
+
before(:all) do
|
453
|
+
Rents.debug=true
|
454
|
+
Rents.test_env=true
|
455
|
+
|
456
|
+
# Test passing no RID & passing specific RID
|
457
|
+
global_sample_transaction = get_json("#{@base_url}/api/v1/global_sample_transaction")
|
458
|
+
@transaction = Rents::Transaction.new rid: global_sample_transaction[:id]
|
459
|
+
|
460
|
+
# Send Unsubscribe
|
461
|
+
@transaction_resp = @transaction.payment_history
|
462
|
+
end
|
463
|
+
|
464
|
+
it 'should be a simple hash' do
|
465
|
+
expect(@transaction_resp).to be_a Hash
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'should not have any error' do
|
469
|
+
expect(@transaction_resp).to_not include :error
|
470
|
+
end
|
471
|
+
|
472
|
+
it 'should have the valid bank_transactions_payment format' do
|
473
|
+
valid_keys = [
|
474
|
+
:amount, :active, :brand,
|
475
|
+
:currency_iso, :status_code, :status_message,
|
476
|
+
:created_at, :updated_at
|
477
|
+
]
|
478
|
+
|
479
|
+
invalid_keys = [
|
480
|
+
:next_transaction_at, :recurrence_period_id
|
481
|
+
]
|
482
|
+
|
483
|
+
valid_keys.each {|key| expect(@transaction_resp[key]).to_not be_nil}
|
484
|
+
invalid_keys.each {|key| expect(@transaction_resp[key]).to be_nil}
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
# Check if a subscription is up-to-date
|
489
|
+
describe 'Up-to-date subscription' do
|
490
|
+
# ================ SetUp/Config ================
|
491
|
+
before(:all) do
|
492
|
+
Rents.debug=true
|
493
|
+
Rents.test_env=true
|
494
|
+
|
495
|
+
# Test passing no RID & passing specific RID
|
496
|
+
|
497
|
+
@transaction = Rents::Transaction.new
|
498
|
+
|
499
|
+
# Send Unsubscribe
|
500
|
+
@transaction_resp = @transaction.up_to_date
|
501
|
+
end
|
502
|
+
|
503
|
+
it 'should be Hash' do
|
504
|
+
expect(@transaction_resp).to be_a Hash
|
505
|
+
end
|
506
|
+
|
507
|
+
it 'should be up-to-date with success message' do
|
508
|
+
expect(@transaction_resp[:success]).to_not be_nil
|
509
|
+
end
|
510
|
+
|
511
|
+
it 'should not have any error' do
|
512
|
+
expect(@transaction_resp).to_not include :error
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
# Check if a subscription is up-to-date
|
517
|
+
describe 'Subscription PENDING payment, not up-to-date' do
|
518
|
+
# ================ SetUp/Config ================
|
519
|
+
before(:all) do
|
520
|
+
Rents.debug=true
|
521
|
+
Rents.test_env=true
|
522
|
+
|
523
|
+
# Test pending subscription payment passing specific RID
|
524
|
+
@global_pending_subscription = get_json("#{@base_url}/api/v1/global_pending_subscription")
|
525
|
+
@transaction_with_rid = Rents::Transaction.new rid: @global_pending_subscription[:id]
|
526
|
+
|
527
|
+
# Send Unsubscribe
|
528
|
+
@rid_transaction_resp = @transaction_with_rid.up_to_date
|
529
|
+
end
|
530
|
+
|
531
|
+
it 'should be Hash' do
|
532
|
+
expect(@rid_transaction_resp).to be_a Hash
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'should not have any error' do
|
536
|
+
expect(@rid_transaction_resp).to include :error
|
537
|
+
end
|
538
|
+
|
539
|
+
it 'should have the subscription' do
|
540
|
+
expect(@rid_transaction_resp[:subscription]).to_not be_nil
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
context 'Denied request' do
|
546
|
+
# Denying a subscription update
|
547
|
+
describe 'Update recurrent subscription DENIED' do
|
548
|
+
# ================ SetUp/Config ================
|
549
|
+
before(:all) do
|
550
|
+
Rents.debug=false
|
551
|
+
Rents.test_env=false
|
552
|
+
|
553
|
+
Rents.app_id = 1
|
554
|
+
Rents.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
555
|
+
|
556
|
+
# Force the amount to be random & to be exact
|
557
|
+
amount = Random.rand(99999).to_s
|
558
|
+
@amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
559
|
+
@amount = @amount.to_i
|
560
|
+
@recurrence_period = Rents.enum[:recurrence_periods][:monthly]
|
561
|
+
|
562
|
+
# Test passing no RID & passing specific RID
|
563
|
+
transaction_params = {rid: 1, amount: @amount, recurrence_period: @recurrence_period}
|
564
|
+
@transaction = Rents::Transaction.new transaction_params
|
565
|
+
|
566
|
+
# Send subscription update
|
567
|
+
@subscription_update_resp = @transaction.update_subscription
|
568
|
+
@subscription_update_full_resp = @transaction.update_subscription nil, true
|
569
|
+
end
|
570
|
+
|
571
|
+
it 'should be Hash' do
|
572
|
+
expect(@subscription_update_resp).to be_a Hash
|
573
|
+
end
|
574
|
+
|
575
|
+
it 'should not have an error' do
|
576
|
+
expect(@subscription_update_resp).to include :error
|
577
|
+
end
|
578
|
+
|
579
|
+
it 'should resp with SUCCESS (200)' do
|
580
|
+
expect(@subscription_update_full_resp.code).to eq(http_success)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
# Denying an unsubscribe
|
585
|
+
describe 'Unsubscribe denied' do
|
586
|
+
# ================ SetUp/Config ================
|
587
|
+
before(:all) do
|
588
|
+
Rents.debug=false
|
589
|
+
Rents.test_env=false
|
590
|
+
|
591
|
+
Rents.app_id = 1
|
592
|
+
Rents.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
593
|
+
|
594
|
+
# Test passing no RID & passing specific RID
|
595
|
+
@transaction_with_rid = Rents::Transaction.new rid: 1
|
596
|
+
|
597
|
+
# Send Unsubscribe
|
598
|
+
@rid_transaction_resp = @transaction_with_rid.unsubscribe
|
599
|
+
@transaction_full_resp = @transaction_with_rid.unsubscribe nil, true
|
600
|
+
end
|
601
|
+
|
602
|
+
it 'should be Hash' do
|
603
|
+
expect(@rid_transaction_resp).to be_a Hash
|
604
|
+
end
|
605
|
+
|
606
|
+
it 'should not have an error' do
|
607
|
+
expect(@rid_transaction_resp).to include :error
|
608
|
+
end
|
609
|
+
|
610
|
+
it 'should resp with SUCCESS (200)' do
|
611
|
+
expect(@transaction_full_resp.code).to eq(http_success)
|
612
|
+
end
|
613
|
+
end
|
614
|
+
end
|
137
615
|
end
|
138
616
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
617
|
+
# incorrect Request/Params
|
618
|
+
context 'BAD REQUEST' do
|
619
|
+
# NOT_OK on the authentication Store Page tests
|
620
|
+
describe 'Authentication failing' do
|
621
|
+
# SetUp/Config
|
622
|
+
before(:all) do
|
623
|
+
Rents.debug = true
|
624
|
+
Rents.test_env = false
|
625
|
+
Rents.app_id = 1
|
626
|
+
Rents.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
627
|
+
|
628
|
+
amount = Random.rand(99999).to_s
|
629
|
+
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
630
|
+
|
631
|
+
@store_transaction = Rents::Transaction.new({
|
632
|
+
card:{
|
633
|
+
brand: 'visa',
|
634
|
+
cvv: '321',
|
635
|
+
expiration_month: '05',
|
636
|
+
expiration_year: '2018',
|
637
|
+
number: '9999999999999999',
|
638
|
+
holder: Faker::Name.name,
|
639
|
+
},
|
640
|
+
|
641
|
+
amount: amount
|
642
|
+
})
|
643
|
+
|
644
|
+
# Fake SoldItems added
|
645
|
+
@store_transaction.sold_items = fake_sold_items
|
646
|
+
|
647
|
+
# Send StoreCharge
|
648
|
+
@resp = @store_transaction.charge_store
|
649
|
+
end
|
650
|
+
|
651
|
+
# ================ Tests/Expects/Should ================
|
652
|
+
it 'resp should exist (do not be empty)' do
|
653
|
+
expect(@resp).to_not be_nil
|
654
|
+
end
|
655
|
+
|
656
|
+
it 'resp should contain the RequestID' do
|
657
|
+
request_id = @resp[:request_id]
|
658
|
+
expect(request_id).to_not be_nil
|
659
|
+
expect(request_id).to be_a Integer
|
660
|
+
end
|
661
|
+
|
662
|
+
it 'resp should contain auth error' do
|
663
|
+
error = @resp[:error].downcase
|
664
|
+
expect(error).to_not be_nil
|
665
|
+
expect(error.index('auth error').nil?).to_not be_truthy
|
666
|
+
expect(error.index('AppID'.downcase).nil?).to_not be_truthy
|
667
|
+
expect(error.index('SecretKey'.downcase).nil?).to_not be_truthy
|
668
|
+
end
|
669
|
+
end
|
159
670
|
end
|
160
671
|
end
|
161
672
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
Rents.debugger=true
|
168
|
-
|
169
|
-
# To test it as DENIED it must have cents or invalid credit card number!?
|
170
|
-
amount = Random.rand(99999).to_s
|
171
|
-
amount = "#{amount}71" if amount[amount.length-2, amount.length] == '00'
|
172
|
-
|
173
|
-
@store_transaction = Rents::Transaction.new({
|
174
|
-
card:{
|
175
|
-
flag: 'visa',
|
176
|
-
cvv: '321',
|
177
|
-
expiration_month: '05',
|
178
|
-
expiration_year: '2018',
|
179
|
-
number: '9999999999999999',
|
180
|
-
holder: Faker::Name.name,
|
181
|
-
},
|
182
|
-
|
183
|
-
amount: amount
|
184
|
-
})
|
185
|
-
|
186
|
-
# Fake SoldItems added
|
187
|
-
@store_transaction.sold_items = fake_sold_items
|
188
|
-
|
189
|
-
# Send StoreCharge
|
190
|
-
@resp = @store_transaction.charge_store
|
191
|
-
end
|
192
|
-
|
193
|
-
# ================ Tests/Expects/Should ================
|
194
|
-
it 'resp should not be null' do
|
195
|
-
expect(@resp).to_not be_nil
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'resp should have a full SUCCESSFUL transaction status' do
|
199
|
-
status = @resp[:status]
|
200
|
-
expect(status[:name]).to eq('error')
|
201
|
-
expect(status[:code]).to eq(5) # TODO change it to ENUM
|
202
|
-
expect(status[:msg].index('não').nil?).to_not be_truthy
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :flag}' do
|
206
|
-
card = @resp[:card]
|
207
|
-
expect(card[:rid]).to be_nil
|
208
|
-
expect(card[:brand_mark]).to eq('visa')
|
209
|
-
expect(card[:truncated].index('***')).to_not be_nil
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'resp should have the remote reference (TransactionRID)' do
|
213
|
-
rid = @resp[:rid]
|
214
|
-
expect(rid).to_not be_nil
|
215
|
-
expect(rid).to be_a Integer
|
216
|
-
expect(rid != 0).to be_truthy
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# NOT_OK on the authentication Store Page tests
|
221
|
-
describe '(BAD REQUEST) Store - BuyPage' do
|
222
|
-
# SetUp/Config
|
223
|
-
before(:all) do
|
224
|
-
Rents.test_env = false
|
225
|
-
Rents.debugger = false
|
226
|
-
Rents.app_id = 1
|
227
|
-
Rents.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
228
|
-
|
229
|
-
amount = Random.rand(99999).to_s
|
230
|
-
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
231
|
-
|
232
|
-
@store_transaction = Rents::Transaction.new({
|
233
|
-
card:{
|
234
|
-
flag: 'visa',
|
235
|
-
cvv: '321',
|
236
|
-
expiration_month: '05',
|
237
|
-
expiration_year: '2018',
|
238
|
-
number: '9999999999999999',
|
239
|
-
holder: Faker::Name.name,
|
240
|
-
},
|
241
|
-
|
242
|
-
amount: amount
|
243
|
-
})
|
244
|
-
|
245
|
-
# Fake SoldItems added
|
246
|
-
@store_transaction.sold_items = fake_sold_items
|
247
|
-
|
248
|
-
# Send StoreCharge
|
249
|
-
@resp = @store_transaction.charge_store
|
250
|
-
end
|
251
|
-
|
252
|
-
# ================ Tests/Expects/Should ================
|
253
|
-
it 'resp should exist (do not be empty)' do
|
254
|
-
expect(@resp).to_not be_nil
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'resp should contain auth error' do
|
258
|
-
error = @resp[:error].downcase
|
259
|
-
expect(error).to_not be_nil
|
260
|
-
expect(error.index('auth error').nil?).to_not be_truthy
|
261
|
-
expect(error.index('AppID'.downcase).nil?).to_not be_truthy
|
262
|
-
expect(error.index('SecretKey'.downcase).nil?).to_not be_truthy
|
673
|
+
context 'Proxy' do
|
674
|
+
it 'should validate the proxy' do
|
675
|
+
uncomment_proxy_yml
|
676
|
+
expect(Rents.proxy).to_not be_nil
|
677
|
+
comment_proxy_yml
|
263
678
|
end
|
264
679
|
end
|
265
680
|
end
|