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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +1984 -0
  7. data/Rakefile +16 -0
  8. data/lib/openpay/bankaccounts.rb +58 -0
  9. data/lib/openpay/cards.rb +73 -0
  10. data/lib/openpay/charges.rb +101 -0
  11. data/lib/openpay/colombia/cards_co.rb +73 -0
  12. data/lib/openpay/colombia/charges_co.rb +76 -0
  13. data/lib/openpay/colombia/customers_co.rb +166 -0
  14. data/lib/openpay/colombia/plans_co.rb +17 -0
  15. data/lib/openpay/colombia/pse_co.rb +17 -0
  16. data/lib/openpay/colombia/subscriptions_co.rb +50 -0
  17. data/lib/openpay/colombia/tokens_co.rb +5 -0
  18. data/lib/openpay/colombia/webhooks_co.rb +5 -0
  19. data/lib/openpay/customers.rb +200 -0
  20. data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
  21. data/lib/openpay/errors/openpay_exception.rb +29 -0
  22. data/lib/openpay/errors/openpay_exception_factory.rb +56 -0
  23. data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
  24. data/lib/openpay/fees.rb +5 -0
  25. data/lib/openpay/open_pay_resource.rb +295 -0
  26. data/lib/openpay/open_pay_resource_factory.rb +17 -0
  27. data/lib/openpay/openpay_api.rb +72 -0
  28. data/lib/openpay/payouts.rb +55 -0
  29. data/lib/openpay/peru/cards_pe.rb +73 -0
  30. data/lib/openpay/peru/charges_pe.rb +76 -0
  31. data/lib/openpay/peru/checkouts_pe.rb +51 -0
  32. data/lib/openpay/peru/customers_pe.rb +79 -0
  33. data/lib/openpay/peru/tokens_pe.rb +5 -0
  34. data/lib/openpay/peru/webhooks_pe.rb +5 -0
  35. data/lib/openpay/plans.rb +17 -0
  36. data/lib/openpay/points.rb +10 -0
  37. data/lib/openpay/subscriptions.rb +50 -0
  38. data/lib/openpay/tokens.rb +7 -0
  39. data/lib/openpay/transfers.rb +39 -0
  40. data/lib/openpay/utils/country.rb +3 -0
  41. data/lib/openpay/utils/search_params.rb +24 -0
  42. data/lib/openpay/webhooks.rb +9 -0
  43. data/lib/openpay.rb +55 -0
  44. data/lib/version.rb +3 -0
  45. data/openpay.gemspec +30 -0
  46. data/test/Factories.rb +524 -0
  47. data/test/spec/bankaccounts_spec.rb +52 -0
  48. data/test/spec/cards_spec.rb +437 -0
  49. data/test/spec/charges_spec.rb +382 -0
  50. data/test/spec/colombia/cards_col_spec.rb +364 -0
  51. data/test/spec/colombia/charges_col_spec.rb +258 -0
  52. data/test/spec/colombia/customers_co_spec.rb +151 -0
  53. data/test/spec/colombia/plans_col_spec.rb +133 -0
  54. data/test/spec/colombia/pse_col_spec.rb +49 -0
  55. data/test/spec/colombia/subscriptions_col_spec.rb +230 -0
  56. data/test/spec/colombia/tokens_col_spec.rb +38 -0
  57. data/test/spec/customers_spec.rb +172 -0
  58. data/test/spec/exceptions_spec.rb +105 -0
  59. data/test/spec/fees_spec.rb +166 -0
  60. data/test/spec/openpayresource_spec.rb +54 -0
  61. data/test/spec/payouts_spec.rb +231 -0
  62. data/test/spec/peru/cards_pe_spec.rb +363 -0
  63. data/test/spec/peru/charges_pe_spec.rb +218 -0
  64. data/test/spec/peru/checkouts_pe_spec.rb +71 -0
  65. data/test/spec/peru/customers_pe_spec.rb +151 -0
  66. data/test/spec/peru/tokens_pe_spec.rb +38 -0
  67. data/test/spec/peru/webhook_pe_spec.rb +50 -0
  68. data/test/spec/plans_spec.rb +158 -0
  69. data/test/spec/points_spec.rb +26 -0
  70. data/test/spec/requesttimeout_spec.rb +22 -0
  71. data/test/spec/subscriptions_spec.rb +294 -0
  72. data/test/spec/transfers_spec.rb +219 -0
  73. data/test/spec/utils/search_params_spec.rb +36 -0
  74. data/test/spec_helper.rb +24 -0
  75. metadata +219 -0
data/test/Factories.rb ADDED
@@ -0,0 +1,524 @@
1
+ require 'factory_bot'
2
+
3
+ FactoryBot.define do
4
+
5
+ factory :customer, class: Hash do
6
+ name 'Guadalupe'
7
+ last_name 'Reyes'
8
+ email 'lupereyes@lemail.com'
9
+ phone_number '0180012345'
10
+ address { {
11
+ postal_code: '76190',
12
+ state: 'QRO',
13
+ line1: 'LINE1',
14
+ line2: 'LINE2',
15
+ line3: 'LINE3',
16
+ country_code: 'MX',
17
+ city: 'Queretaro',
18
+ } }
19
+
20
+ initialize_with { attributes }
21
+
22
+ end
23
+
24
+ factory :customer_col, class: Hash do
25
+ name 'Guadalupe'
26
+ last_name 'Reyes'
27
+ email 'lupereyes@lemail.com'
28
+ phone_number '0180012345'
29
+ customer_address { {
30
+ department: 'department',
31
+ city: 'Colombia',
32
+ additional: 'additional'
33
+ } }
34
+ initialize_with { attributes }
35
+
36
+ end
37
+
38
+ factory :valid_card, class: Hash do
39
+
40
+ bank_name 'visa'
41
+ holder_name 'Vicente Olmos'
42
+ expiration_month '09'
43
+ card_number '4111111111111111'
44
+ expiration_year '25'
45
+ bank_code 'bmx'
46
+ cvv2 '111'
47
+ address { {
48
+ postal_code: '76190',
49
+ state: 'QRO',
50
+ line1: 'LINE1',
51
+ line2: 'LINE2',
52
+ line3: 'LINE3',
53
+ country_code: 'CO',
54
+ city: 'Queretaro',
55
+ } }
56
+
57
+ initialize_with { attributes }
58
+
59
+ end
60
+
61
+ factory :valid_card_col, class: Hash do
62
+ holder_name 'Vicente Olmos'
63
+ card_number '4111111111111111'
64
+ cvv2 '111'
65
+ expiration_month '09'
66
+ expiration_year '25'
67
+ initialize_with { attributes }
68
+ end
69
+
70
+ factory :valid_card2, class: Hash do
71
+
72
+ bank_name 'visa'
73
+ holder_name 'Alma Olmos'
74
+ expiration_month '09'
75
+ card_number '4242424242424242'
76
+ expiration_year '22'
77
+ bank_code 'bmx'
78
+ cvv2 '111'
79
+ address { {
80
+ postal_code: '76190',
81
+ state: 'QRO',
82
+ line1: 'LINE1',
83
+ line2: 'LINE2',
84
+ line3: 'LINE3',
85
+ country_code: 'MX',
86
+ city: 'Queretaro',
87
+ } }
88
+
89
+ initialize_with { attributes }
90
+
91
+ end
92
+
93
+ factory :valid_card2_col, class: Hash do
94
+ holder_name 'Alma Olmos'
95
+ card_number '4242424242424242'
96
+ cvv2 '111'
97
+ expiration_month '09'
98
+ expiration_year '22'
99
+ initialize_with { attributes }
100
+ end
101
+
102
+ factory :only_deposit, class: Hash do
103
+
104
+ bank_name 'visa'
105
+ holder_name 'Alma Olmos'
106
+ expiration_month '09'
107
+ card_number '4444444444444448'
108
+ expiration_year '20'
109
+ bank_code 'bmx'
110
+ cvv2 '111'
111
+ address { {
112
+ postal_code: '76190',
113
+ state: 'QRO',
114
+ line1: 'LINE1',
115
+ line2: 'LINE2',
116
+ line3: 'LINE3',
117
+ country_code: 'MX',
118
+ city: 'Queretaro',
119
+ } }
120
+
121
+ initialize_with { attributes }
122
+
123
+ end
124
+
125
+ factory :expired_card, class: Hash do
126
+
127
+ bank_name 'visa'
128
+ holder_name 'Vicente Olmos'
129
+ expiration_month '09'
130
+ card_number '4000000000000069'
131
+ expiration_year '21'
132
+ bank_code 'bmx'
133
+ cvv2 '111'
134
+ address { {
135
+ postal_code: '76190',
136
+ state: 'QRO',
137
+ line1: 'LINE1',
138
+ line2: 'LINE2',
139
+ line3: 'LINE3',
140
+ country_code: 'MX',
141
+ city: 'Queretaro',
142
+ } }
143
+
144
+ initialize_with { attributes }
145
+
146
+ end
147
+
148
+ factory :expired_card_col, class: Hash do
149
+ holder_name 'Vicente Olmos'
150
+ card_number '4000000000000069'
151
+ cvv2 '111'
152
+ expiration_month '09'
153
+ expiration_year '21'
154
+ initialize_with { attributes }
155
+ end
156
+
157
+ factory :bank_account, class: Hash do
158
+
159
+ holder_name 'Juan Perez'
160
+ self.alias 'Cuenta principal'
161
+ clabe '032180000118359719'
162
+
163
+ initialize_with { attributes }
164
+
165
+ end
166
+
167
+ factory :card_charge, class: Hash do
168
+
169
+ amount "1000"
170
+ description "Cargo inicial a tarjeta"
171
+ source_id "string"
172
+ add_attribute :method, "card"
173
+ order_id 'required'
174
+
175
+ initialize_with { attributes }
176
+
177
+ end
178
+
179
+ factory :card_charge_col_2, class: Hash do
180
+
181
+ amount "1000"
182
+ description "Cargo inicial a tarjeta"
183
+ source_id "string"
184
+ add_attribute :method, "card"
185
+ order_id 'required'
186
+ currency 'COP'
187
+ device_session_id "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
188
+ initialize_with { attributes }
189
+
190
+ end
191
+
192
+ factory :card_charge_col, class: Hash do
193
+ amount "1000"
194
+ description "Cargo inicial a tarjeta"
195
+ source_id "string"
196
+ add_attribute :method, "card"
197
+ order_id 'required'
198
+ currency 'COP'
199
+ device_session_id "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
200
+ customer { {
201
+ name: "Cliente Colombia",
202
+ last_name: "Vazquez Juarez",
203
+ phone_number: "4448936475",
204
+ email: "juan.vazquez@empresa.co"
205
+ } }
206
+ initialize_with { attributes }
207
+ end
208
+
209
+ factory :card_charge_store_col, class: Hash do
210
+ amount "1000"
211
+ description "Cargo inicial a tarjeta"
212
+ add_attribute :method, "store"
213
+ currency 'COP'
214
+ iva '10'
215
+ customer { {
216
+ name: "Cliente Colombia",
217
+ last_name: "Vazquez Juarez",
218
+ phone_number: "4448936475",
219
+ email: "juan.vazquez@empresa.co"
220
+ } }
221
+ initialize_with { attributes }
222
+ end
223
+
224
+ factory :charge_pse_col, class: Hash do
225
+ add_attribute :method, "bank_account"
226
+ amount "1000"
227
+ currency 'COP'
228
+ description "Cargo SPE"
229
+ iva '10'
230
+ redirect_url "/"
231
+ initialize_with { attributes }
232
+ end
233
+
234
+ factory :charge_pse_new_client_col, class: Hash do
235
+ add_attribute :method, "bank_account"
236
+ amount "1000"
237
+ currency 'COP'
238
+ description "Cargo SPE"
239
+ iva '10'
240
+ redirect_url "/"
241
+ customer { {
242
+ name: "Cliente Colombia",
243
+ last_name: "Vazquez Juarez",
244
+ email: "juan.vazquez@empresa.co",
245
+ phone_number: "4448936475",
246
+ requires_account: false,
247
+ customer_address:
248
+ {
249
+ department: "Medellín",
250
+ city: "Antioquía",
251
+ additional: "Avenida 7m bis #174-25 Apartamento 637"
252
+ }
253
+ } }
254
+ initialize_with { attributes }
255
+ end
256
+
257
+ factory :card_charge_store_col_2, class: Hash do
258
+
259
+ amount "1000"
260
+ description "Cargo inicial a tarjeta"
261
+ add_attribute :method, "store"
262
+ currency 'COP'
263
+ iva '10'
264
+ initialize_with { attributes }
265
+
266
+ end
267
+
268
+ factory :bank_charge, class: Hash do
269
+
270
+ amount "10000"
271
+ description "Cargo con banco"
272
+ order_id 'required'
273
+ add_attribute :method, "bank_account"
274
+
275
+ initialize_with { attributes }
276
+
277
+ end
278
+
279
+ factory :refund_description, class: Hash do
280
+ description 'A peticion del cliente'
281
+ initialize_with { attributes }
282
+
283
+ end
284
+
285
+ factory :fee, class: Hash do
286
+ customer_id 'dvocf97jd20es3tw5laz'
287
+ amount '12.50'
288
+ description 'Cobro de Comision'
289
+ initialize_with { attributes }
290
+ end
291
+
292
+ factory :payout_card, class: Hash do
293
+
294
+ add_attribute :method, 'card'
295
+ destination_id '4444444444444448'
296
+ amount '2'
297
+ description 'Retiro de saldo semanal'
298
+
299
+ initialize_with { attributes }
300
+
301
+ end
302
+
303
+ factory :payout_bank_account, class: Hash do
304
+
305
+ add_attribute :method, 'bank_account'
306
+ amount '1000'
307
+ destination_id 'required'
308
+ description 'Retiro de saldo semanal'
309
+
310
+ initialize_with { attributes }
311
+
312
+ end
313
+
314
+ factory :plan, class: Hash do
315
+
316
+ amount '150.00'
317
+ status_after_retry 'cancelled'
318
+ retry_times 2
319
+ add_attribute :name, 'TODO INCLUIDO'
320
+ repeat_unit 'week'
321
+ trial_days 30
322
+ repeat_every 1
323
+ initialize_with { attributes }
324
+
325
+ end
326
+
327
+ factory :transfer, class: Hash do
328
+ customer_id 'required'
329
+ amount 12.50
330
+ description 'Transferencia entre cuentas'
331
+ initialize_with { attributes }
332
+ end
333
+
334
+ factory :subscription, class: Hash do
335
+ plan_id 'required'
336
+ trial_days 30
337
+ card_id 'required'
338
+ initialize_with { attributes }
339
+ end
340
+
341
+ factory :webhook1, class: Hash do
342
+ url 'https://requestb.in/15r2d5n1'
343
+ event_types ['charge.succeeded', 'charge.created', 'charge.cancelled', 'charge.failed']
344
+ initialize_with { attributes }
345
+ end
346
+
347
+ factory :webhook2, class: Hash do
348
+ url 'https://requestb.in/s3pj3ds3'
349
+ event_types ['charge.succeeded', 'charge.created', 'charge.cancelled', 'charge.failed']
350
+ initialize_with { attributes }
351
+ end
352
+
353
+ factory :token_col, class: Hash do
354
+ holder_name 'Vicente Olmos'
355
+ card_number '4111111111111111'
356
+ cvv2 '111'
357
+ expiration_month '09'
358
+ expiration_year '30'
359
+ address { {
360
+ city: 'Bogotá',
361
+ country_code: 'CO',
362
+ postal_code: '110511',
363
+ line1: 'LINE1',
364
+ line2: 'LINE2',
365
+ line3: 'LINE3',
366
+ state: 'Bogota',
367
+ } }
368
+ initialize_with { attributes }
369
+ end
370
+
371
+ # Perú
372
+ factory :customer_pe, class: Hash do
373
+ name 'Guadalupe'
374
+ last_name 'Peru'
375
+ email 'peru@lemail.com'
376
+ requires_account false
377
+ phone_number '0180012345'
378
+ customer_address { {
379
+ department: 'department',
380
+ city: 'Peru',
381
+ additional: 'additional'
382
+ } }
383
+ initialize_with { attributes }
384
+
385
+ end
386
+
387
+ factory :valid_card_peru, class: Hash do
388
+ holder_name 'Vicente Olmos'
389
+ card_number '4111111111111111'
390
+ cvv2 '111'
391
+ expiration_month '09'
392
+ expiration_year '25'
393
+ initialize_with { attributes }
394
+ end
395
+
396
+ factory :charge_redirect_peru, class: Hash do
397
+ add_attribute :method, "card"
398
+ amount 1000
399
+ currency "PEN"
400
+ description "Cargo con redireccionamiento"
401
+ confirm false
402
+ redirect_url "http://qrsof.com/test"
403
+ customer { {
404
+ name: "Cliente Colombia",
405
+ last_name: "Vazquez Juarez",
406
+ email: "juan.vazquez@empresa.co"
407
+ } }
408
+ initialize_with { attributes }
409
+ end
410
+
411
+ factory :charge_redirect_customer_peru, class: Hash do
412
+ add_attribute :method, "card"
413
+ amount 1000
414
+ currency "PEN"
415
+ description "Cargo con redireccionamiento"
416
+ confirm false
417
+ redirect_url "http://qrsof.com/test"
418
+ initialize_with { attributes }
419
+ end
420
+
421
+ factory :charge_store_peru_customer, class: Hash do
422
+ add_attribute :method, "store"
423
+ amount 1000
424
+ currency "PEN"
425
+ description "Cargo con store"
426
+ initialize_with { attributes }
427
+ end
428
+
429
+ factory :charge_store_peru_merchant, class: Hash do
430
+ add_attribute :method, "store"
431
+ amount 1000
432
+ currency "PEN"
433
+ description "Cargo con store"
434
+ customer { {
435
+ name: "Cliente Colombia",
436
+ last_name: "Vazquez Juarez",
437
+ email: "juan.vazquez@empresa.co"
438
+ } }
439
+ initialize_with { attributes }
440
+ end
441
+
442
+ factory :token_peru, class: Hash do
443
+ holder_name 'Vicente Olmos'
444
+ card_number '4111111111111111'
445
+ cvv2 '111'
446
+ expiration_month '09'
447
+ expiration_year '30'
448
+ address { {
449
+ city: 'Peru',
450
+ country_code: 'PE',
451
+ postal_code: '12312',
452
+ line1: 'line1',
453
+ line2: 'line2',
454
+ line3: 'line3',
455
+ state: 'Lima'
456
+ } }
457
+ initialize_with { attributes }
458
+ end
459
+
460
+ factory :checkou_peru, class: Hash do
461
+ amount 1000
462
+ description 'Probando checkouts'
463
+ currency "PEN"
464
+ redirect_url "http://qrsof.com/test"
465
+ initialize_with { attributes }
466
+ end
467
+
468
+ factory :checkou_peru_merchant, class: Hash do
469
+ amount 1000
470
+ description 'Probando checkouts'
471
+ currency "PEN"
472
+ redirect_url "http://qrsof.com/test"
473
+ customer { {
474
+ name: "Cliente Colombia",
475
+ last_name: "Vazquez Juarez",
476
+ email: "juan.vazquez@empresa.co",
477
+ phone_number: "4448936475"
478
+ } }
479
+ initialize_with { attributes }
480
+ end
481
+
482
+ factory :webhook_peru, class: Hash do
483
+ url "https://webhook.site/4c73409c-8b7e-4e97-9448-654409859b00"
484
+ user 'user'
485
+ password "password"
486
+ event_types ["charge.refunded","charge.failed","charge.cancelled","charge.created","chargeback.accepted"]
487
+ initialize_with { attributes }
488
+ end
489
+
490
+ factory :valid_card2_pe, class: Hash do
491
+ holder_name 'Alma Olmos'
492
+ card_number '4242424242424242'
493
+ cvv2 '111'
494
+ expiration_month '09'
495
+ expiration_year '22'
496
+ initialize_with { attributes }
497
+ end
498
+
499
+ factory :charge_pe, class: Hash do
500
+ source_id 'source_id'
501
+ add_attribute :method, "card"
502
+ amount 716
503
+ currency 'PEN'
504
+ description 'Probando cargos'
505
+ device_session_id 'device_session_id'
506
+ initialize_with { attributes }
507
+ end
508
+
509
+ factory :charge_merchant_pe, class: Hash do
510
+ source_id 'source_id'
511
+ add_attribute :method, "card"
512
+ amount 716
513
+ currency 'PEN'
514
+ description 'Probando cargos'
515
+ device_session_id 'device_session_id'
516
+ customer { {
517
+ name: "Cliente peru",
518
+ email: "juan.vazquez@empresa.pe"
519
+ } }
520
+ initialize_with { attributes }
521
+ end
522
+
523
+
524
+ end
@@ -0,0 +1,52 @@
1
+ require_relative '../spec_helper'
2
+
3
+
4
+ describe Bankaccounts do
5
+
6
+ #bankaccounts for merchant cannot be created using the api
7
+ #the merchant bank account should be created using the Openpay dashboard
8
+ before(:all) do
9
+
10
+ @merchant_id='mywvupjjs9xdnryxtplq'
11
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
12
+
13
+ #LOG.level=Logger::DEBUG
14
+
15
+
16
+ @openpay=OpenpayApi.new(@merchant_id, @private_key)
17
+ @bank_accounts=@openpay.create(:bankaccounts)
18
+ @customers=@openpay.create(:customers)
19
+
20
+ end
21
+
22
+ it 'has all required methods' do
23
+ %w(all each create get list delete).each do |meth|
24
+ expect(@bank_accounts).to respond_to(meth)
25
+ end
26
+ end
27
+ describe '.list' do
28
+
29
+ it 'list the bank accounts using a creation_gte filter' do
30
+
31
+ customer_hash= FactoryBot.build(:customer)
32
+ customer=@customers.create(customer_hash)
33
+ bank_accounts = @bank_accounts.all(customer['id'])
34
+ expect(bank_accounts.size).to be 0
35
+
36
+ account_hash=FactoryBot.build(:bank_account)
37
+ bank=@bank_accounts.create(account_hash, customer['id'])
38
+ expect(@bank_accounts.all(customer['id']).size).to be 1
39
+
40
+ search_params = OpenpayUtils::SearchParams.new
41
+ search_params.limit = 1
42
+ search_params.creation_gte = '2000-01-01'
43
+
44
+ expect(@bank_accounts.all(customer['id']).size).to eq 1
45
+ expect(@bank_accounts.list(search_params , customer['id']).size).to eq 1
46
+
47
+ @bank_accounts.delete(customer['id'], bank['id'])
48
+ @customers.delete(customer['id'])
49
+
50
+ end
51
+ end
52
+ end