openpay_copemx 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +6 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +13 -0
- data/README.md +1984 -0
- data/Rakefile +16 -0
- data/lib/openpay/bankaccounts.rb +58 -0
- data/lib/openpay/cards.rb +73 -0
- data/lib/openpay/charges.rb +101 -0
- data/lib/openpay/colombia/cards_co.rb +73 -0
- data/lib/openpay/colombia/charges_co.rb +76 -0
- data/lib/openpay/colombia/customers_co.rb +166 -0
- data/lib/openpay/colombia/plans_co.rb +17 -0
- data/lib/openpay/colombia/pse_co.rb +17 -0
- data/lib/openpay/colombia/subscriptions_co.rb +50 -0
- data/lib/openpay/colombia/tokens_co.rb +5 -0
- data/lib/openpay/colombia/webhooks_co.rb +5 -0
- data/lib/openpay/customers.rb +200 -0
- data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
- data/lib/openpay/errors/openpay_exception.rb +29 -0
- data/lib/openpay/errors/openpay_exception_factory.rb +56 -0
- data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
- data/lib/openpay/fees.rb +5 -0
- data/lib/openpay/open_pay_resource.rb +295 -0
- data/lib/openpay/open_pay_resource_factory.rb +17 -0
- data/lib/openpay/openpay_api.rb +72 -0
- data/lib/openpay/payouts.rb +55 -0
- data/lib/openpay/peru/cards_pe.rb +73 -0
- data/lib/openpay/peru/charges_pe.rb +76 -0
- data/lib/openpay/peru/checkouts_pe.rb +51 -0
- data/lib/openpay/peru/customers_pe.rb +79 -0
- data/lib/openpay/peru/tokens_pe.rb +5 -0
- data/lib/openpay/peru/webhooks_pe.rb +5 -0
- data/lib/openpay/plans.rb +17 -0
- data/lib/openpay/points.rb +10 -0
- data/lib/openpay/subscriptions.rb +50 -0
- data/lib/openpay/tokens.rb +7 -0
- data/lib/openpay/transfers.rb +39 -0
- data/lib/openpay/utils/country.rb +3 -0
- data/lib/openpay/utils/search_params.rb +24 -0
- data/lib/openpay/webhooks.rb +9 -0
- data/lib/openpay.rb +55 -0
- data/lib/version.rb +3 -0
- data/openpay.gemspec +30 -0
- data/test/Factories.rb +524 -0
- data/test/spec/bankaccounts_spec.rb +52 -0
- data/test/spec/cards_spec.rb +437 -0
- data/test/spec/charges_spec.rb +382 -0
- data/test/spec/colombia/cards_col_spec.rb +364 -0
- data/test/spec/colombia/charges_col_spec.rb +258 -0
- data/test/spec/colombia/customers_co_spec.rb +151 -0
- data/test/spec/colombia/plans_col_spec.rb +133 -0
- data/test/spec/colombia/pse_col_spec.rb +49 -0
- data/test/spec/colombia/subscriptions_col_spec.rb +230 -0
- data/test/spec/colombia/tokens_col_spec.rb +38 -0
- data/test/spec/customers_spec.rb +172 -0
- data/test/spec/exceptions_spec.rb +105 -0
- data/test/spec/fees_spec.rb +166 -0
- data/test/spec/openpayresource_spec.rb +54 -0
- data/test/spec/payouts_spec.rb +231 -0
- data/test/spec/peru/cards_pe_spec.rb +363 -0
- data/test/spec/peru/charges_pe_spec.rb +218 -0
- data/test/spec/peru/checkouts_pe_spec.rb +71 -0
- data/test/spec/peru/customers_pe_spec.rb +151 -0
- data/test/spec/peru/tokens_pe_spec.rb +38 -0
- data/test/spec/peru/webhook_pe_spec.rb +50 -0
- data/test/spec/plans_spec.rb +158 -0
- data/test/spec/points_spec.rb +26 -0
- data/test/spec/requesttimeout_spec.rb +22 -0
- data/test/spec/subscriptions_spec.rb +294 -0
- data/test/spec/transfers_spec.rb +219 -0
- data/test/spec/utils/search_params_spec.rb +36 -0
- data/test/spec_helper.rb +24 -0
- metadata +219 -0
@@ -0,0 +1,437 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Cards do
|
4
|
+
|
5
|
+
# %w(create delete get list each all fail).each do |meth|
|
6
|
+
# end
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
|
10
|
+
@merchant_id = 'mywvupjjs9xdnryxtplq'
|
11
|
+
@private_key = 'sk_92b25d3baec149e6b428d81abfe37006'
|
12
|
+
|
13
|
+
#LOG.level=Logger::DEBUG
|
14
|
+
|
15
|
+
@openpay = OpenpayApi.new(@merchant_id, @private_key)
|
16
|
+
@cards = @openpay.create(:cards)
|
17
|
+
@customers = @openpay.create(:customers)
|
18
|
+
|
19
|
+
@cards.delete_all
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:all) do
|
24
|
+
#each test should build and clean it's own mess.
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has all required methods' do
|
28
|
+
%w(all each create get list delete).each do |meth|
|
29
|
+
expect(@cards).to respond_to(meth)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.create' do
|
34
|
+
|
35
|
+
it 'creates merchant card' do
|
36
|
+
|
37
|
+
#creates merchant card
|
38
|
+
card_hash = FactoryBot.build(:valid_card)
|
39
|
+
cards = @cards.create(card_hash)
|
40
|
+
expect(cards).to be_a(Hash)
|
41
|
+
|
42
|
+
id = cards['id']
|
43
|
+
name = 'Vicente Olmos'
|
44
|
+
|
45
|
+
#perform check
|
46
|
+
card = @cards.get(id)
|
47
|
+
expect(card['holder_name']).to match(name)
|
48
|
+
expect(card['card_number']).to match('1111')
|
49
|
+
|
50
|
+
#cleanup
|
51
|
+
@cards.delete(card['id'])
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'creates a customer card' do
|
56
|
+
|
57
|
+
#creates a customer
|
58
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
59
|
+
customers = @openpay.create(:customers)
|
60
|
+
customer_hash = FactoryBot.build(:customer)
|
61
|
+
customer = customers.create(customer_hash)
|
62
|
+
|
63
|
+
#creates a customer card
|
64
|
+
cards = @cards.create(card_hash, customer['id'])
|
65
|
+
expect(cards).to be_a(Hash)
|
66
|
+
|
67
|
+
id = cards['id']
|
68
|
+
|
69
|
+
#performs check
|
70
|
+
customer_cards = customers.all_cards(customer['id'])
|
71
|
+
expect(customer_cards.size).to be 1
|
72
|
+
expect(cards['holder_name']).to match 'Pepe'
|
73
|
+
|
74
|
+
stored_card = @cards.get(id, customer['id'])
|
75
|
+
expect(stored_card['holder_name']).to match 'Pepe'
|
76
|
+
expect(stored_card['id']).to match id
|
77
|
+
|
78
|
+
#cleanup
|
79
|
+
@cards.delete(id, customer['id'])
|
80
|
+
@customers.delete(customer['id'])
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'create an existing merchant card' do
|
85
|
+
|
86
|
+
#creates merchant card
|
87
|
+
card_hash = FactoryBot.build(:valid_card)
|
88
|
+
|
89
|
+
card = @cards.create(card_hash)
|
90
|
+
#cleanup
|
91
|
+
@cards.delete(card['id'])
|
92
|
+
|
93
|
+
card = @cards.create(card_hash)
|
94
|
+
#cleanup
|
95
|
+
@cards.delete(card['id'])
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'trying to create an existing customer card' do
|
100
|
+
|
101
|
+
#creates a customer
|
102
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
103
|
+
customers = @openpay.create(:customers)
|
104
|
+
customer_hash = FactoryBot.build(:customer)
|
105
|
+
customer = customers.create(customer_hash)
|
106
|
+
|
107
|
+
#creates a customer card
|
108
|
+
card = @cards.create(card_hash, customer['id'])
|
109
|
+
expect(card).to be_a(Hash)
|
110
|
+
|
111
|
+
#cleanup
|
112
|
+
@cards.delete(card['id'], customer['id'])
|
113
|
+
@customers.delete(customer['id'])
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'fails when using an expired card' do
|
118
|
+
card_hash = FactoryBot.build(:expired_card)
|
119
|
+
#check
|
120
|
+
expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
|
121
|
+
#extended check
|
122
|
+
begin
|
123
|
+
@cards.create(card_hash)
|
124
|
+
rescue OpenpayTransactionException => e
|
125
|
+
expect(e.description).to match 'The card has expired'
|
126
|
+
expect(e.error_code).to be 3002
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'fails when using a stolen card' do
|
132
|
+
card_json = FactoryBot.build(:valid_card, card_number: '4000000000000119')
|
133
|
+
expect { @cards.create(card_json) }.to raise_error(OpenpayTransactionException)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '.each' do
|
139
|
+
|
140
|
+
it 'iterates over all existing merchant cards' do
|
141
|
+
@cards.each do |card|
|
142
|
+
expect(card['expiration_year']).to match '20'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'iterates over all existing customer cards' do
|
147
|
+
|
148
|
+
#creates a customer
|
149
|
+
card_hash = FactoryBot.build(:valid_card, holder_name: 'Pepe')
|
150
|
+
customers = @openpay.create(:customers)
|
151
|
+
customer_hash = FactoryBot.build(:customer)
|
152
|
+
customer = customers.create(customer_hash)
|
153
|
+
|
154
|
+
#creates a customer card
|
155
|
+
card = @cards.create(card_hash, customer['id'])
|
156
|
+
expect(card).to be_a(Hash)
|
157
|
+
|
158
|
+
@cards.each(customer['id']) do |c|
|
159
|
+
expect(c['expiration_year']).to match '25'
|
160
|
+
end
|
161
|
+
|
162
|
+
#cleanup
|
163
|
+
@cards.delete(card['id'], customer['id'])
|
164
|
+
@customers.delete(customer['id'])
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '.delete' do
|
171
|
+
|
172
|
+
it 'deletes a merchant card' do
|
173
|
+
|
174
|
+
#creates merchant card
|
175
|
+
card_hash = FactoryBot.build(:valid_card)
|
176
|
+
cards = @cards.create(card_hash)
|
177
|
+
expect(cards).to be_a(Hash)
|
178
|
+
|
179
|
+
id = cards['id']
|
180
|
+
name = 'Vicente Olmos'
|
181
|
+
|
182
|
+
#perform check
|
183
|
+
card = @cards.delete(id)
|
184
|
+
expect { @cards.get(id) }.to raise_exception(OpenpayTransactionException)
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'fails to deletes a non existing card' do
|
189
|
+
expect { @cards.delete('1111111') }.to raise_exception(OpenpayTransactionException)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'deletes a customer card' do
|
193
|
+
|
194
|
+
#create customer
|
195
|
+
customers = @openpay.create(:customers)
|
196
|
+
customer_hash = FactoryBot.build(:customer, name: 'Juan', last_name: 'Paez')
|
197
|
+
customer = customers.create(customer_hash)
|
198
|
+
|
199
|
+
#create customer card
|
200
|
+
card_hash = FactoryBot.build(:valid_card)
|
201
|
+
card = @cards.create(card_hash, customer['id'])
|
202
|
+
|
203
|
+
#delete card
|
204
|
+
@cards.delete(card['id'], customer['id'])
|
205
|
+
|
206
|
+
#perform check
|
207
|
+
expect { @cards.get(card['id'], customer['id']) }.to raise_exception(OpenpayTransactionException)
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'fails to deletes a non existing customer card' do
|
212
|
+
expect { @cards.delete('1111111', '1111') }.to raise_exception(OpenpayTransactionException)
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '.get' do
|
218
|
+
|
219
|
+
it ' gets an existing merchant card' do
|
220
|
+
|
221
|
+
#create merchant card
|
222
|
+
bank_name = 'Banamex'
|
223
|
+
card_hash = FactoryBot.build(:valid_card)
|
224
|
+
|
225
|
+
card = @cards.create(card_hash)
|
226
|
+
id = card['id']
|
227
|
+
|
228
|
+
#pass just a single parameter for getting merchant cards
|
229
|
+
stored_card = @cards.get(id)
|
230
|
+
bank = stored_card['bank_name']
|
231
|
+
expect(bank).to match bank_name
|
232
|
+
|
233
|
+
#cleanup
|
234
|
+
@cards.delete(id)
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'fails when getting a non existing card' do
|
239
|
+
expect { @cards.get('11111') }.to raise_exception(OpenpayTransactionException)
|
240
|
+
end
|
241
|
+
|
242
|
+
it ' gets an existing customer card' do
|
243
|
+
|
244
|
+
#create customer
|
245
|
+
customer_hash = FactoryBot.build(:customer)
|
246
|
+
customer = @customers.create(customer_hash)
|
247
|
+
|
248
|
+
#creates card
|
249
|
+
bank_name = 'Banamex'
|
250
|
+
card_hash = FactoryBot.build(:valid_card)
|
251
|
+
card = @cards.create(card_hash, customer['id'])
|
252
|
+
id = card['id']
|
253
|
+
|
254
|
+
#two parameters for getting customer cards
|
255
|
+
stored_cards = @cards.get(id, customer['id'])
|
256
|
+
bank = stored_cards['bank_name']
|
257
|
+
|
258
|
+
#perform check
|
259
|
+
expect(bank).to match bank_name
|
260
|
+
|
261
|
+
#cleanup
|
262
|
+
@cards.delete(id, customer['id'])
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'fails when getting a non existing customer card' do
|
267
|
+
expect { @cards.get('11111', '1111') }.to raise_exception(OpenpayTransactionException)
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
describe '.all' do
|
273
|
+
|
274
|
+
it 'all merchant cards' do
|
275
|
+
|
276
|
+
#check initial state
|
277
|
+
expect(@cards.all.size).to be 0
|
278
|
+
|
279
|
+
#create merchant card
|
280
|
+
card_hash = FactoryBot.build(:valid_card)
|
281
|
+
card = @cards.create(card_hash)
|
282
|
+
id = card['id']
|
283
|
+
|
284
|
+
#perform check
|
285
|
+
expect(@cards.all.size).to be 1
|
286
|
+
|
287
|
+
#cleanup
|
288
|
+
@cards.delete(id)
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'all customer cards' do
|
293
|
+
|
294
|
+
#create customer
|
295
|
+
customer_hash = FactoryBot.build(:customer)
|
296
|
+
customer = @customers.create(customer_hash)
|
297
|
+
|
298
|
+
#check initial state
|
299
|
+
expect(@cards.all(customer['id']).size).to be 0
|
300
|
+
|
301
|
+
#create customer card
|
302
|
+
card_hash = FactoryBot.build(:valid_card)
|
303
|
+
card = @cards.create(card_hash, customer['id'])
|
304
|
+
id = card['id']
|
305
|
+
|
306
|
+
#perform check
|
307
|
+
expect(@cards.all(customer['id']).size).to be 1
|
308
|
+
|
309
|
+
#cleanup
|
310
|
+
@cards.delete(id, customer['id'])
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'cards for a non existing customer' do
|
315
|
+
expect { @cards.all('111111') }.to raise_exception OpenpayTransactionException
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
describe '.list' do
|
321
|
+
|
322
|
+
it 'list the merchant cards using a filter' do
|
323
|
+
|
324
|
+
#create merchant card
|
325
|
+
card_hash = FactoryBot.build(:valid_card)
|
326
|
+
card1 = @cards.create(card_hash)
|
327
|
+
|
328
|
+
card_hash = FactoryBot.build(:valid_card2)
|
329
|
+
card2 = @cards.create(card_hash)
|
330
|
+
|
331
|
+
search_params = OpenpayUtils::SearchParams.new
|
332
|
+
search_params.limit = 1
|
333
|
+
expect(@cards.list(search_params).size).to eq 1
|
334
|
+
@cards.delete_all
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'list the customer cards using a filter' do
|
338
|
+
|
339
|
+
#create customer
|
340
|
+
customer_hash = FactoryBot.build(:customer)
|
341
|
+
customer = @customers.create(customer_hash)
|
342
|
+
|
343
|
+
#creates card
|
344
|
+
bank_name = 'Banamex'
|
345
|
+
card_hash = FactoryBot.build(:valid_card)
|
346
|
+
card = @cards.create(card_hash, customer['id'])
|
347
|
+
id = card['id']
|
348
|
+
|
349
|
+
#creates card 2
|
350
|
+
bank_name = 'Bancomer'
|
351
|
+
card_hash = FactoryBot.build(:valid_card2)
|
352
|
+
card = @cards.create(card_hash, customer['id'])
|
353
|
+
id = card['id']
|
354
|
+
|
355
|
+
search_params = OpenpayUtils::SearchParams.new
|
356
|
+
search_params.limit = 1
|
357
|
+
|
358
|
+
expect(@cards.all(customer['id']).size).to eq 2
|
359
|
+
expect(@cards.list(search_params, customer['id']).size).to eq 1
|
360
|
+
|
361
|
+
@cards.delete_all(customer['id'])
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'list the merchant cards using a filter creation and amount' do
|
366
|
+
#create merchant card
|
367
|
+
card_hash = FactoryBot.build(:valid_card)
|
368
|
+
card1 = @cards.create(card_hash)
|
369
|
+
card_hash = FactoryBot.build(:valid_card2)
|
370
|
+
card2 = @cards.create(card_hash)
|
371
|
+
search_params = OpenpayUtils::SearchParams.new
|
372
|
+
search_params.limit = 1
|
373
|
+
creation_date = "2013-11-01"
|
374
|
+
search_params.creation_gte = creation_date
|
375
|
+
expect(@cards.list(search_params).size).to eq 1
|
376
|
+
@cards.delete_all
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
describe '.delete_all' do
|
381
|
+
|
382
|
+
it 'raise an exception when used on Production' do
|
383
|
+
|
384
|
+
openpayprod = OpenpayApi.new(@merchant_id, @private_key, true, "mx")
|
385
|
+
cust = openpayprod.create(:customers)
|
386
|
+
expect { cust.delete_all }.to raise_error
|
387
|
+
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'deletes all existing merchant cards' do
|
391
|
+
|
392
|
+
#create merchant card
|
393
|
+
card_hash = FactoryBot.build(:valid_card)
|
394
|
+
@cards.create(card_hash)
|
395
|
+
|
396
|
+
#using json just for fun ...and test
|
397
|
+
card2_json = FactoryBot.build(:valid_card2).to_json
|
398
|
+
@cards.create(card2_json)
|
399
|
+
|
400
|
+
#perform check
|
401
|
+
expect(@cards.all.size).to be 2
|
402
|
+
|
403
|
+
#cleanup
|
404
|
+
@cards.delete_all
|
405
|
+
|
406
|
+
#perform check
|
407
|
+
expect(@cards.all.size).to be 0
|
408
|
+
|
409
|
+
end
|
410
|
+
|
411
|
+
it 'deletes all existing cards for a given customer' do
|
412
|
+
|
413
|
+
#creates customer
|
414
|
+
customer_hash = FactoryBot.build(:customer)
|
415
|
+
customer = @customers.create(customer_hash)
|
416
|
+
|
417
|
+
#check initial state
|
418
|
+
expect(@cards.all(customer['id']).size).to be 0
|
419
|
+
|
420
|
+
#create card
|
421
|
+
card_hash = FactoryBot.build(:valid_card)
|
422
|
+
card = @cards.create(card_hash, customer['id'])
|
423
|
+
|
424
|
+
#perform check
|
425
|
+
expect(@cards.all(customer['id']).size).to be 1
|
426
|
+
|
427
|
+
#cleanup
|
428
|
+
@cards.delete_all(customer['id'])
|
429
|
+
|
430
|
+
#check
|
431
|
+
expect(@cards.all(customer['id']).size).to be 0
|
432
|
+
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|