nitro_pay 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ =begin
2
+ require 'spec_helper'
3
+
4
+ describe 'Numeric conversions' do
5
+ describe 'BigDecimalBackup conversions' do
6
+ # setup it vars to have the conversion tested, value: 1999 (nineteen ninety nine)
7
+ pt_br = '1.999,00'
8
+ en_us = '1,999.00'
9
+
10
+ # Value like the card operator uses
11
+ operator_expected_value = '199900'
12
+ operator_value = '199900'
13
+ decimal_expected_value = BigDecimal.new '1999.00'
14
+
15
+ # it is the Rails conversion form the Form for Decimal input
16
+ decimal_obj_pt_br = BigDecimal.new(pt_br)
17
+ decimal_obj_en_us = BigDecimal.new(en_us.remove('.').remove(','))
18
+
19
+ # Conversions
20
+ pt_br_converted = Currency.to_operator_str decimal_obj_pt_br
21
+ en_us_converted = Currency.to_operator_str decimal_obj_en_us
22
+ decimal_converted = Currency.to_decimal operator_value
23
+
24
+ context 'Operator Format value' do
25
+
26
+ end
27
+
28
+ it 'should be running correctly' do
29
+ status = NitroPay::Status.new
30
+ expect(status.http_code).to equal(200)
31
+ expect(status.api_code).to equal(200)
32
+ expect(status.message).not_to be nil
33
+ end
34
+ end
35
+ end
36
+ =end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe NitroPay::Currency do
4
+ describe 'Operator Format value' do
5
+ # setup it vars to have the conversion tested, value: 1999 (nineteen ninety nine)
6
+ pt_br = '1.999,00'
7
+ en_us = '1,999.00'
8
+ non_formatted = '199900'
9
+ non_formatted_with_cents = '199933'
10
+
11
+ # Values expected
12
+ cents_expected = '55'
13
+ non_cents_expected = '00'
14
+ operator_value = non_formatted
15
+ integer_value = non_formatted.to_i
16
+ operator_expected_value = '199900'
17
+ decimal_value = BigDecimal.new '1999.00'
18
+ operator_with_cents = '300055' # R$ 3.000,55
19
+ decimal_expected_value = BigDecimal.new '1999.00'
20
+ expected_float_unit_cents = '100005'
21
+ expected_float_decimal_cents = '100050'
22
+ expected_float_without_cents = '100000'
23
+
24
+ # Float values
25
+ float_with_cents = 1000.55
26
+ float_without_cents = 1000.00
27
+
28
+ float_unit_cents = 1000.05
29
+ float_decimal_cents = 1000.50
30
+
31
+ # Values Converted to operator format
32
+ non_cents_received = NitroPay::Currency.get_cents operator_value
33
+ decimal_converted = NitroPay::Currency.to_decimal operator_value
34
+ cents_received = NitroPay::Currency.get_cents operator_with_cents
35
+ pt_br_operator_converted = NitroPay::Currency.to_operator_str pt_br
36
+ en_us_operator_converted = NitroPay::Currency.to_operator_str en_us
37
+ integer_converted = NitroPay::Currency.to_operator_str integer_value
38
+ big_decimal_converted = NitroPay::Currency.to_operator_str decimal_value
39
+ non_formatted_converted = NitroPay::Currency.to_operator_str non_formatted
40
+ non_formatted_with_cents_converted = NitroPay::Currency.to_operator_str non_formatted_with_cents
41
+ float_unit_cents_conv = NitroPay::Currency.to_operator_str float_unit_cents
42
+ float_decimal_cents_conv = NitroPay::Currency.to_operator_str float_decimal_cents
43
+ float_without_cents_conv = NitroPay::Currency.to_operator_str float_without_cents
44
+
45
+ context 'Decimal to Operator' do
46
+ # Convert PT_BR
47
+ it 'PT_BR should be convertible' do
48
+ expect(pt_br_operator_converted).to be_a String
49
+ expect(pt_br_operator_converted.index('.')).to be_nil
50
+ expect(pt_br_operator_converted.index(',')).to be_nil
51
+ expect(pt_br_operator_converted).to be_integer
52
+ expect(pt_br_operator_converted).to be_equals operator_expected_value
53
+ end
54
+
55
+ # Convert EN_US
56
+ it 'EN_US should be convertible' do
57
+ expect(en_us_operator_converted).to be_a String
58
+ expect(en_us_operator_converted.index('.')).to be_nil
59
+ expect(en_us_operator_converted.index(',')).to be_nil
60
+ expect(en_us_operator_converted).to be_integer
61
+ expect(en_us_operator_converted).to be_equals operator_expected_value
62
+ end
63
+
64
+ # To operator passing a BigDecimal instance
65
+ it 'should have a Operator format based on BigDecimal instance' do
66
+ expect(big_decimal_converted).to be_a String
67
+ expect(big_decimal_converted.index('.')).to be_nil
68
+ expect(big_decimal_converted.index(',')).to be_nil
69
+ expect(big_decimal_converted).to be_integer
70
+ expect(big_decimal_converted).to be_equals operator_expected_value
71
+ end
72
+ end
73
+
74
+ context 'Integer to Operator' do
75
+ it 'should have a Operator format based on Integer instance' do
76
+ expect(integer_converted).to be_a String
77
+ expect(integer_converted.index('.')).to be_nil
78
+ expect(integer_converted.index(',')).to be_nil
79
+ expect(integer_converted).to be_integer
80
+ expect(integer_converted).to be_equals operator_expected_value
81
+ end
82
+ end
83
+
84
+ context 'Float to Operator' do
85
+ it 'unit cents con must be on Operator format' do
86
+ expect(float_unit_cents_conv).to be == expected_float_unit_cents
87
+ end
88
+
89
+ it 'decimal cents con must be on Operator format' do
90
+ expect(float_decimal_cents_conv).to be == expected_float_decimal_cents
91
+ end
92
+
93
+ it 'no cents must be an Operator format' do
94
+ expect(float_without_cents_conv).to be == expected_float_without_cents
95
+ end
96
+ end
97
+
98
+ context 'Operator to Decimal' do
99
+ # Convert from the operator to BigDecimal instance, like rails does/need
100
+ it 'should be the BigDecimal expected' do
101
+ expect(decimal_converted).to be_a BigDecimal
102
+ expect(decimal_converted).to be == decimal_expected_value.to_i
103
+ end
104
+ end
105
+
106
+ context 'Non-formatted value to operator' do
107
+ context 'without cents' do
108
+ it 'must be the same as received' do
109
+ expect(non_formatted_converted).to be == non_formatted
110
+ end
111
+
112
+ it 'cents must be the same' do
113
+ expect(NitroPay::Currency.get_cents(non_formatted_converted)).to be == NitroPay::Currency.get_cents(non_formatted)
114
+ end
115
+ end
116
+
117
+ context 'with cents' do
118
+ it 'must be the same as received' do
119
+ expect(non_formatted_with_cents_converted).to be == non_formatted_with_cents
120
+ end
121
+
122
+ it 'cents must be the same' do
123
+ expect(NitroPay::Currency.get_cents(non_formatted_with_cents_converted)).to be == NitroPay::Currency.get_cents(non_formatted_with_cents)
124
+ end
125
+ end
126
+ end
127
+
128
+ context 'Methods to work in operator format' do
129
+ it 'should retrieve existent cents' do
130
+ expect(cents_received).to be_equals cents_expected
131
+ end
132
+
133
+ it 'should retrieve the non existent cents' do
134
+ expect(non_cents_received).to be_equals non_cents_expected
135
+ end
136
+
137
+ it 'should have cents' do
138
+ expect(NitroPay::Currency.have_cents?(operator_with_cents)).to be_truthy
139
+ end
140
+
141
+ it 'should not have cents' do
142
+ expect(NitroPay::Currency.have_cents?(operator_value)).to_not be_truthy
143
+ end
144
+
145
+ it '(RECEIVING FLOAT) should have cents' do
146
+ expect(NitroPay::Currency.have_cents?(float_with_cents)).to be_truthy
147
+ end
148
+
149
+ it '(RECEIVING FLOAT) should not have cents' do
150
+ expect(NitroPay::Currency.have_cents?(float_without_cents)).to_not be_truthy
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe NitroPay::Status do
4
+ describe 'API' do
5
+ it 'should be running correctly' do
6
+ NitroPay.debug=true
7
+ NitroPay.test_env=true
8
+
9
+ status = NitroPay::Status.new
10
+ expect(status.http_code).to equal(200)
11
+ expect(status.api_code).to equal(200)
12
+ expect(status.message).not_to be nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,584 @@
1
+ require 'spec_helper'
2
+
3
+ describe NitroPay::Transaction do
4
+ before(:all) do
5
+ @protocol = 'http://'
6
+ @domain = 'pay.dev:4000'
7
+ @base_url = "#{@protocol}#{@domain}"
8
+ @global_subscription_rid = get_json("#{@base_url}/api/v1/global_subscription")[:rid]
9
+ end
10
+
11
+ context 'Proxy' do
12
+ it 'should validate the proxy' do
13
+ uncomment_proxy_yml
14
+ expect(NitroPay.proxy).to_not be_nil
15
+ comment_proxy_yml
16
+ end
17
+ end
18
+
19
+ context 'BuyStorePage' do
20
+ # correct Request/Params
21
+ context 'SUCCESS' do
22
+ context 'Denied request' do
23
+ # Denying a subscription update
24
+ describe 'Update recurrent subscription DENIED' do
25
+ # ================ SetUp/Config ================
26
+ before(:all) do
27
+ NitroPay.debug=true
28
+ NitroPay.test_env=false
29
+
30
+ NitroPay.app_id = 1
31
+ NitroPay.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
32
+
33
+ # Force the amount to be random & to be exact
34
+ amount = Random.rand(99999).to_s
35
+ @amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
36
+ @amount = @amount.to_i
37
+ @recurrence_period = NitroPay.enum[:recurrence_periods][:monthly]
38
+
39
+ # Test passing no RID & passing specific RID
40
+ transaction_params = {rid: 1, amount: @amount, recurrence_period: @recurrence_period}
41
+ @transaction = NitroPay::Transaction.new transaction_params
42
+
43
+ # Send subscription update
44
+ @subscription_update_resp = @transaction.update_subscription
45
+ @subscription_update_full_resp = @transaction.update_subscription nil, true
46
+ end
47
+
48
+ it 'should be Hash' do
49
+ expect(@subscription_update_resp).to be_a Hash
50
+ end
51
+
52
+ it 'should not have an error' do
53
+ expect(@subscription_update_resp).to include :error
54
+ end
55
+
56
+ it 'should resp with SUCCESS (200)' do
57
+ expect(@subscription_update_full_resp.code).to eq(http_success)
58
+ end
59
+ end
60
+
61
+ # Denying an unsubscribe
62
+ describe 'Unsubscribe denied' do
63
+ # ================ SetUp/Config ================
64
+ before(:all) do
65
+ NitroPay.debug=true
66
+ NitroPay.test_env=false
67
+
68
+ NitroPay.app_id = 1
69
+ NitroPay.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
70
+
71
+ # Test passing no RID & passing specific RID
72
+ @transaction_with_rid = NitroPay::Transaction.new rid: 1
73
+
74
+ # Send Unsubscribe
75
+ @rid_transaction_resp = @transaction_with_rid.unsubscribe
76
+ @transaction_full_resp = @transaction_with_rid.unsubscribe nil, true
77
+ end
78
+
79
+ it 'should be Hash' do
80
+ expect(@rid_transaction_resp).to be_a Hash
81
+ end
82
+
83
+ it 'should not have an error' do
84
+ expect(@rid_transaction_resp).to include :error
85
+ end
86
+
87
+ it 'should resp with SUCCESS (200)' do
88
+ expect(@transaction_full_resp.code).to eq(http_success)
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'Permitted request' do
94
+ # OK StorePage tests
95
+ describe 'Transaction charged' do
96
+ # ================ SetUp/Config ================
97
+ before(:all) do
98
+ NitroPay.debug=true
99
+ NitroPay.test_env=true
100
+
101
+ # To test it as CAPTURED it mustn't have cents or invalid credit card number!?
102
+ amount = Random.rand(99999).to_s
103
+ amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
104
+
105
+ # Forcing formatted amount to check if the GEM is sending it with Operator format
106
+ amount.insert amount.length-2, ','
107
+
108
+ @store_transaction = NitroPay::Transaction.new({
109
+ card:{
110
+ brand: 'visa',
111
+ cvv: '123',
112
+ expiration_month: '05',
113
+ expiration_year: '2018',
114
+ number: '4012001037141112',
115
+ holder: Faker::Name.name,
116
+ },
117
+
118
+ amount: amount
119
+ })
120
+
121
+ # Fake SoldItems added
122
+ @store_transaction.sold_items = fake_sold_items
123
+
124
+ # Send StoreCharge
125
+ @resp = @store_transaction.charge_store
126
+ end
127
+
128
+ # ================ Tests/Expects/Should ================
129
+ it 'resp should not be null' do
130
+ expect(@resp).to_not be_nil
131
+ end
132
+
133
+ it 'resp should contain the RequestID' do
134
+ request_id = @resp[:request_id]
135
+ expect(request_id).to_not be_nil
136
+ expect(request_id).to be_a Integer
137
+ end
138
+
139
+ it 'resp should have a full SUCCESSFUL transaction status' do
140
+ status = @resp[:status]
141
+ expect(status[:name]).to eq('charged')
142
+ expect(status[:code]).to eq(6) # TODO change it to ENUM
143
+ expect(status[:msg].index('Capturada').nil?).to_not be_truthy
144
+ end
145
+
146
+ it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
147
+ card = @resp[:card]
148
+ expect(card[:rid]).to be_a Integer
149
+ expect(card[:rid] == 0).to_not be_truthy
150
+ expect(card[:brand]).to eq('visa')
151
+ expect(card[:truncated].index('***')).to_not be_nil
152
+ end
153
+
154
+ it 'resp should have the remote reference (TransactionRID)' do
155
+ rid = @resp[:rid]
156
+ expect(rid).to_not be_nil
157
+ expect(rid).to be_a Integer
158
+ expect(rid != 0).to be_truthy
159
+ end
160
+ end
161
+
162
+ # TRANSACTION DENIED example
163
+ describe 'Transaction denied' do
164
+ # ================ SetUp/Config ================
165
+ before(:all) do
166
+ NitroPay.debug=true
167
+ NitroPay.test_env=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 = NitroPay::Transaction.new({
174
+ card:{
175
+ brand: 'visa',
176
+ cvv: '321',
177
+ expiration_month: '05',
178
+ expiration_year: '2018',
179
+ number: '9999999999999999',
180
+ holder: Faker::Name.name,
181
+ },
182
+ recurrence_period_id: NitroPay.enum[:recurrence_periods][:daily],
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 contain the RequestID' do
199
+ request_id = @resp[:request_id]
200
+ expect(request_id).to_not be_nil
201
+ expect(request_id).to be_a Integer
202
+ end
203
+
204
+ it 'resp should have a full SUCCESSFUL transaction status' do
205
+ status = @resp[:status]
206
+ expect(status[:name]).to eq('error')
207
+ expect(status[:code]).to eq(5) # TODO change it to ENUM
208
+ expect(status[:msg].index('não').nil?).to_not be_truthy
209
+ end
210
+
211
+ it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
212
+ card = @resp[:card]
213
+ expect(card[:rid]).to be_nil
214
+ expect(card[:brand]).to eq('visa')
215
+ expect(card[:truncated].index('***')).to_not be_nil
216
+ end
217
+
218
+ it 'resp should have the remote reference (TransactionRID)' do
219
+ rid = @resp[:rid]
220
+ expect(rid).to_not be_nil
221
+ expect(rid).to be_a Integer
222
+ expect(rid != 0).to be_truthy
223
+ end
224
+ end
225
+
226
+ # Create a Subscription (Recurrent charges)
227
+ describe 'Sign a recurrent subscription' do
228
+ # ================ SetUp/Config ================
229
+ before(:all) do
230
+ NitroPay.debug=true
231
+ NitroPay.test_env=true
232
+
233
+ # To test it as CAPTURED it mustn't have cents or invalid credit card number!?
234
+ amount = Random.rand(99999).to_s
235
+ amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
236
+
237
+ @store_transaction = NitroPay::Transaction.new({
238
+ card:{
239
+ brand: 'visa',
240
+ cvv: '123',
241
+ expiration_month: '05',
242
+ expiration_year: '2018',
243
+ number: '4012001037141112',
244
+ holder: Faker::Name.name
245
+ },
246
+ recurrence_period_id: NitroPay.enum[:recurrence_periods][:daily],
247
+ amount: amount
248
+ })
249
+
250
+ # Fake SoldItems added
251
+ @store_transaction.sold_items = fake_sold_items
252
+
253
+ # Send StoreCharge
254
+ @resp = @store_transaction.charge_store
255
+ end
256
+
257
+ # ================ Tests/Expects/Should ================
258
+ it 'resp should not be null' do
259
+ expect(@resp).to_not be_nil
260
+ end
261
+
262
+ it 'resp should contain the RequestID' do
263
+ request_id = @resp[:request_id]
264
+ expect(request_id).to_not be_nil
265
+ expect(request_id).to be_a Integer
266
+ end
267
+
268
+ it 'resp should have a full SUCCESSFUL transaction status' do
269
+ status = @resp[:status]
270
+ expect(status[:name]).to eq('charged')
271
+ expect(status[:code]).to eq(6) # TODO change it to ENUM
272
+ expect(status[:msg].index('Capturada').nil?).to_not be_truthy
273
+ end
274
+
275
+ it 'resp should have a full CardObj which is allowed to be stored {:rid, :truncated, :brand}' do
276
+ card = @resp[:card]
277
+ expect(card[:rid]).to be_a Integer
278
+ expect(card[:rid] == 0).to_not be_truthy
279
+ expect(card[:brand]).to eq('visa')
280
+ expect(card[:truncated].index('***')).to_not be_nil
281
+ end
282
+
283
+ it 'resp should have the remote reference (TransactionRID)' do
284
+ rid = @resp[:rid]
285
+ expect(rid).to_not be_nil
286
+ expect(rid).to be_a Integer
287
+ expect(rid != 0).to be_truthy
288
+ end
289
+ end
290
+
291
+ # Update a Subscription (Recurrent charges updated)
292
+ describe 'Update the recurrent subscription AMOUNT' do
293
+ # ================ SetUp/Config ================
294
+ before(:all) do
295
+ NitroPay.debug=true
296
+ NitroPay.test_env=true
297
+
298
+ # Force the amount to be random & to be exact
299
+ amount = Random.rand(99999).to_s
300
+ @amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
301
+ @amount = @amount.to_i
302
+ @recurrence_period = NitroPay.enum[:recurrence_periods][:monthly]
303
+
304
+ # Test passing no RID & passing specific RID
305
+ transaction_params = {amount: @amount, recurrence_period: @recurrence_period}
306
+ @empty_transaction = NitroPay::Transaction.new transaction_params
307
+ transaction_params[:rid] = @global_subscription_rid
308
+ @transaction_with_rid = NitroPay::Transaction.new transaction_params
309
+
310
+ # Send subscription update
311
+ @empty_transaction_resp = @empty_transaction.update_subscription
312
+ @rid_transaction_resp = @transaction_with_rid.update_subscription
313
+ end
314
+
315
+ it 'should be Hash' do
316
+ expect(@empty_transaction_resp).to be_a Hash
317
+ expect(@rid_transaction_resp).to be_a Hash
318
+ end
319
+
320
+ it 'should be performed the unsubscribe' do
321
+ # SetUpVars
322
+ empty_subscription_resp = @empty_transaction_resp[:subscription]
323
+ resp_amount = empty_subscription_resp[:amount]
324
+ resp_recurrence_period = empty_subscription_resp[:recurrence_period]
325
+
326
+ # test those attrs
327
+ expect(resp_amount).to eq(@amount)
328
+ expect(resp_recurrence_period).to eq(@recurrence_period)
329
+
330
+ # SetUpVars
331
+ rid_subscription_resp = @rid_transaction_resp[:subscription]
332
+ resp_amount = rid_subscription_resp[:amount]
333
+ resp_recurrence_period = rid_subscription_resp[:recurrence_period]
334
+
335
+ # test those attrs
336
+ expect(resp_amount).to eq(@amount)
337
+ expect(resp_recurrence_period).to eq(@recurrence_period)
338
+ end
339
+
340
+ it 'should not have any error' do
341
+ expect(@empty_transaction_resp).to_not include :error
342
+ expect(@rid_transaction_resp).to_not include :error
343
+ end
344
+ end
345
+
346
+ # Unsubscribe a recurrence payment / signature
347
+ describe 'Unsubscribe a recurrent subscription' do
348
+ # ================ SetUp/Config ================
349
+ before(:all) do
350
+ NitroPay.debug=true
351
+ NitroPay.test_env=true
352
+
353
+ # Test passing no RID & passing specific RID
354
+ @empty_transaction = NitroPay::Transaction.new
355
+ @transaction_with_rid = NitroPay::Transaction.new rid: @global_subscription_rid
356
+
357
+ # Send Unsubscribe
358
+ @empty_transaction_resp = @empty_transaction.unsubscribe
359
+ @rid_transaction_resp = @transaction_with_rid.unsubscribe
360
+ end
361
+
362
+ it 'should be Hash' do
363
+ expect(@empty_transaction_resp).to be_a Hash
364
+ expect(@rid_transaction_resp).to be_a Hash
365
+ end
366
+
367
+ it 'should be performed the unsubscribe' do
368
+ expect(@empty_transaction_resp[:did_unsubscribe]).to be_truthy
369
+ expect(@rid_transaction_resp[:did_unsubscribe]).to be_truthy
370
+ end
371
+
372
+ it 'should not have any error' do
373
+ expect(@empty_transaction_resp).to_not include :error
374
+ expect(@rid_transaction_resp).to_not include :error
375
+ end
376
+ end
377
+
378
+ # Should return all the bank transaction payments done
379
+ describe 'Subscription payment history' do
380
+ # ================ SetUp/Config ================
381
+ before(:all) do
382
+ NitroPay.debug=true
383
+ NitroPay.test_env=true
384
+
385
+ # Test passing no RID & passing specific RID
386
+ @transaction = NitroPay::Transaction.new
387
+
388
+ # Send Unsubscribe
389
+ @transaction_resp = @transaction.payment_history
390
+ end
391
+
392
+ it 'should be an array' do
393
+ expect(@transaction_resp).to be_a Array
394
+ end
395
+
396
+ it 'should not have any error' do
397
+ expect(@transaction_resp.first).to_not include :error
398
+ end
399
+
400
+ it 'should have the valid bank_transactions_payment format on it array' do
401
+ transaction = @transaction_resp.first
402
+ valid_keys = [
403
+ :amount, :active, :brand,
404
+ :currency_iso, :status_code, :status_message,
405
+ :next_transaction_at, :created_at, :updated_at
406
+ ]
407
+
408
+ valid_keys.each {|key| expect(transaction[key]).to_not be_nil}
409
+ end
410
+ end
411
+
412
+ # Should retrieve it only bank transaction done
413
+ describe 'Non-subscription payment history' do
414
+ # ================ SetUp/Config ================
415
+ before(:all) do
416
+ NitroPay.debug=true
417
+ NitroPay.test_env=true
418
+
419
+ # Test passing no RID & passing specific RID
420
+ global_sample_transaction = get_json("#{@base_url}/api/v1/global_sample_transaction")
421
+ @transaction = NitroPay::Transaction.new rid: global_sample_transaction[:id]
422
+
423
+ # Send Unsubscribe
424
+ @transaction_resp = @transaction.payment_history
425
+ end
426
+
427
+ it 'should be a simple hash' do
428
+ expect(@transaction_resp).to be_a Hash
429
+ end
430
+
431
+ it 'should not have any error' do
432
+ expect(@transaction_resp).to_not include :error
433
+ end
434
+
435
+ it 'should have the valid bank_transactions_payment format' do
436
+ valid_keys = [
437
+ :amount, :active, :brand,
438
+ :currency_iso, :status_code, :status_message,
439
+ :created_at, :updated_at
440
+ ]
441
+
442
+ invalid_keys = [
443
+ :next_transaction_at, :recurrence_period_id
444
+ ]
445
+
446
+ valid_keys.each {|key| expect(@transaction_resp[key]).to_not be_nil}
447
+ invalid_keys.each {|key| expect(@transaction_resp[key]).to be_nil}
448
+ end
449
+ end
450
+
451
+ # Check if a subscription is up-to-date
452
+ describe 'Up-to-date subscription' do
453
+ # ================ SetUp/Config ================
454
+ before(:all) do
455
+ NitroPay.debug=true
456
+ NitroPay.test_env=true
457
+
458
+ # Test passing no RID & passing specific RID
459
+
460
+ @transaction = NitroPay::Transaction.new
461
+
462
+ # Send Unsubscribe
463
+ @transaction_resp = @transaction.up_to_date
464
+ end
465
+
466
+ it 'should be Hash' do
467
+ expect(@transaction_resp).to be_a Hash
468
+ end
469
+
470
+ it 'should be up-to-date with success message' do
471
+ expect(@transaction_resp[:success]).to_not be_nil
472
+ end
473
+
474
+ it 'should not have any error' do
475
+ expect(@transaction_resp).to_not include :error
476
+ end
477
+ end
478
+
479
+ # Check if a subscription is up-to-date
480
+ describe 'Subscription PENDING payment, not up-to-date' do
481
+ # ================ SetUp/Config ================
482
+ before(:all) do
483
+ NitroPay.debug=true
484
+ NitroPay.test_env=true
485
+
486
+ # Test pending subscription payment passing specific RID
487
+ @global_pending_subscription = get_json("#{@base_url}/api/v1/global_pending_subscription")
488
+ @transaction_with_rid = NitroPay::Transaction.new rid: @global_pending_subscription[:id]
489
+
490
+ # Send Unsubscribe
491
+ @rid_transaction_resp = @transaction_with_rid.up_to_date
492
+ end
493
+
494
+ it 'should be Hash' do
495
+ expect(@rid_transaction_resp).to be_a Hash
496
+ end
497
+
498
+ it 'should not have any error' do
499
+ expect(@rid_transaction_resp).to_not include :error
500
+ end
501
+
502
+ it 'should have the subscription' do
503
+ expect(@rid_transaction_resp[:subscription]).to_not be_nil
504
+ end
505
+ end
506
+ end
507
+ end
508
+
509
+ # incorrect Request/Params
510
+ context 'BAD REQUEST' do
511
+ # NOT_OK on the authentication Store Page tests
512
+ describe 'Authentication failing' do
513
+ # SetUp/Config
514
+ before(:all) do
515
+ NitroPay.debug = true
516
+ NitroPay.test_env = false
517
+ NitroPay.app_id = 1
518
+ NitroPay.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
519
+
520
+ amount = Random.rand(99999).to_s
521
+ amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
522
+
523
+ @store_transaction = NitroPay::Transaction.new({
524
+ card:{
525
+ brand: 'visa',
526
+ cvv: '321',
527
+ expiration_month: '05',
528
+ expiration_year: '2018',
529
+ number: '9999999999999999',
530
+ holder: Faker::Name.name,
531
+ },
532
+
533
+ amount: amount
534
+ })
535
+
536
+ # Fake SoldItems added
537
+ @store_transaction.sold_items = fake_sold_items
538
+
539
+ # Send StoreCharge
540
+ @resp = @store_transaction.charge_store
541
+ end
542
+
543
+ # ================ Tests/Expects/Should ================
544
+ it 'resp should exist (do not be empty)' do
545
+ expect(@resp).to_not be_nil
546
+ end
547
+
548
+ it 'resp should contain the RequestID' do
549
+ request_id = @resp[:request_id]
550
+ expect(request_id).to_not be_nil
551
+ expect(request_id).to be_a Integer
552
+ end
553
+
554
+ it 'resp should contain auth error' do
555
+ error = @resp[:error].downcase
556
+ expect(error).to_not be_nil
557
+ expect(error.index('auth error').nil?).to_not be_truthy
558
+ expect(error.index('AppID'.downcase).nil?).to_not be_truthy
559
+ expect(error.index('SecretKey'.downcase).nil?).to_not be_truthy
560
+ end
561
+ end
562
+ end
563
+ end
564
+
565
+ context 'Remote sample connection test' do
566
+ before(:all) do
567
+ NitroPay.debug=false
568
+ NitroPay.test_env=false
569
+ @remote = NitroPay::Status.new
570
+ end
571
+
572
+ it 'must have a JSON response' do
573
+ expect(@remote.response).to be_a Hash
574
+ end
575
+
576
+ it 'must have a message' do
577
+ expect(@remote.message).to be_a String
578
+ end
579
+
580
+ it 'must have an API code' do
581
+ expect(@remote.api_code).to be_a Integer
582
+ end
583
+ end
584
+ end