openpay 1.0.3 → 1.0.4

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 (65) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +1 -0
  3. data/.idea/.rakeTasks +2 -2
  4. data/.idea/OpenPay.iml +30 -20
  5. data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +1 -0
  6. data/.idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml +1 -0
  7. data/.idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml +1 -0
  8. data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +1 -0
  9. data/.idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml +1 -0
  10. data/.idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml +1 -0
  11. data/.idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml +1 -0
  12. data/.idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml +1 -0
  13. data/.idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml +1 -0
  14. data/.idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml +1 -0
  15. data/.idea/runConfigurations/all_specs.xml +1 -0
  16. data/.idea/workspace.xml +484 -268
  17. data/Gemfile +0 -6
  18. data/README.md +111 -29
  19. data/lib/openpay.rb +7 -3
  20. data/lib/openpay/bankaccounts.rb +10 -11
  21. data/lib/openpay/cards.rb +12 -14
  22. data/lib/openpay/charges.rb +38 -14
  23. data/lib/openpay/customers.rb +73 -67
  24. data/lib/openpay/errors/openpay_exception_factory.rb +14 -26
  25. data/lib/openpay/fees.rb +1 -1
  26. data/lib/openpay/open_pay_resource.rb +77 -77
  27. data/lib/openpay/open_pay_resource_factory.rb +1 -1
  28. data/lib/openpay/openpay_api.rb +6 -16
  29. data/lib/openpay/payouts.rb +13 -17
  30. data/lib/openpay/plans.rb +1 -7
  31. data/lib/openpay/subscriptions.rb +21 -29
  32. data/lib/openpay/transfers.rb +14 -18
  33. data/lib/openpay/utils/search_params.rb +20 -0
  34. data/lib/version.rb +1 -2
  35. data/openpay.gemspec +0 -8
  36. data/test/Factories.rb +80 -126
  37. data/test/spec/bankaccounts_spec.rb +55 -61
  38. data/test/spec/cards_spec.rb +56 -76
  39. data/test/spec/charges_spec.rb +89 -84
  40. data/test/spec/customers_spec.rb +37 -47
  41. data/test/spec/exceptions_spec.rb +4 -21
  42. data/test/spec/fees_spec.rb +51 -7
  43. data/test/spec/payouts_spec.rb +102 -65
  44. data/test/spec/plans_spec.rb +27 -50
  45. data/test/spec/subscriptions_spec.rb +87 -24
  46. data/test/spec/transfers_spec.rb +42 -44
  47. data/test/spec/utils/search_params_spec.rb +36 -0
  48. data/test/spec_helper.rb +1 -5
  49. metadata +15 -55
  50. data/lib/OpenPay/Cards.rb +0 -75
  51. data/lib/OpenPay/Charges.rb +0 -77
  52. data/lib/OpenPay/Customers.rb +0 -194
  53. data/lib/OpenPay/Fees.rb +0 -5
  54. data/lib/OpenPay/Payouts.rb +0 -59
  55. data/lib/OpenPay/Plans.rb +0 -23
  56. data/lib/OpenPay/Subscriptions.rb +0 -58
  57. data/lib/OpenPay/Transfers.rb +0 -43
  58. data/lib/OpenPay/bankaccounts.rb +0 -59
  59. data/lib/OpenPay/errors/openpay_connection_exception.rb +0 -3
  60. data/lib/OpenPay/errors/openpay_exception.rb +0 -29
  61. data/lib/OpenPay/errors/openpay_exception_factory.rb +0 -60
  62. data/lib/OpenPay/errors/openpay_transaction_exception.rb +0 -5
  63. data/lib/OpenPay/open_pay_resource.rb +0 -242
  64. data/lib/OpenPay/open_pay_resource_factory.rb +0 -10
  65. data/lib/OpenPay/openpay_api.rb +0 -58
data/Gemfile CHANGED
@@ -1,14 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
-
4
3
  gem 'rspec'
5
4
  gem 'rest-client', '~>1.6.7'
6
5
  gem 'factory_girl' , '4.2.0'
7
- gem 'json_spec'
8
-
9
-
10
-
11
-
12
6
 
13
7
  # Specify your gem's dependencies in Openpay.gemspec
14
8
  gemspec
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Openpay-Ruby
1
+ <img src="http://www.openpay.mx/img/logo.png">
2
+
3
+ # Openpay-Ruby [![Build Status](https://travis-ci.org/open-pay/openpay-ruby.png?branch=master)](https://travis-ci.org/open-pay/openpay-ruby)
2
4
 
3
5
  ##Description
4
6
 
5
- ruby client for *Openpay api* services (version 1.0.3)
7
+ ruby client for *Openpay api* services (version 1.0.4)
6
8
 
7
9
  This is a ruby client implementing the payment services for *Openpay* at openpay.mx
8
10
 
@@ -275,13 +277,21 @@ open_pay_resource.delete_all(customer_id=nil)
275
277
  bank_account['alias']
276
278
  end
277
279
 
280
+ - list merchant / customer bank accounts
281
+
282
+ search_params = OpenpayUtils::SearchParams.new
283
+ search_params.limit = 1
284
+
285
+ merchant_filtered_list = bank_accounts.list(search_params)
286
+ customer_filtered_list = bank_accounts.list(search_params, customer_id)
287
+
278
288
  - all bank accounts for a given customer
279
289
 
280
- accounts=bank_accounts.all(customer_id)
290
+ accounts=bank_accounts.all(customer_id)
281
291
 
282
292
  - deletes a given customer bank account
283
293
 
284
- bank_accounts.delete(customer_id,bank_id)
294
+ bank_accounts.delete(customer_id,bank_id)
285
295
 
286
296
  - deletes all customer bank accounts (sandbox mode only)
287
297
 
@@ -309,6 +319,14 @@ open_pay_resource.delete_all(customer_id=nil)
309
319
 
310
320
  cards.each {|merchant_card| p card}
311
321
 
322
+ - list merchant / customer cards
323
+
324
+ search_params = OpenpayUtils::SearchParams.new
325
+ search_params.limit = 1
326
+
327
+ merchant_filtered_list = cards.list(search_params)
328
+ customer_filtered_list = cards.list(search_params, customer_id)
329
+
312
330
  - each customer card
313
331
 
314
332
  cards.each(customer_id) {|customer_card | p customer_card }
@@ -329,13 +347,13 @@ open_pay_resource.delete_all(customer_id=nil)
329
347
 
330
348
  cards.delete(card_id,customer_id)
331
349
 
332
- - delete all merchant cards
350
+ - delete all merchant cards
333
351
 
334
352
  cards.delete_all
335
353
 
336
- - delete all customer cards
354
+ - delete all customer cards
337
355
 
338
- cards.delete_all(customer_id)
356
+ cards.delete_all(customer_id)
339
357
 
340
358
 
341
359
  #### charges
@@ -355,24 +373,32 @@ open_pay_resource.delete_all(customer_id=nil)
355
373
 
356
374
  - gets customer charge
357
375
 
358
- customer_charge=charges.get(charge_id,customer_id)
376
+ customer_charge=charges.get(charge_id,customer_id)
359
377
 
360
378
  - each merchant charge
361
379
 
362
- charges.each {|charge| p charge}
380
+ charges.each {|charge| p charge}
381
+
382
+ - list merchant / customer charges
383
+
384
+ search_params = OpenpayUtils::SearchParams.new
385
+ search_params.limit = 1
386
+
387
+ merchant_filtered_list = charges.list(search_params)
388
+ customer_filtered_list = charges.list(search_params, customer_id)
363
389
 
364
390
  - each customer charge
365
391
 
366
- charges.each(customer_id) {|charge| p charge}
392
+ charges.each(customer_id) {|charge| p charge}
367
393
 
368
394
 
369
395
  - all merchant charge
370
396
 
371
- charges.all
397
+ charges.all
372
398
 
373
399
  - all customer charge
374
400
 
375
- charges.all(customer_id)
401
+ charges.all(customer_id)
376
402
 
377
403
  - capture merchant card
378
404
 
@@ -382,14 +408,25 @@ open_pay_resource.delete_all(customer_id=nil)
382
408
 
383
409
  charges.capture(charge['id'],customer['id'])
384
410
 
411
+ - confirm capture merchant
412
+
413
+ #pass a hash with the following options, no customer_id needed
414
+ confirm_capture_options = { transaction_id: transaction['id'], amount: 100 }
415
+ charges.confirm_capture(confirm_capture_options)
416
+
417
+ - confirm capture customer
418
+
419
+ #pass a hash with the following options, pass the customer_id
420
+ confirm_capture_options = { customer_id: customer['id'], transaction_id: charge['id'], amount: 100 }
421
+ charges.confirm_capture(confirm_capture_options)
422
+
385
423
  - refund merchant charge
386
424
 
387
425
  charges.refund(charge_id, refund_description_hash)
388
426
 
389
427
  - refund merchant charge
390
428
 
391
- charges.refund(charge_id, refund_description_hash)
392
-
429
+ charges.refund(charge_id, refund_description_hash)
393
430
 
394
431
 
395
432
  #### customers
@@ -414,19 +451,24 @@ open_pay_resource.delete_all(customer_id=nil)
414
451
 
415
452
  customers.each do {|customer| p customer }
416
453
 
417
- - list all customer
454
+ - list customers
455
+
456
+ search_params = OpenpayUtils::SearchParams.new
457
+ search_params.limit = 1
458
+
459
+ customers_filtered_list = customers.list(search_params)
418
460
 
419
- all_customers=customers.all
420
461
 
462
+ - all customer
463
+
464
+ all_customers=customers.all
421
465
 
422
466
  - delete all customers (sand box mode only)
423
467
 
424
468
  all_customers=customers.all
425
469
 
426
-
427
470
  #### fees
428
471
 
429
-
430
472
  - creates fee
431
473
 
432
474
  #In order to create a fee a charge should exists
@@ -436,6 +478,12 @@ open_pay_resource.delete_all(customer_id=nil)
436
478
 
437
479
  all_fees=fees.all
438
480
 
481
+ - list customer fees
482
+
483
+ search_params = OpenpayUtils::SearchParams.new
484
+ search_params.limit = 1
485
+
486
+ merchant_filtered_list = fees.list(search_params)
439
487
 
440
488
  #### payouts
441
489
 
@@ -445,7 +493,7 @@ open_pay_resource.delete_all(customer_id=nil)
445
493
 
446
494
  - creates a customer payout
447
495
 
448
- payouts.create(payout_hash,customer_id)
496
+ payouts.create(payout_hash,customer_id)
449
497
 
450
498
  - gets a merchant payout
451
499
 
@@ -470,7 +518,13 @@ open_pay_resource.delete_all(customer_id=nil)
470
518
 
471
519
  payouts.each(customer_id) { |payout| p payout }
472
520
 
521
+ - list merchant/customer payouts
522
+
523
+ search_params = OpenpayUtils::SearchParams.new
524
+ search_params.limit = 1
473
525
 
526
+ merchant_filtered_list = payouts.list(search_params)
527
+ customer_filtered_list = payouts.list(search_params, customer_id)
474
528
 
475
529
  #### plans
476
530
 
@@ -479,7 +533,7 @@ open_pay_resource.delete_all(customer_id=nil)
479
533
  plans.create(plan_hash)
480
534
 
481
535
 
482
- - create customer plan
536
+ - create customer plan
483
537
 
484
538
  plans.create(plan_hash,customer_id)
485
539
 
@@ -487,33 +541,42 @@ open_pay_resource.delete_all(customer_id=nil)
487
541
 
488
542
  merchant_plan=plans.get(plan_id)
489
543
 
490
- - get a customer plan
544
+ - get a customer plan
491
545
 
492
546
  customer_plan=plans.get(plan_id,customer_id)
493
547
 
494
548
 
495
- - updates a merchant plan
549
+ - updates a merchant plan
496
550
 
497
551
  plans.update(plan_hash,customer_id)
498
552
 
499
- - updates a customer plan
553
+ - updates a customer plan
500
554
 
501
555
  plans.update(plan_hash,customer_id)
502
556
 
503
- - each merchant plan
557
+ - each merchant plan
504
558
 
505
559
  plans.each do {|plan| p plan }
506
560
 
507
- - each customer plans
561
+ - each customer plans
508
562
 
509
563
  plans.each(customer_id) do {|plan| p plan }
510
564
 
511
565
 
512
- - all merchant plans
566
+ - list merchant /customer plan
567
+
568
+ search_params = OpenpayUtils::SearchParams.new
569
+ search_params.limit = 1
570
+
571
+ merchant_filtered_list = plans.list(search_params)
572
+ customer_filtered_list = plans.list(search_params, customer_id)
573
+
574
+
575
+ - all merchant plans
513
576
 
514
577
  plans.all
515
578
 
516
- - all customer plans
579
+ - all customer plans
517
580
 
518
581
  plans.all(customer_id)
519
582
 
@@ -528,6 +591,11 @@ open_pay_resource.delete_all(customer_id=nil)
528
591
 
529
592
  subscriptions.get(subscriptions_hash,customer_id)
530
593
 
594
+ - update customer subscription
595
+
596
+ subscription_update_hash={ trial_end_date: "2016-01-12" }
597
+ subscriptions.update(subscription_id,customer_id, subscription_update_hash )
598
+
531
599
  - all customer subscription
532
600
 
533
601
  subscriptions.all(customer_id)
@@ -537,6 +605,14 @@ open_pay_resource.delete_all(customer_id=nil)
537
605
 
538
606
  subscriptions.each(customer_id) {|subscription| p subscription }
539
607
 
608
+
609
+ - list customer subscriptions
610
+
611
+ search_params = OpenpayUtils::SearchParams.new
612
+ search_params.limit = 1
613
+
614
+ customer_filtered_list = subscriptions.list(search_params, customer_id)
615
+
540
616
  - deletes customer subscription
541
617
 
542
618
  subscriptions.delete(customer_id)
@@ -566,15 +642,21 @@ open_pay_resource.delete_all(customer_id=nil)
566
642
 
567
643
  transfers.each(customer_id) {|transfer| p transfer }
568
644
 
645
+ - list customer transfers
646
+
647
+ search_params = OpenpayUtils::SearchParams.new
648
+ search_params.limit = 1
649
+
650
+ customer_filtered_list = transfers.list(search_params, customer_id)
569
651
 
570
652
 
571
653
  #### Exceptions
572
654
 
573
655
  This API generates 3 different Exception classes.
574
656
 
575
- - **OpenpayException**: Generic base api exception class, for generic api exceptions.
657
+ - **OpenpayException**: Generic base API exception class, Generic API exceptions.
576
658
 
577
- - Internal server error (500 Internal Server Error)
659
+ - Internal server error (500 Internal Server Error).
578
660
  - OpenpayApi factory method, invalid resource name.
579
661
 
580
662
  Examples:
data/lib/openpay.rb CHANGED
@@ -8,10 +8,10 @@ require 'json'
8
8
  module Openpay
9
9
 
10
10
  #api setup / constants
11
- require 'openpay/openpay_api'
11
+ require 'openpay/openpay_api'
12
12
 
13
13
  #base class
14
- require 'openpay/open_pay_resource'
14
+ require 'openpay/open_pay_resource'
15
15
 
16
16
  #resource classes
17
17
  require 'openpay/bankaccounts'
@@ -25,10 +25,14 @@ module Openpay
25
25
  require 'openpay/transfers'
26
26
  require 'openpay/charges'
27
27
 
28
+ #misc
29
+ require 'openpay/utils/search_params'
30
+
28
31
  #exceptions
29
32
  require 'errors/openpay_exception_factory'
30
33
  require 'errors/openpay_exception'
31
34
  require 'errors/openpay_transaction_exception'
32
35
  require 'errors/openpay_connection_exception'
33
36
 
34
- end
37
+ include OpenpayUtils
38
+ end
@@ -1,15 +1,12 @@
1
1
  require 'open_pay_resource'
2
2
 
3
-
4
3
  class Bankaccounts < OpenPayResource
5
4
 
6
-
7
5
  def create(bank_account,customer_id)
8
6
  customers=@api_hook.create(:customers)
9
7
  customers.create_bank_account(customer_id,bank_account)
10
8
  end
11
9
 
12
-
13
10
  def get(customer_id='',bank_account=nil)
14
11
  customers=@api_hook.create(:customers)
15
12
 
@@ -21,27 +18,31 @@ class Bankaccounts < OpenPayResource
21
18
 
22
19
  end
23
20
 
24
-
25
21
  def delete(customer_id,bank_account)
26
22
  customers=@api_hook.create(:customers)
27
23
  customers.delete_bank_account(customer_id,bank_account)
28
24
  end
29
25
 
30
-
31
26
  def each(customer_id)
32
27
  customers=@api_hook.create(:customers)
33
28
  customers.each_bank_account(customer_id) do |acc|
34
29
  yield acc
35
30
  end
36
-
37
31
  end
38
32
 
39
-
40
33
  def all(customer_id)
41
- customers=@api_hook.create(:customers)
42
- customers.all_bank_accounts(customer_id)
34
+ customers=@api_hook.create(:customers)
35
+ customers.all_bank_accounts(customer_id)
43
36
  end
44
37
 
38
+ def list(search_params,customer_id=nil)
39
+ if customer_id
40
+ customers=@api_hook.create(:customers)
41
+ customers.list_bankaccounts(customer_id,search_params)
42
+ else
43
+ super search_params
44
+ end
45
+ end
45
46
 
46
47
  def delete_all(customer_id)
47
48
 
@@ -54,6 +55,4 @@ class Bankaccounts < OpenPayResource
54
55
 
55
56
  end
56
57
 
57
-
58
-
59
58
  end
data/lib/openpay/cards.rb CHANGED
@@ -2,11 +2,6 @@ require 'open_pay_resource'
2
2
 
3
3
  class Cards < OpenPayResource
4
4
 
5
- def list(creation,before,after,offset=0,limit=10)
6
-
7
- end
8
-
9
-
10
5
  def get(card='',customer_id=nil)
11
6
  if customer_id
12
7
  customers=@api_hook.create(:customers)
@@ -16,7 +11,6 @@ class Cards < OpenPayResource
16
11
  end
17
12
  end
18
13
 
19
-
20
14
  def create(card,customer_id=nil)
21
15
  if customer_id
22
16
  customers=@api_hook.create(:customers)
@@ -26,7 +20,6 @@ class Cards < OpenPayResource
26
20
  end
27
21
  end
28
22
 
29
-
30
23
  def delete(card_id,customer_id=nil)
31
24
  if customer_id
32
25
  customers=@api_hook.create(:customers)
@@ -36,7 +29,6 @@ class Cards < OpenPayResource
36
29
  end
37
30
  end
38
31
 
39
-
40
32
  def delete_all(customer_id=nil)
41
33
  if customer_id
42
34
  customers=@api_hook.create(:customers)
@@ -48,28 +40,34 @@ class Cards < OpenPayResource
48
40
  end
49
41
  end
50
42
 
51
-
52
43
  def each(customer_id=nil)
53
44
  if customer_id
54
45
  all(customer_id).each do |card|
55
46
  yield card
56
47
  end
57
48
  else
58
- all.each do |card|
59
- yield card
60
- end
49
+ all.each do |card|
50
+ yield card
51
+ end
61
52
  end
62
53
  end
63
54
 
64
-
65
55
  def all(customer_id=nil)
66
56
  if customer_id
67
57
  customers=@api_hook.create(:customers)
68
58
  customers.all_cards(customer_id)
69
59
  else
70
- super ''
60
+ super ''
71
61
  end
72
62
  end
73
63
 
64
+ def list(search_params,customer_id=nil)
65
+ if customer_id
66
+ customers=@api_hook.create(:customers)
67
+ customers.list_cards(customer_id,search_params)
68
+ else
69
+ super search_params
70
+ end
71
+ end
74
72
 
75
73
  end