nitro_pay 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/lib/nitro_pay.rb +1 -1
- data/lib/nitro_pay/connection.rb +3 -3
- data/lib/nitro_pay/hash.rb +1 -1
- data/lib/nitro_pay/transaction.rb +31 -25
- data/lib/nitro_pay/version.rb +1 -1
- data/spec/helpers.rb +2 -2
- data/spec/nitro_pay/transaction_spec.rb +192 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77f963c8478e8be1c91f4120954b3602262a06da
|
4
|
+
data.tar.gz: b55a4fa43bac405b7088fac7ae9754e2fdb97cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1eb5f5fa34e0fec7f107137f48ac8c784c8e794a7fe872f459a99ce6338ecf1ae67898e0ddb155b0d7410fa130c1b8776cfa22986545f286b813e65084cb1c6
|
7
|
+
data.tar.gz: 0f639803d3c1c941afd6a8046fe37bef400c127ebb6caa53406a4b8d3ad73ad6ab4d459dd8f91870be492a184442e43aeaf13aaa3fe68313ecd573d7005e7a6e
|
data/lib/nitro_pay.rb
CHANGED
data/lib/nitro_pay/connection.rb
CHANGED
@@ -7,7 +7,7 @@ module NitroPay
|
|
7
7
|
attr_accessor :protocol
|
8
8
|
attr_accessor :end_point
|
9
9
|
attr_accessor :api_version
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :recurrent_tid
|
11
11
|
attr_accessor :request_params
|
12
12
|
attr_accessor :end_point_versioned
|
13
13
|
|
@@ -39,7 +39,7 @@ module NitroPay
|
|
39
39
|
# Dynamic env
|
40
40
|
setup_default_app if params[:test_env]
|
41
41
|
setup_attrs(params)
|
42
|
-
self.
|
42
|
+
self.recurrent_tid = params[:tid] unless params[:tid].nil?
|
43
43
|
end
|
44
44
|
|
45
45
|
# Full URL for the last request
|
@@ -114,7 +114,7 @@ module NitroPay
|
|
114
114
|
# Get the GlobalRecurrent & setup/config
|
115
115
|
self.path = 'global_subscription'
|
116
116
|
recurrence = get_json_request
|
117
|
-
self.
|
117
|
+
self.recurrent_tid = recurrence[:tid]
|
118
118
|
|
119
119
|
return puts 'Please run: rails g nitro_pay:install' if NitroPay.app_id.nil? || NitroPay.secret_key.nil?
|
120
120
|
self.auth = {app_id:NitroPay.app_id, secret_key:NitroPay.secret_key}
|
data/lib/nitro_pay/hash.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module NitroPay
|
2
2
|
# Transaction Obj, but can Abstract nested objs like Costumer
|
3
3
|
class Transaction < NitroPay::Connection
|
4
|
+
attr_accessor :tid
|
4
5
|
attr_accessor :resp
|
5
6
|
attr_accessor :status # can be API Status: self.status = NitroPay::Status.new OR/AND Transaction Status
|
6
7
|
attr_accessor :sold_items
|
@@ -12,24 +13,24 @@ module NitroPay
|
|
12
13
|
self.redirect_link = "#{self.end_point_versioned}/transactions" if params[:test_env]
|
13
14
|
end
|
14
15
|
|
15
|
-
# Return it RID easily
|
16
|
-
def rid
|
17
|
-
self.resp[:rid]
|
18
|
-
end
|
19
|
-
|
20
16
|
# Return it Purchase URL, to pay on the OperatorPage
|
21
|
-
def
|
22
|
-
|
17
|
+
def checkout_page_url
|
18
|
+
hash_resp[:checkout_page]
|
23
19
|
end
|
24
20
|
|
25
|
-
# GET /api/transactions/:
|
21
|
+
# GET /api/transactions/:tid by it attr
|
26
22
|
def verify
|
27
23
|
auth_hash = {}
|
24
|
+
tid = self.resp[:tid]
|
28
25
|
auth_hash[:auth] = self.request_params[:auth]
|
29
|
-
if
|
26
|
+
if tid.nil? then return {error:'TID not received'} else self.path = "transactions/#{tid}#{auth_hash.it_keys_to_get_param}" end
|
30
27
|
return self.get_json_request
|
31
28
|
end
|
32
29
|
|
30
|
+
def unformed_received_amount
|
31
|
+
NitroPay::Currency.to_operator_str self.hash_resp[:amount].to_s
|
32
|
+
end
|
33
|
+
|
33
34
|
# POST /api/transactions/page return operator page URL, like the Cielo Page
|
34
35
|
def charge_page(full_resp=false)
|
35
36
|
custom_http_params
|
@@ -37,7 +38,7 @@ module NitroPay
|
|
37
38
|
self.request_params[:transaction][:redirect_link] = "#{self.redirect_link}" if self.request_params[:transaction][:test_env]
|
38
39
|
|
39
40
|
# dynamic path (it is written when a specific method use it)
|
40
|
-
self.path = '
|
41
|
+
self.path = 'checkouts'
|
41
42
|
|
42
43
|
# using json_request because need only the answer (do not use something like it HTTP Code)
|
43
44
|
self.resp = self.post_json_request unless full_resp
|
@@ -60,10 +61,10 @@ module NitroPay
|
|
60
61
|
end
|
61
62
|
|
62
63
|
# Update the recurrence amount
|
63
|
-
def update_subscription(
|
64
|
+
def update_subscription(tid=nil, full_resp=false)
|
64
65
|
# SetUp
|
65
|
-
self.
|
66
|
-
self.path = "transactions/#{self.
|
66
|
+
self.recurrent_tid = tid if tid
|
67
|
+
self.path = "transactions/#{self.recurrent_tid}/subscription"
|
67
68
|
|
68
69
|
# Perform the request
|
69
70
|
full_resp ? self.resp = self.put_request : self.resp = self.put_json_request
|
@@ -72,11 +73,11 @@ module NitroPay
|
|
72
73
|
self.resp
|
73
74
|
end
|
74
75
|
|
75
|
-
# Stop a recurrence based on it transaction
|
76
|
-
def unsubscribe(
|
76
|
+
# Stop a recurrence based on it transaction tid
|
77
|
+
def unsubscribe(tid=nil, full_resp=false)
|
77
78
|
# SetUp
|
78
|
-
self.
|
79
|
-
self.path = "transactions/#{self.
|
79
|
+
self.recurrent_tid = tid if tid
|
80
|
+
self.path = "transactions/#{self.recurrent_tid}/subscription/unsubscribe"
|
80
81
|
|
81
82
|
# Perform the request
|
82
83
|
full_resp ? self.resp = self.delete_request : self.resp = self.delete_json_request
|
@@ -86,10 +87,10 @@ module NitroPay
|
|
86
87
|
end
|
87
88
|
|
88
89
|
# Return the payments executed for the purchase passed
|
89
|
-
def payment_history(
|
90
|
+
def payment_history(tid=nil, full_resp=false)
|
90
91
|
# SetUp
|
91
|
-
self.
|
92
|
-
self.path = "transactions/#{self.
|
92
|
+
self.recurrent_tid = tid if tid
|
93
|
+
self.path = "transactions/#{self.recurrent_tid}/subscription/payment_history"
|
93
94
|
self.path = "#{self.path}#{self.request_params.it_keys_to_get_param}"
|
94
95
|
|
95
96
|
# Perform the request
|
@@ -100,12 +101,12 @@ module NitroPay
|
|
100
101
|
end
|
101
102
|
|
102
103
|
# Check if a subscription is up-to-date or have any pending
|
103
|
-
def up_to_date(
|
104
|
+
def up_to_date(tid=nil, full_resp=false)
|
104
105
|
# SetUp
|
105
|
-
self.
|
106
|
+
self.recurrent_tid = tid if tid
|
106
107
|
|
107
108
|
# Create/customize the path & add the auth as param
|
108
|
-
self.path = "transactions/#{self.
|
109
|
+
self.path = "transactions/#{self.recurrent_tid}/subscription/up-to-date"
|
109
110
|
self.path = "#{self.path}#{self.request_params.it_keys_to_get_param}"
|
110
111
|
|
111
112
|
# Perform the request
|
@@ -115,9 +116,14 @@ module NitroPay
|
|
115
116
|
self.resp
|
116
117
|
end
|
117
118
|
|
119
|
+
# return it hash resp when resp is a string
|
120
|
+
def hash_resp
|
121
|
+
self.resp.is_a?(String) ? JSON.parse(self.resp).it_keys_to_sym : self.resp
|
122
|
+
end
|
123
|
+
|
118
124
|
# ================ STATIC methods ================
|
119
|
-
# GET /api/transactions/:
|
120
|
-
def self.find(
|
125
|
+
# GET /api/transactions/:tid by the tid passed
|
126
|
+
def self.find(tid)
|
121
127
|
end
|
122
128
|
end
|
123
129
|
end
|
data/lib/nitro_pay/version.rb
CHANGED
data/spec/helpers.rb
CHANGED
@@ -4,8 +4,8 @@ module Helpers
|
|
4
4
|
200
|
5
5
|
end
|
6
6
|
|
7
|
-
def accessible?
|
8
|
-
RestClient.proxy = NitroPay.proxy
|
7
|
+
def accessible?(url)
|
8
|
+
RestClient.proxy = NitroPay.proxy if NitroPay.proxy.index('your_login').nil?
|
9
9
|
resp = RestClient.get url
|
10
10
|
RestClient.proxy = nil
|
11
11
|
resp.code == 200 ? true : false
|
@@ -5,7 +5,8 @@ describe NitroPay::Transaction do
|
|
5
5
|
@protocol = 'http://'
|
6
6
|
@domain = 'pay.dev:4000'
|
7
7
|
@base_url = "#{@protocol}#{@domain}"
|
8
|
-
@
|
8
|
+
@redirect_link = 'http://up.nitrostart.me/campaigns/2'
|
9
|
+
@global_subscription_tid = get_json("#{@base_url}/api/v1/global_subscription")[:tid]
|
9
10
|
end
|
10
11
|
|
11
12
|
context 'Proxy' do
|
@@ -36,8 +37,8 @@ describe NitroPay::Transaction do
|
|
36
37
|
@amount = @amount.to_i
|
37
38
|
@recurrence_period = NitroPay.enum[:recurrence_periods][:monthly]
|
38
39
|
|
39
|
-
# Test passing no
|
40
|
-
transaction_params = {
|
40
|
+
# Test passing no TID & passing specific TID
|
41
|
+
transaction_params = {tid: 1, amount: @amount, recurrence_period: @recurrence_period}
|
41
42
|
@transaction = NitroPay::Transaction.new transaction_params
|
42
43
|
|
43
44
|
# Send subscription update
|
@@ -68,20 +69,20 @@ describe NitroPay::Transaction do
|
|
68
69
|
NitroPay.app_id = 1
|
69
70
|
NitroPay.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
70
71
|
|
71
|
-
# Test passing no
|
72
|
-
@
|
72
|
+
# Test passing no TID & passing specific TID
|
73
|
+
@transaction_with_tid = NitroPay::Transaction.new tid: 1
|
73
74
|
|
74
75
|
# Send Unsubscribe
|
75
|
-
@
|
76
|
-
@transaction_full_resp = @
|
76
|
+
@tid_transaction_resp = @transaction_with_tid.unsubscribe
|
77
|
+
@transaction_full_resp = @transaction_with_tid.unsubscribe nil, true
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'should be Hash' do
|
80
|
-
expect(@
|
81
|
+
expect(@tid_transaction_resp).to be_a Hash
|
81
82
|
end
|
82
83
|
|
83
84
|
it 'should not have an error' do
|
84
|
-
expect(@
|
85
|
+
expect(@tid_transaction_resp).to include :error
|
85
86
|
end
|
86
87
|
|
87
88
|
it 'should resp with SUCCESS (200)' do
|
@@ -143,19 +144,34 @@ describe NitroPay::Transaction do
|
|
143
144
|
expect(status[:msg].index('Capturada').nil?).to_not be_truthy
|
144
145
|
end
|
145
146
|
|
146
|
-
it 'resp should have a full CardObj which is allowed to be stored {:
|
147
|
+
it 'resp should have a full CardObj which is allowed to be stored {:tid, :truncated, :brand}' do
|
147
148
|
card = @resp[:card]
|
148
|
-
expect(card[:
|
149
|
-
expect(card[:
|
149
|
+
expect(card[:tid]).to be_a Integer
|
150
|
+
expect(card[:tid] == 0).to_not be_truthy
|
150
151
|
expect(card[:brand]).to eq('visa')
|
151
152
|
expect(card[:truncated].index('***')).to_not be_nil
|
152
153
|
end
|
153
154
|
|
154
|
-
it 'resp should have the remote reference (
|
155
|
-
|
156
|
-
expect(
|
157
|
-
expect(
|
158
|
-
expect(
|
155
|
+
it 'resp should have the remote reference (TransactionTID)' do
|
156
|
+
tid = @resp[:tid]
|
157
|
+
expect(tid).to_not be_nil
|
158
|
+
expect(tid).to be_a Integer
|
159
|
+
expect(tid != 0).to be_truthy
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'verifiable trasaction' do
|
163
|
+
before(:all) do
|
164
|
+
@verified = @store_transaction.verify
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'resp must be a charged status' do
|
168
|
+
expect(@verified[:status][:code]).to eq(6)
|
169
|
+
expect(@verified[:status][:name]).to eq('charged')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'resp must have an array of sold_items' do
|
173
|
+
expect(@verified[:sold_items]).to be_a_kind_of Array
|
174
|
+
end
|
159
175
|
end
|
160
176
|
end
|
161
177
|
|
@@ -208,18 +224,18 @@ describe NitroPay::Transaction do
|
|
208
224
|
expect(status[:msg].index('não').nil?).to_not be_truthy
|
209
225
|
end
|
210
226
|
|
211
|
-
it 'resp should have a full CardObj which is allowed to be stored {:
|
227
|
+
it 'resp should have a full CardObj which is allowed to be stored {:tid, :truncated, :brand}' do
|
212
228
|
card = @resp[:card]
|
213
|
-
expect(card[:
|
229
|
+
expect(card[:tid]).to be_nil
|
214
230
|
expect(card[:brand]).to eq('visa')
|
215
231
|
expect(card[:truncated].index('***')).to_not be_nil
|
216
232
|
end
|
217
233
|
|
218
|
-
it 'resp should have the remote reference (
|
219
|
-
|
220
|
-
expect(
|
221
|
-
expect(
|
222
|
-
expect(
|
234
|
+
it 'resp should have the remote reference (TransactionTID)' do
|
235
|
+
tid = @resp[:tid]
|
236
|
+
expect(tid).to_not be_nil
|
237
|
+
expect(tid).to be_a Integer
|
238
|
+
expect(tid != 0).to be_truthy
|
223
239
|
end
|
224
240
|
end
|
225
241
|
|
@@ -272,19 +288,19 @@ describe NitroPay::Transaction do
|
|
272
288
|
expect(status[:msg].index('Capturada').nil?).to_not be_truthy
|
273
289
|
end
|
274
290
|
|
275
|
-
it 'resp should have a full CardObj which is allowed to be stored {:
|
291
|
+
it 'resp should have a full CardObj which is allowed to be stored {:tid, :truncated, :brand}' do
|
276
292
|
card = @resp[:card]
|
277
|
-
expect(card[:
|
278
|
-
expect(card[:
|
293
|
+
expect(card[:tid]).to be_a Integer
|
294
|
+
expect(card[:tid] == 0).to_not be_truthy
|
279
295
|
expect(card[:brand]).to eq('visa')
|
280
296
|
expect(card[:truncated].index('***')).to_not be_nil
|
281
297
|
end
|
282
298
|
|
283
|
-
it 'resp should have the remote reference (
|
284
|
-
|
285
|
-
expect(
|
286
|
-
expect(
|
287
|
-
expect(
|
299
|
+
it 'resp should have the remote reference (TransactionTID)' do
|
300
|
+
tid = @resp[:tid]
|
301
|
+
expect(tid).to_not be_nil
|
302
|
+
expect(tid).to be_a Integer
|
303
|
+
expect(tid != 0).to be_truthy
|
288
304
|
end
|
289
305
|
end
|
290
306
|
|
@@ -301,20 +317,20 @@ describe NitroPay::Transaction do
|
|
301
317
|
@amount = @amount.to_i
|
302
318
|
@recurrence_period = NitroPay.enum[:recurrence_periods][:monthly]
|
303
319
|
|
304
|
-
# Test passing no
|
320
|
+
# Test passing no TID & passing specific TID
|
305
321
|
transaction_params = {amount: @amount, recurrence_period: @recurrence_period}
|
306
322
|
@empty_transaction = NitroPay::Transaction.new transaction_params
|
307
|
-
transaction_params[:
|
308
|
-
@
|
323
|
+
transaction_params[:tid] = @global_subscription_tid
|
324
|
+
@transaction_with_tid = NitroPay::Transaction.new transaction_params
|
309
325
|
|
310
326
|
# Send subscription update
|
311
327
|
@empty_transaction_resp = @empty_transaction.update_subscription
|
312
|
-
@
|
328
|
+
@tid_transaction_resp = @transaction_with_tid.update_subscription
|
313
329
|
end
|
314
330
|
|
315
331
|
it 'should be Hash' do
|
316
332
|
expect(@empty_transaction_resp).to be_a Hash
|
317
|
-
expect(@
|
333
|
+
expect(@tid_transaction_resp).to be_a Hash
|
318
334
|
end
|
319
335
|
|
320
336
|
it 'should be performed the unsubscribe' do
|
@@ -328,9 +344,9 @@ describe NitroPay::Transaction do
|
|
328
344
|
expect(resp_recurrence_period).to eq(@recurrence_period)
|
329
345
|
|
330
346
|
# SetUpVars
|
331
|
-
|
332
|
-
resp_amount =
|
333
|
-
resp_recurrence_period =
|
347
|
+
tid_subscription_resp = @tid_transaction_resp[:subscription]
|
348
|
+
resp_amount = tid_subscription_resp[:amount]
|
349
|
+
resp_recurrence_period = tid_subscription_resp[:recurrence_period]
|
334
350
|
|
335
351
|
# test those attrs
|
336
352
|
expect(resp_amount).to eq(@amount)
|
@@ -339,7 +355,7 @@ describe NitroPay::Transaction do
|
|
339
355
|
|
340
356
|
it 'should not have any error' do
|
341
357
|
expect(@empty_transaction_resp).to_not include :error
|
342
|
-
expect(@
|
358
|
+
expect(@tid_transaction_resp).to_not include :error
|
343
359
|
end
|
344
360
|
end
|
345
361
|
|
@@ -350,28 +366,28 @@ describe NitroPay::Transaction do
|
|
350
366
|
NitroPay.debug=true
|
351
367
|
NitroPay.test_env=true
|
352
368
|
|
353
|
-
# Test passing no
|
369
|
+
# Test passing no TID & passing specific TID
|
354
370
|
@empty_transaction = NitroPay::Transaction.new
|
355
|
-
@
|
371
|
+
@transaction_with_tid = NitroPay::Transaction.new tid: @global_subscription_tid
|
356
372
|
|
357
373
|
# Send Unsubscribe
|
358
374
|
@empty_transaction_resp = @empty_transaction.unsubscribe
|
359
|
-
@
|
375
|
+
@tid_transaction_resp = @transaction_with_tid.unsubscribe
|
360
376
|
end
|
361
377
|
|
362
378
|
it 'should be Hash' do
|
363
379
|
expect(@empty_transaction_resp).to be_a Hash
|
364
|
-
expect(@
|
380
|
+
expect(@tid_transaction_resp).to be_a Hash
|
365
381
|
end
|
366
382
|
|
367
383
|
it 'should be performed the unsubscribe' do
|
368
384
|
expect(@empty_transaction_resp[:did_unsubscribe]).to be_truthy
|
369
|
-
expect(@
|
385
|
+
expect(@tid_transaction_resp[:did_unsubscribe]).to be_truthy
|
370
386
|
end
|
371
387
|
|
372
388
|
it 'should not have any error' do
|
373
389
|
expect(@empty_transaction_resp).to_not include :error
|
374
|
-
expect(@
|
390
|
+
expect(@tid_transaction_resp).to_not include :error
|
375
391
|
end
|
376
392
|
end
|
377
393
|
|
@@ -382,7 +398,7 @@ describe NitroPay::Transaction do
|
|
382
398
|
NitroPay.debug=true
|
383
399
|
NitroPay.test_env=true
|
384
400
|
|
385
|
-
# Test passing no
|
401
|
+
# Test passing no TID & passing specific TID
|
386
402
|
@transaction = NitroPay::Transaction.new
|
387
403
|
|
388
404
|
# Send Unsubscribe
|
@@ -416,9 +432,9 @@ describe NitroPay::Transaction do
|
|
416
432
|
NitroPay.debug=true
|
417
433
|
NitroPay.test_env=true
|
418
434
|
|
419
|
-
# Test passing no
|
435
|
+
# Test passing no TID & passing specific TID
|
420
436
|
global_sample_transaction = get_json("#{@base_url}/api/v1/global_sample_transaction")
|
421
|
-
@transaction = NitroPay::Transaction.new
|
437
|
+
@transaction = NitroPay::Transaction.new tid: global_sample_transaction[:id]
|
422
438
|
|
423
439
|
# Send Unsubscribe
|
424
440
|
@transaction_resp = @transaction.payment_history
|
@@ -455,7 +471,7 @@ describe NitroPay::Transaction do
|
|
455
471
|
NitroPay.debug=true
|
456
472
|
NitroPay.test_env=true
|
457
473
|
|
458
|
-
# Test passing no
|
474
|
+
# Test passing no TID & passing specific TID
|
459
475
|
|
460
476
|
@transaction = NitroPay::Transaction.new
|
461
477
|
|
@@ -483,24 +499,24 @@ describe NitroPay::Transaction do
|
|
483
499
|
NitroPay.debug=true
|
484
500
|
NitroPay.test_env=true
|
485
501
|
|
486
|
-
# Test pending subscription payment passing specific
|
502
|
+
# Test pending subscription payment passing specific TID
|
487
503
|
@global_pending_subscription = get_json("#{@base_url}/api/v1/global_pending_subscription")
|
488
|
-
@
|
504
|
+
@transaction_with_tid = NitroPay::Transaction.new tid: @global_pending_subscription[:id]
|
489
505
|
|
490
506
|
# Send Unsubscribe
|
491
|
-
@
|
507
|
+
@tid_transaction_resp = @transaction_with_tid.up_to_date
|
492
508
|
end
|
493
509
|
|
494
510
|
it 'should be Hash' do
|
495
|
-
expect(@
|
511
|
+
expect(@tid_transaction_resp).to be_a Hash
|
496
512
|
end
|
497
513
|
|
498
514
|
it 'should not have any error' do
|
499
|
-
expect(@
|
515
|
+
expect(@tid_transaction_resp).to_not include :error
|
500
516
|
end
|
501
517
|
|
502
518
|
it 'should have the subscription' do
|
503
|
-
expect(@
|
519
|
+
expect(@tid_transaction_resp[:subscription]).to_not be_nil
|
504
520
|
end
|
505
521
|
end
|
506
522
|
end
|
@@ -562,6 +578,125 @@ describe NitroPay::Transaction do
|
|
562
578
|
end
|
563
579
|
end
|
564
580
|
|
581
|
+
context 'BuyCheckoutPage' do
|
582
|
+
# correct Request/Params
|
583
|
+
context 'SUCCESS' do
|
584
|
+
# Create CheckoutPage
|
585
|
+
describe 'Create CheckoutPage' do
|
586
|
+
# ================ SetUp/Config ================
|
587
|
+
before(:all) do
|
588
|
+
NitroPay.debug=true
|
589
|
+
NitroPay.test_env=true
|
590
|
+
|
591
|
+
# To test it as CAPTURED it mustn't have cents or invalid credit card number!?
|
592
|
+
amount = Random.rand(99999).to_s
|
593
|
+
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
594
|
+
|
595
|
+
# Forcing formatted amount to check if the GEM is sending it with Operator format
|
596
|
+
amount.insert amount.length-2, ','
|
597
|
+
|
598
|
+
@checkout_page_params = {
|
599
|
+
title: 'Alfred Robots',
|
600
|
+
amount: Random.rand(99999).to_s,
|
601
|
+
redirect_link: @redirect_link,
|
602
|
+
brand: 'https://s3-sa-east-1.amazonaws.com/global-defaults/nitropay/alfred.png',
|
603
|
+
alert: 'Atenção. Você está comprando Créditos para serem usados quando este produto for lançado.',
|
604
|
+
description: 'Seu Robô Doméstico de baixo custo, alta eficiência e mais prático.'
|
605
|
+
}
|
606
|
+
|
607
|
+
# Perform it page_checkout request
|
608
|
+
@checkout_transaction = NitroPay::Transaction.new(@checkout_page_params)
|
609
|
+
@full_resp = @checkout_transaction.charge_page(full_resp=true)
|
610
|
+
@resp = JSON.parse(@full_resp).it_keys_to_sym
|
611
|
+
end
|
612
|
+
|
613
|
+
# ================ Tests/Expects/Should ================
|
614
|
+
it 'resp should not be null' do
|
615
|
+
expect(@resp).to_not be_nil
|
616
|
+
end
|
617
|
+
|
618
|
+
it 'resp should contain the RequestID' do
|
619
|
+
request_id = @resp[:request_id]
|
620
|
+
expect(request_id).to_not be_nil
|
621
|
+
expect(request_id).to be_a Integer
|
622
|
+
end
|
623
|
+
|
624
|
+
it 'resp must have a checkout_page url' do
|
625
|
+
checkout_page = @checkout_transaction.checkout_page_url
|
626
|
+
expect(checkout_page).to_not be_nil
|
627
|
+
expect(accessible?(checkout_page)).to be_truthy
|
628
|
+
end
|
629
|
+
|
630
|
+
it 'resp must contain the TID attr' do
|
631
|
+
tid = @checkout_transaction.tid
|
632
|
+
expect(@resp).to include(:tid)
|
633
|
+
expect(tid).to eq(@resp[:tid])
|
634
|
+
end
|
635
|
+
|
636
|
+
it 'resp amount must be equals the sent value' do
|
637
|
+
amount = @resp[:amount]
|
638
|
+
unformed_received_amount = @checkout_transaction.unformed_received_amount
|
639
|
+
expect(unformed_received_amount).to eq(@checkout_page_params[:amount])
|
640
|
+
end
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
# incorrect Request/Params
|
645
|
+
context 'BAD REQUEST' do
|
646
|
+
# NOT_OK on the authentication Store Page tests
|
647
|
+
describe 'Authentication failing' do
|
648
|
+
# SetUp/Config
|
649
|
+
before(:all) do
|
650
|
+
NitroPay.debug = true
|
651
|
+
NitroPay.test_env = false
|
652
|
+
NitroPay.app_id = 1
|
653
|
+
NitroPay.secret_key = '12312321312$2a$10$NmV9EysKVLe8ItBdl9CHN.LF05bOuDdoOkmfptdbJs7cuaDWksuUu'
|
654
|
+
|
655
|
+
amount = Random.rand(99999).to_s
|
656
|
+
amount = "#{amount}00" if amount[amount.length-2, amount.length] != '00'
|
657
|
+
|
658
|
+
@store_transaction = NitroPay::Transaction.new({
|
659
|
+
card:{
|
660
|
+
brand: 'visa',
|
661
|
+
cvv: '321',
|
662
|
+
expiration_month: '05',
|
663
|
+
expiration_year: '2018',
|
664
|
+
number: '9999999999999999',
|
665
|
+
holder: Faker::Name.name,
|
666
|
+
},
|
667
|
+
|
668
|
+
amount: amount
|
669
|
+
})
|
670
|
+
|
671
|
+
# Fake SoldItems added
|
672
|
+
@store_transaction.sold_items = fake_sold_items
|
673
|
+
|
674
|
+
# Send StoreCharge
|
675
|
+
@resp = @store_transaction.charge_store
|
676
|
+
end
|
677
|
+
|
678
|
+
# ================ Tests/Expects/Should ================
|
679
|
+
it 'resp should exist (do not be empty)' do
|
680
|
+
expect(@resp).to_not be_nil
|
681
|
+
end
|
682
|
+
|
683
|
+
it 'resp should contain the RequestID' do
|
684
|
+
request_id = @resp[:request_id]
|
685
|
+
expect(request_id).to_not be_nil
|
686
|
+
expect(request_id).to be_a Integer
|
687
|
+
end
|
688
|
+
|
689
|
+
it 'resp should contain auth error' do
|
690
|
+
error = @resp[:error].downcase
|
691
|
+
expect(error).to_not be_nil
|
692
|
+
expect(error.index('auth error').nil?).to_not be_truthy
|
693
|
+
expect(error.index('AppID'.downcase).nil?).to_not be_truthy
|
694
|
+
expect(error.index('SecretKey'.downcase).nil?).to_not be_truthy
|
695
|
+
end
|
696
|
+
end
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
565
700
|
context 'Remote sample connection test' do
|
566
701
|
before(:all) do
|
567
702
|
NitroPay.debug=false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nitro_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilton Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|