openpay 1.0.7 → 2.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 +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/Gemfile +2 -2
- data/README.md +25 -25
- data/Rakefile +2 -1
- data/lib/openpay.rb +3 -0
- data/lib/openpay/open_pay_resource.rb +40 -9
- data/lib/openpay/points.rb +10 -0
- data/lib/openpay/tokens.rb +7 -0
- data/lib/openpay/utils/search_params.rb +4 -1
- data/lib/openpay/webhooks.rb +9 -0
- data/lib/version.rb +1 -1
- data/openpay.gemspec +6 -6
- data/test/Factories.rb +30 -16
- data/test/spec/bankaccounts_spec.rb +44 -17
- data/test/spec/cards_spec.rb +52 -39
- data/test/spec/charges_spec.rb +48 -71
- data/test/spec/customers_spec.rb +15 -13
- data/test/spec/exceptions_spec.rb +4 -20
- data/test/spec/fees_spec.rb +24 -18
- data/test/spec/openpayresource_spec.rb +4 -2
- data/test/spec/payouts_spec.rb +41 -44
- data/test/spec/plans_spec.rb +16 -10
- data/test/spec/points_spec.rb +26 -0
- data/test/spec/requesttimeout_spec.rb +2 -0
- data/test/spec/subscriptions_spec.rb +39 -36
- data/test/spec/transfers_spec.rb +37 -31
- data/test/spec/utils/search_params_spec.rb +1 -1
- data/test/spec_helper.rb +10 -2
- metadata +41 -49
@@ -10,6 +10,8 @@ describe Bankaccounts do
|
|
10
10
|
@merchant_id='mywvupjjs9xdnryxtplq'
|
11
11
|
@private_key='sk_92b25d3baec149e6b428d81abfe37006'
|
12
12
|
|
13
|
+
#LOG.level=Logger::DEBUG
|
14
|
+
|
13
15
|
@openpay=OpenpayApi.new(@merchant_id, @private_key)
|
14
16
|
@bank_accounts=@openpay.create(:bankaccounts)
|
15
17
|
@customers=@openpay.create(:customers)
|
@@ -21,18 +23,43 @@ describe Bankaccounts do
|
|
21
23
|
expect(@bank_accounts).to respond_to(meth)
|
22
24
|
end
|
23
25
|
end
|
26
|
+
describe '.list' do
|
27
|
+
|
28
|
+
it 'list the bank accounts using a creation_gte filter' do
|
29
|
+
|
30
|
+
customer_hash= FactoryBot.build(:customer)
|
31
|
+
customer=@customers.create(customer_hash)
|
32
|
+
expect(@bank_accounts.all(customer['id']).size).to be 0
|
33
|
+
|
34
|
+
account_hash=FactoryBot.build(:bank_account)
|
35
|
+
bank=@bank_accounts.create(account_hash, customer['id'])
|
36
|
+
expect(@bank_accounts.all(customer['id']).size).to be 1
|
37
|
+
|
38
|
+
search_params = OpenpayUtils::SearchParams.new
|
39
|
+
search_params.limit = 1
|
40
|
+
search_params.creation_gte = '2000-01-01'
|
24
41
|
|
42
|
+
expect(@bank_accounts.all(customer['id']).size).to eq 1
|
43
|
+
expect(@bank_accounts.list(search_params , customer['id']).size).to eq 1
|
44
|
+
|
45
|
+
@bank_accounts.delete(customer['id'], bank['id'])
|
46
|
+
@customers.delete(customer['id'])
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
=begin
|
25
51
|
describe '.create' do
|
26
52
|
|
27
53
|
it 'creates a customer bank account' do
|
28
|
-
|
54
|
+
|
55
|
+
customer_hash= FactoryBot.build(:customer)
|
29
56
|
customer=@customers.create(customer_hash)
|
30
|
-
|
31
|
-
account_hash=
|
57
|
+
|
58
|
+
account_hash=FactoryBot.build(:bank_account)
|
32
59
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
33
60
|
|
34
61
|
bank_account=@bank_accounts.get(customer['id'], bank['id'])
|
35
|
-
expect(bank_account['alias']).to match
|
62
|
+
expect(bank_account['alias']).to match "Cuenta principal"
|
36
63
|
|
37
64
|
@bank_accounts.delete(customer['id'], bank['id'])
|
38
65
|
@customers.delete(customer['id'])
|
@@ -40,15 +67,14 @@ describe Bankaccounts do
|
|
40
67
|
end
|
41
68
|
|
42
69
|
end
|
43
|
-
|
44
70
|
describe '.get' do
|
45
71
|
|
46
72
|
it 'get a given bank account for a given customer' do
|
47
73
|
|
48
|
-
customer_hash=
|
74
|
+
customer_hash= FactoryBot.build(:customer)
|
49
75
|
customer=@customers.create(customer_hash)
|
50
76
|
|
51
|
-
account_hash=
|
77
|
+
account_hash=FactoryBot.build(:bank_account)
|
52
78
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
53
79
|
|
54
80
|
bank_account=@bank_accounts.get(customer['id'], bank['id'])
|
@@ -64,10 +90,10 @@ describe Bankaccounts do
|
|
64
90
|
|
65
91
|
it 'iterator for all given customer bank accounts' do
|
66
92
|
|
67
|
-
customer_hash=
|
93
|
+
customer_hash= FactoryBot.build(:customer)
|
68
94
|
customer=@customers.create(customer_hash)
|
69
95
|
|
70
|
-
account_hash=
|
96
|
+
account_hash=FactoryBot.build(:bank_account)
|
71
97
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
72
98
|
|
73
99
|
@bank_accounts.each(customer['id']) do |bank_account|
|
@@ -85,11 +111,11 @@ describe Bankaccounts do
|
|
85
111
|
|
86
112
|
it 'list the bank accounts using a given filter' do
|
87
113
|
|
88
|
-
customer_hash=
|
114
|
+
customer_hash= FactoryBot.build(:customer)
|
89
115
|
customer=@customers.create(customer_hash)
|
90
116
|
expect(@bank_accounts.all(customer['id']).size).to be 0
|
91
117
|
|
92
|
-
account_hash=
|
118
|
+
account_hash=FactoryBot.build(:bank_account)
|
93
119
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
94
120
|
expect(@bank_accounts.all(customer['id']).size).to be 1
|
95
121
|
|
@@ -109,11 +135,11 @@ describe Bankaccounts do
|
|
109
135
|
|
110
136
|
it 'all bank accounts for a given customer' do
|
111
137
|
|
112
|
-
customer_hash=
|
138
|
+
customer_hash= FactoryBot.build(:customer)
|
113
139
|
customer=@customers.create(customer_hash)
|
114
140
|
expect(@bank_accounts.all(customer['id']).size).to be 0
|
115
141
|
|
116
|
-
account_hash=
|
142
|
+
account_hash=FactoryBot.build(:bank_account)
|
117
143
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
118
144
|
expect(@bank_accounts.all(customer['id']).size).to be 1
|
119
145
|
|
@@ -132,11 +158,11 @@ describe Bankaccounts do
|
|
132
158
|
|
133
159
|
it 'deletes a given bank account' do
|
134
160
|
|
135
|
-
customer_hash=
|
161
|
+
customer_hash= FactoryBot.build(:customer)
|
136
162
|
customer=@customers.create(customer_hash)
|
137
163
|
expect(@bank_accounts.all(customer['id']).size).to be 0
|
138
164
|
|
139
|
-
account_hash=
|
165
|
+
account_hash=FactoryBot.build(:bank_account)
|
140
166
|
bank=@bank_accounts.create(account_hash, customer['id'])
|
141
167
|
expect(@bank_accounts.all(customer['id']).size).to be 1
|
142
168
|
|
@@ -155,10 +181,10 @@ describe Bankaccounts do
|
|
155
181
|
|
156
182
|
it 'deletes all bank accounts' do
|
157
183
|
|
158
|
-
customer_hash=
|
184
|
+
customer_hash= FactoryBot.build(:customer)
|
159
185
|
customer=@customers.create(customer_hash)
|
160
186
|
|
161
|
-
account_hash=
|
187
|
+
account_hash=FactoryBot.build(:bank_account)
|
162
188
|
|
163
189
|
@bank_accounts.create(account_hash, customer['id'])
|
164
190
|
expect(@bank_accounts.all(customer['id']).size).to be 1
|
@@ -177,4 +203,5 @@ describe Bankaccounts do
|
|
177
203
|
end
|
178
204
|
|
179
205
|
end
|
206
|
+
=end
|
180
207
|
end
|
data/test/spec/cards_spec.rb
CHANGED
@@ -10,6 +10,8 @@ describe Cards do
|
|
10
10
|
|
11
11
|
@merchant_id='mywvupjjs9xdnryxtplq'
|
12
12
|
@private_key='sk_92b25d3baec149e6b428d81abfe37006'
|
13
|
+
|
14
|
+
#LOG.level=Logger::DEBUG
|
13
15
|
|
14
16
|
@openpay=OpenpayApi.new(@merchant_id, @private_key)
|
15
17
|
@cards=@openpay.create(:cards)
|
@@ -34,7 +36,7 @@ describe Cards do
|
|
34
36
|
it 'creates merchant card' do
|
35
37
|
|
36
38
|
#creates merchant card
|
37
|
-
card_hash =
|
39
|
+
card_hash = FactoryBot.build(:valid_card)
|
38
40
|
cards=@cards.create(card_hash)
|
39
41
|
expect(cards).to be_a(Hash)
|
40
42
|
|
@@ -54,9 +56,9 @@ describe Cards do
|
|
54
56
|
it 'creates a customer card' do
|
55
57
|
|
56
58
|
#creates a customer
|
57
|
-
card_hash =
|
59
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
58
60
|
customers=@openpay.create(:customers)
|
59
|
-
customer_hash =
|
61
|
+
customer_hash = FactoryBot.build(:customer)
|
60
62
|
customer=customers.create(customer_hash)
|
61
63
|
|
62
64
|
#creates a customer card
|
@@ -80,35 +82,33 @@ describe Cards do
|
|
80
82
|
|
81
83
|
end
|
82
84
|
|
83
|
-
it '
|
85
|
+
it 'create an existing merchant card' do
|
84
86
|
|
85
87
|
#creates merchant card
|
86
|
-
card_hash =
|
88
|
+
card_hash = FactoryBot.build(:valid_card)
|
89
|
+
|
90
|
+
card=@cards.create(card_hash)
|
91
|
+
#cleanup
|
92
|
+
@cards.delete(card['id'])
|
93
|
+
|
87
94
|
card=@cards.create(card_hash)
|
88
|
-
|
89
|
-
#perform check
|
90
|
-
expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
|
91
|
-
|
92
95
|
#cleanup
|
93
96
|
@cards.delete(card['id'])
|
94
97
|
|
95
98
|
end
|
96
99
|
|
97
|
-
it '
|
100
|
+
it 'trying to create an existing customer card' do
|
98
101
|
|
99
102
|
#creates a customer
|
100
|
-
card_hash =
|
103
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
101
104
|
customers=@openpay.create(:customers)
|
102
|
-
customer_hash =
|
105
|
+
customer_hash = FactoryBot.build(:customer)
|
103
106
|
customer=customers.create(customer_hash)
|
104
107
|
|
105
108
|
#creates a customer card
|
106
109
|
card=@cards.create(card_hash, customer['id'])
|
107
110
|
expect(card).to be_a(Hash)
|
108
111
|
|
109
|
-
#performs check
|
110
|
-
expect { @cards.create(card_hash, customer['id']) }.to raise_error(OpenpayTransactionException)
|
111
|
-
|
112
112
|
#cleanup
|
113
113
|
@cards.delete(card['id'], customer['id'])
|
114
114
|
@customers.delete(customer['id'])
|
@@ -116,7 +116,7 @@ describe Cards do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'fails when using an expired card' do
|
119
|
-
card_hash =
|
119
|
+
card_hash = FactoryBot.build(:expired_card)
|
120
120
|
#check
|
121
121
|
expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
|
122
122
|
#extended check
|
@@ -130,7 +130,7 @@ describe Cards do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'fails when using a stolen card' do
|
133
|
-
card_json =
|
133
|
+
card_json = FactoryBot.build(:valid_card, card_number: '4000000000000119')
|
134
134
|
expect { @cards.create(card_json) }.to raise_error(OpenpayTransactionException)
|
135
135
|
end
|
136
136
|
|
@@ -140,16 +140,16 @@ describe Cards do
|
|
140
140
|
|
141
141
|
it 'iterates over all existing merchant cards' do
|
142
142
|
@cards.each do |card|
|
143
|
-
expect(card['expiration_year']).to match '
|
143
|
+
expect(card['expiration_year']).to match '20'
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'iterates over all existing customer cards' do
|
148
148
|
|
149
149
|
#creates a customer
|
150
|
-
card_hash =
|
150
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
151
151
|
customers=@openpay.create(:customers)
|
152
|
-
customer_hash =
|
152
|
+
customer_hash = FactoryBot.build(:customer)
|
153
153
|
customer=customers.create(customer_hash)
|
154
154
|
|
155
155
|
#creates a customer card
|
@@ -157,7 +157,7 @@ describe Cards do
|
|
157
157
|
expect(card).to be_a(Hash)
|
158
158
|
|
159
159
|
@cards.each(customer['id']) do |c|
|
160
|
-
expect(c['expiration_year']).to match '
|
160
|
+
expect(c['expiration_year']).to match '25'
|
161
161
|
end
|
162
162
|
|
163
163
|
#cleanup
|
@@ -173,7 +173,7 @@ describe Cards do
|
|
173
173
|
it 'deletes a merchant card' do
|
174
174
|
|
175
175
|
#creates merchant card
|
176
|
-
card_hash =
|
176
|
+
card_hash = FactoryBot.build(:valid_card)
|
177
177
|
cards=@cards.create(card_hash)
|
178
178
|
expect(cards).to be_a(Hash)
|
179
179
|
|
@@ -194,11 +194,11 @@ describe Cards do
|
|
194
194
|
|
195
195
|
#create customer
|
196
196
|
customers=@openpay.create(:customers)
|
197
|
-
customer_hash =
|
197
|
+
customer_hash = FactoryBot.build(:customer, name: 'Juan', last_name: 'Paez')
|
198
198
|
customer=customers.create(customer_hash)
|
199
199
|
|
200
200
|
#create customer card
|
201
|
-
card_hash =
|
201
|
+
card_hash = FactoryBot.build(:valid_card)
|
202
202
|
card=@cards.create(card_hash, customer['id'])
|
203
203
|
|
204
204
|
#delete card
|
@@ -221,7 +221,7 @@ describe Cards do
|
|
221
221
|
|
222
222
|
#create merchant card
|
223
223
|
bank_name='Banamex'
|
224
|
-
card_hash =
|
224
|
+
card_hash = FactoryBot.build(:valid_card)
|
225
225
|
|
226
226
|
card=@cards.create(card_hash)
|
227
227
|
id=card['id']
|
@@ -243,12 +243,12 @@ describe Cards do
|
|
243
243
|
it ' gets an existing customer card' do
|
244
244
|
|
245
245
|
#create customer
|
246
|
-
customer_hash =
|
246
|
+
customer_hash = FactoryBot.build(:customer)
|
247
247
|
customer=@customers.create(customer_hash)
|
248
248
|
|
249
249
|
#creates card
|
250
250
|
bank_name='Banamex'
|
251
|
-
card_hash =
|
251
|
+
card_hash = FactoryBot.build(:valid_card)
|
252
252
|
card=@cards.create(card_hash, customer['id'])
|
253
253
|
id=card['id']
|
254
254
|
|
@@ -278,7 +278,7 @@ describe Cards do
|
|
278
278
|
expect(@cards.all.size).to be 0
|
279
279
|
|
280
280
|
#create merchant card
|
281
|
-
card_hash =
|
281
|
+
card_hash = FactoryBot.build(:valid_card)
|
282
282
|
card=@cards.create(card_hash)
|
283
283
|
id=card['id']
|
284
284
|
|
@@ -293,14 +293,14 @@ describe Cards do
|
|
293
293
|
it 'all customer cards' do
|
294
294
|
|
295
295
|
#create customer
|
296
|
-
customer_hash =
|
296
|
+
customer_hash = FactoryBot.build(:customer)
|
297
297
|
customer=@customers.create(customer_hash)
|
298
298
|
|
299
299
|
#check initial state
|
300
300
|
expect(@cards.all(customer['id']).size).to be 0
|
301
301
|
|
302
302
|
#create customer card
|
303
|
-
card_hash =
|
303
|
+
card_hash = FactoryBot.build(:valid_card)
|
304
304
|
card=@cards.create(card_hash, customer['id'])
|
305
305
|
id=card['id']
|
306
306
|
|
@@ -323,10 +323,10 @@ describe Cards do
|
|
323
323
|
it 'list the merchant cards using a filter' do
|
324
324
|
|
325
325
|
#create merchant card
|
326
|
-
card_hash =
|
326
|
+
card_hash = FactoryBot.build(:valid_card)
|
327
327
|
card1 = @cards.create(card_hash)
|
328
328
|
|
329
|
-
card_hash =
|
329
|
+
card_hash = FactoryBot.build(:valid_card2)
|
330
330
|
card2 = @cards.create(card_hash)
|
331
331
|
|
332
332
|
search_params = OpenpayUtils::SearchParams.new
|
@@ -338,18 +338,18 @@ describe Cards do
|
|
338
338
|
it 'list the customer cards using a filter' do
|
339
339
|
|
340
340
|
#create customer
|
341
|
-
customer_hash =
|
341
|
+
customer_hash = FactoryBot.build(:customer)
|
342
342
|
customer = @customers.create(customer_hash)
|
343
343
|
|
344
344
|
#creates card
|
345
345
|
bank_name ='Banamex'
|
346
|
-
card_hash =
|
346
|
+
card_hash = FactoryBot.build(:valid_card)
|
347
347
|
card = @cards.create(card_hash, customer['id'])
|
348
348
|
id = card['id']
|
349
349
|
|
350
350
|
#creates card 2
|
351
351
|
bank_name = 'Bancomer'
|
352
|
-
card_hash =
|
352
|
+
card_hash = FactoryBot.build(:valid_card2)
|
353
353
|
card = @cards.create(card_hash, customer['id'])
|
354
354
|
id = card['id']
|
355
355
|
|
@@ -363,6 +363,19 @@ describe Cards do
|
|
363
363
|
|
364
364
|
end
|
365
365
|
|
366
|
+
it 'list the merchant cards using a filter creation and amount' do
|
367
|
+
#create merchant card
|
368
|
+
card_hash = FactoryBot.build(:valid_card)
|
369
|
+
card1 = @cards.create(card_hash)
|
370
|
+
card_hash = FactoryBot.build(:valid_card2)
|
371
|
+
card2 = @cards.create(card_hash)
|
372
|
+
search_params = OpenpayUtils::SearchParams.new
|
373
|
+
search_params.limit = 1
|
374
|
+
creation_date = "2013-11-01"
|
375
|
+
search_params.creation_gte = creation_date
|
376
|
+
expect(@cards.list(search_params).size).to eq 1
|
377
|
+
@cards.delete_all
|
378
|
+
end
|
366
379
|
end
|
367
380
|
|
368
381
|
|
@@ -379,11 +392,11 @@ describe Cards do
|
|
379
392
|
it 'deletes all existing merchant cards' do
|
380
393
|
|
381
394
|
#create merchant card
|
382
|
-
card_hash =
|
395
|
+
card_hash = FactoryBot.build(:valid_card)
|
383
396
|
@cards.create(card_hash)
|
384
397
|
|
385
398
|
#using json just for fun ...and test
|
386
|
-
card2_json =
|
399
|
+
card2_json = FactoryBot.build(:valid_card2).to_json
|
387
400
|
@cards.create(card2_json)
|
388
401
|
|
389
402
|
#perform check
|
@@ -400,14 +413,14 @@ describe Cards do
|
|
400
413
|
it 'deletes all existing cards for a given customer' do
|
401
414
|
|
402
415
|
#creates customer
|
403
|
-
customer_hash =
|
416
|
+
customer_hash = FactoryBot.build(:customer)
|
404
417
|
customer=@customers.create(customer_hash)
|
405
418
|
|
406
419
|
#check initial state
|
407
420
|
expect(@cards.all(customer['id']).size).to be 0
|
408
421
|
|
409
422
|
#create card
|
410
|
-
card_hash =
|
423
|
+
card_hash = FactoryBot.build(:valid_card)
|
411
424
|
card=@cards.create(card_hash, customer['id'])
|
412
425
|
|
413
426
|
#perform check
|
data/test/spec/charges_spec.rb
CHANGED
@@ -9,6 +9,8 @@ describe Charges do
|
|
9
9
|
|
10
10
|
@openpay=OpenpayApi.new(@merchant_id,@private_key)
|
11
11
|
@customers=@openpay.create(:customers)
|
12
|
+
|
13
|
+
#LOG.level=Logger::DEBUG
|
12
14
|
|
13
15
|
@charges=@openpay.create(:charges)
|
14
16
|
@cards=@openpay.create(:cards)
|
@@ -23,17 +25,17 @@ describe Charges do
|
|
23
25
|
expect(@charges).to respond_to(meth)
|
24
26
|
end
|
25
27
|
end
|
26
|
-
|
28
|
+
|
27
29
|
describe '.create' do
|
28
30
|
|
29
31
|
it 'creates a new merchant charge using the card method using a pre-stored card' do
|
30
32
|
|
31
33
|
#create card
|
32
|
-
card_hash=
|
34
|
+
card_hash=FactoryBot.build(:valid_card)
|
33
35
|
card=@cards.create(card_hash)
|
34
36
|
|
35
37
|
#create charge attached to prev created card
|
36
|
-
charge_hash=
|
38
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 101)
|
37
39
|
charge=@charges.create(charge_hash)
|
38
40
|
|
39
41
|
#perform check
|
@@ -48,15 +50,15 @@ describe Charges do
|
|
48
50
|
it 'creates a new customer charge using the card method using a pre-stored card' do
|
49
51
|
|
50
52
|
#create new customer
|
51
|
-
customer_hash=
|
53
|
+
customer_hash= FactoryBot.build(:customer)
|
52
54
|
customer=@customers.create(customer_hash)
|
53
55
|
|
54
56
|
#create customer card
|
55
|
-
card_hash=
|
57
|
+
card_hash=FactoryBot.build(:valid_card)
|
56
58
|
card=@cards.create(card_hash,customer['id'])
|
57
59
|
|
58
60
|
#create charge
|
59
|
-
charge_hash=
|
61
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
60
62
|
charge=@charges.create(charge_hash,customer['id'])
|
61
63
|
|
62
64
|
#perform check
|
@@ -69,30 +71,6 @@ describe Charges do
|
|
69
71
|
|
70
72
|
end
|
71
73
|
|
72
|
-
it 'creates a new customer charge using the bank_account method' do
|
73
|
-
|
74
|
-
#create new customer
|
75
|
-
customer_hash= FactoryGirl.build(:customer)
|
76
|
-
customer=@customers.create(customer_hash)
|
77
|
-
|
78
|
-
#create bank account
|
79
|
-
account_hash=FactoryGirl.build(:bank_account)
|
80
|
-
account=@bank_accounts.create(account_hash,customer['id'])
|
81
|
-
|
82
|
-
#create charge
|
83
|
-
charge_hash=FactoryGirl.build(:bank_charge, order_id: account['id'])
|
84
|
-
charge=@charges.create(charge_hash,customer['id'])
|
85
|
-
|
86
|
-
#perform check
|
87
|
-
stored_charge=@charges.get(charge['id'],customer['id'])
|
88
|
-
expect(stored_charge['amount']).to be_within(0.1).of(10000)
|
89
|
-
|
90
|
-
#clean up
|
91
|
-
@bank_accounts.delete(customer['id'],account['id'])
|
92
|
-
@customers.delete(customer['id'])
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
74
|
end
|
97
75
|
|
98
76
|
describe '.get' do
|
@@ -100,11 +78,11 @@ describe Charges do
|
|
100
78
|
it 'gets a merchant charge' do
|
101
79
|
|
102
80
|
#create card
|
103
|
-
card_hash=
|
81
|
+
card_hash=FactoryBot.build(:valid_card)
|
104
82
|
card=@cards.create(card_hash)
|
105
83
|
|
106
84
|
#create charge attached to prev created card
|
107
|
-
charge_hash=
|
85
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 505)
|
108
86
|
charge=@charges.create(charge_hash)
|
109
87
|
|
110
88
|
#perform check
|
@@ -119,15 +97,15 @@ describe Charges do
|
|
119
97
|
it 'gets a customer charge' do
|
120
98
|
|
121
99
|
#create new customer
|
122
|
-
customer_hash=
|
100
|
+
customer_hash= FactoryBot.build(:customer)
|
123
101
|
customer=@customers.create(customer_hash)
|
124
102
|
|
125
103
|
#create customer card
|
126
|
-
card_hash=
|
104
|
+
card_hash=FactoryBot.build(:valid_card)
|
127
105
|
card=@cards.create(card_hash,customer['id'])
|
128
106
|
|
129
107
|
#create charge
|
130
|
-
charge_hash=
|
108
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000)
|
131
109
|
charge=@charges.create(charge_hash,customer['id'])
|
132
110
|
|
133
111
|
#perform check
|
@@ -151,7 +129,7 @@ describe Charges do
|
|
151
129
|
|
152
130
|
it 'all customer charges' do
|
153
131
|
#create new customer
|
154
|
-
customer_hash=
|
132
|
+
customer_hash= FactoryBot.build(:customer)
|
155
133
|
customer=@customers.create(customer_hash)
|
156
134
|
|
157
135
|
expect(@charges.all(customer['id']).size).to be 0
|
@@ -166,15 +144,15 @@ describe Charges do
|
|
166
144
|
it 'captures a merchant card charge' do
|
167
145
|
|
168
146
|
#create new customer
|
169
|
-
customer_hash=
|
147
|
+
customer_hash= FactoryBot.build(:customer)
|
170
148
|
customer=@customers.create(customer_hash)
|
171
149
|
|
172
150
|
#create merchant card
|
173
|
-
card_hash=
|
151
|
+
card_hash=FactoryBot.build(:valid_card)
|
174
152
|
card=@cards.create(card_hash)
|
175
153
|
|
176
154
|
#create merchant charge
|
177
|
-
charge_hash=
|
155
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000, capture:'false')
|
178
156
|
charge=@charges.create(charge_hash)
|
179
157
|
|
180
158
|
#capture merchant charge
|
@@ -188,15 +166,15 @@ describe Charges do
|
|
188
166
|
|
189
167
|
it 'captures a customer card charge' do
|
190
168
|
#create new customer
|
191
|
-
customer_hash=
|
169
|
+
customer_hash= FactoryBot.build(:customer)
|
192
170
|
customer=@customers.create(customer_hash)
|
193
171
|
|
194
172
|
#create customer card
|
195
|
-
card_hash=
|
173
|
+
card_hash=FactoryBot.build(:valid_card)
|
196
174
|
card=@cards.create(card_hash,customer['id'])
|
197
175
|
|
198
176
|
#create charge
|
199
|
-
charge_hash=
|
177
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000,capture:'false')
|
200
178
|
charge=@charges.create(charge_hash,customer['id'])
|
201
179
|
|
202
180
|
#capture customer charge
|
@@ -215,15 +193,15 @@ describe Charges do
|
|
215
193
|
it 'confirms a capture on a merchant charge' do
|
216
194
|
|
217
195
|
#create new customer
|
218
|
-
customer_hash=
|
196
|
+
customer_hash= FactoryBot.build(:customer)
|
219
197
|
customer=@customers.create(customer_hash)
|
220
198
|
|
221
199
|
#create merchant card
|
222
|
-
card_hash=
|
200
|
+
card_hash=FactoryBot.build(:valid_card)
|
223
201
|
card=@cards.create(card_hash)
|
224
202
|
|
225
203
|
#create merchant charge
|
226
|
-
charge_hash=
|
204
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000, capture:'false')
|
227
205
|
charge=@charges.create(charge_hash)
|
228
206
|
|
229
207
|
confirm_capture_options = { transaction_id: charge['id'], amount: 100 }
|
@@ -240,15 +218,15 @@ describe Charges do
|
|
240
218
|
|
241
219
|
it 'confirms a capture on a customer charge' do
|
242
220
|
|
243
|
-
customer_hash=
|
221
|
+
customer_hash= FactoryBot.build(:customer)
|
244
222
|
customer=@customers.create(customer_hash)
|
245
223
|
|
246
224
|
#create customer card
|
247
|
-
card_hash=
|
225
|
+
card_hash=FactoryBot.build(:valid_card)
|
248
226
|
card=@cards.create(card_hash,customer['id'])
|
249
227
|
|
250
228
|
#create charge
|
251
|
-
charge_hash=
|
229
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000,capture:'false')
|
252
230
|
charge=@charges.create(charge_hash,customer['id'])
|
253
231
|
|
254
232
|
confirm_capture_options = { customer_id: customer['id'], transaction_id: charge['id'], amount: 100 }
|
@@ -270,15 +248,15 @@ describe Charges do
|
|
270
248
|
#Refunds apply only for card charges
|
271
249
|
it 'refunds an existing merchant charge' do
|
272
250
|
#create card
|
273
|
-
card_hash=
|
251
|
+
card_hash=FactoryBot.build(:valid_card)
|
274
252
|
card=@cards.create(card_hash)
|
275
253
|
|
276
254
|
#create charge attached to prev created card
|
277
|
-
charge_hash=
|
255
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'],amount: 505)
|
278
256
|
charge=@charges.create(charge_hash)
|
279
257
|
|
280
258
|
#creates refund_description
|
281
|
-
refund_description=
|
259
|
+
refund_description=FactoryBot.build(:refund_description)
|
282
260
|
expect(@charges.get(charge['id'])['refund']).to be nil
|
283
261
|
|
284
262
|
@charges.refund(charge['id'],refund_description)
|
@@ -288,35 +266,36 @@ describe Charges do
|
|
288
266
|
@cards.delete(card['id'])
|
289
267
|
|
290
268
|
end
|
291
|
-
|
269
|
+
|
292
270
|
it 'refunds an existing customer charge' do
|
293
271
|
#create new customer
|
294
|
-
customer_hash=
|
272
|
+
customer_hash= FactoryBot.build(:customer)
|
295
273
|
customer=@customers.create(customer_hash)
|
296
274
|
|
297
275
|
#create customer card
|
298
|
-
card_hash=
|
276
|
+
card_hash=FactoryBot.build(:valid_card)
|
299
277
|
card=@cards.create(card_hash,customer['id'])
|
300
278
|
|
301
279
|
#create charge
|
302
|
-
charge_hash=
|
280
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 100)
|
303
281
|
charge=@charges.create(charge_hash,customer['id'])
|
304
282
|
|
305
283
|
#creates refund_description
|
306
|
-
refund_description=
|
307
|
-
|
284
|
+
refund_description=FactoryBot.build(:refund_description)
|
308
285
|
|
309
286
|
#perform check
|
310
287
|
expect(@charges.get(charge['id'],customer['id'])['refund']).to be nil
|
288
|
+
sleep(50)
|
311
289
|
@charges.refund(charge['id'],refund_description,customer['id'])
|
312
|
-
|
290
|
+
|
291
|
+
expect(@charges.get(charge['id'],customer['id'])['refund']['amount'] ).to be_within(0.1).of(100)
|
313
292
|
|
314
293
|
#clean up
|
315
294
|
@cards.delete(card['id'],customer['id'])
|
316
295
|
@customers.delete(customer['id'])
|
317
296
|
|
318
297
|
end
|
319
|
-
|
298
|
+
|
320
299
|
end
|
321
300
|
|
322
301
|
describe '.list' do
|
@@ -324,25 +303,23 @@ describe Charges do
|
|
324
303
|
it 'list customer charges' do
|
325
304
|
|
326
305
|
#create new customer
|
327
|
-
customer_hash=
|
306
|
+
customer_hash= FactoryBot.build(:customer)
|
328
307
|
customer=@customers.create(customer_hash)
|
329
|
-
|
330
308
|
#create customer card
|
331
|
-
card_hash=
|
309
|
+
card_hash=FactoryBot.build(:valid_card)
|
332
310
|
card=@cards.create(card_hash,customer['id'])
|
333
|
-
|
334
311
|
#create charge
|
335
|
-
charge_hash=
|
312
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
336
313
|
charge=@charges.create(charge_hash,customer['id'])
|
337
|
-
charge_hash=
|
314
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id']+"1")
|
338
315
|
charge2=@charges.create(charge_hash,customer['id'])
|
339
|
-
|
340
316
|
#perform check
|
341
317
|
search_params = OpenpayUtils::SearchParams.new
|
342
318
|
search_params.limit = 1
|
319
|
+
search_params.creation_gte = '2000-01-01'
|
320
|
+
search_params.amount_gte = 1
|
343
321
|
expect(@charges.all(customer['id']).size).to eq 2
|
344
322
|
expect(@charges.list(search_params,customer['id']).size).to eq 1
|
345
|
-
|
346
323
|
#clean up
|
347
324
|
@cards.delete(card['id'],customer['id'])
|
348
325
|
@customers.delete(customer['id'])
|
@@ -363,17 +340,17 @@ describe Charges do
|
|
363
340
|
it 'iterate over customer charges' do
|
364
341
|
|
365
342
|
#create new customer
|
366
|
-
customer_hash=
|
343
|
+
customer_hash= FactoryBot.build(:customer)
|
367
344
|
customer=@customers.create(customer_hash)
|
368
345
|
|
369
346
|
#create customer card
|
370
|
-
card_hash=
|
347
|
+
card_hash=FactoryBot.build(:valid_card)
|
371
348
|
card=@cards.create(card_hash,customer['id'])
|
372
349
|
|
373
350
|
#create charge
|
374
|
-
charge_hash=
|
351
|
+
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4)
|
375
352
|
@charges.create(charge_hash,customer['id'])
|
376
|
-
charge2_hash=
|
353
|
+
charge2_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'+"2"],amount: 4)
|
377
354
|
|
378
355
|
@charges.create(charge2_hash,customer['id'])
|
379
356
|
|