mangopay 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +1 -2
  5. data/LICENSE +20 -0
  6. data/README.md +19 -90
  7. data/bin/mangopay +9 -0
  8. data/lib/generators/mangopay/install_generator.rb +60 -0
  9. data/lib/generators/templates/mangopay.rb +5 -0
  10. data/lib/mangopay.rb +94 -24
  11. data/lib/mangopay/bank_account.rb +21 -0
  12. data/lib/mangopay/client.rb +17 -0
  13. data/lib/mangopay/errors.rb +4 -0
  14. data/lib/mangopay/http_calls.rb +53 -0
  15. data/lib/mangopay/json.rb +21 -0
  16. data/lib/mangopay/legal_user.rb +14 -0
  17. data/lib/mangopay/natural_user.rb +14 -0
  18. data/lib/mangopay/payin.rb +17 -0
  19. data/lib/mangopay/payout.rb +15 -0
  20. data/lib/mangopay/resource.rb +22 -0
  21. data/lib/mangopay/transaction.rb +11 -0
  22. data/lib/mangopay/transfer.rb +4 -55
  23. data/lib/mangopay/user.rb +4 -145
  24. data/lib/mangopay/version.rb +3 -0
  25. data/lib/mangopay/wallet.rb +4 -90
  26. data/mangopay.gemspec +33 -0
  27. data/spec/lib/mangopay/bank_account_spec.rb +26 -0
  28. data/spec/lib/mangopay/client_spec.rb +27 -0
  29. data/spec/lib/mangopay/payin_spec.rb +31 -0
  30. data/spec/lib/mangopay/payout_spec.rb +24 -0
  31. data/spec/lib/mangopay/shared_resources.rb +183 -0
  32. data/spec/lib/mangopay/transaction_spec.rb +14 -0
  33. data/spec/lib/mangopay/transfer_spec.rb +25 -81
  34. data/spec/lib/mangopay/user_spec.rb +37 -103
  35. data/spec/lib/mangopay/wallet_spec.rb +24 -73
  36. data/spec/spec_helper.rb +9 -38
  37. metadata +60 -97
  38. data/CONTRIBUTING.md +0 -51
  39. data/Rakefile +0 -5
  40. data/lib/mangopay/beneficiary.rb +0 -72
  41. data/lib/mangopay/card.rb +0 -42
  42. data/lib/mangopay/contribution.rb +0 -61
  43. data/lib/mangopay/expense.rb +0 -17
  44. data/lib/mangopay/immediate_contribution.rb +0 -58
  45. data/lib/mangopay/operation.rb +0 -16
  46. data/lib/mangopay/recurrent_contribution.rb +0 -62
  47. data/lib/mangopay/ressource.rb +0 -96
  48. data/lib/mangopay/strong_authentication.rb +0 -28
  49. data/lib/mangopay/withdrawal.rb +0 -40
  50. data/lib/mangopay/withdrawal_contribution.rb +0 -32
  51. data/spec/lib/mangopay/beneficiary_spec.rb +0 -124
  52. data/spec/lib/mangopay/card_spec.rb +0 -52
  53. data/spec/lib/mangopay/contribution_spec.rb +0 -65
  54. data/spec/lib/mangopay/expense_spec.rb +0 -10
  55. data/spec/lib/mangopay/immediate_contribution_spec.rb +0 -73
  56. data/spec/lib/mangopay/operation_spec.rb +0 -8
  57. data/spec/lib/mangopay/recurrent_contribution_spec.rb +0 -55
  58. data/spec/lib/mangopay/ressource_spec.rb +0 -5
  59. data/spec/lib/mangopay/strong_authentication_spec.rb +0 -82
  60. data/spec/lib/mangopay/withdrawal_contribution_spec.rb +0 -44
  61. data/spec/lib/mangopay/withdrawal_spec.rb +0 -98
  62. data/spec/support-files/example.pem +0 -49
  63. data/spec/support-files/test_upload.gif +0 -0
  64. data/spec/support-files/test_upload.jpg +0 -0
  65. data/spec/support-files/test_upload.pdf +0 -0
  66. data/spec/support-files/test_upload.png +0 -0
@@ -0,0 +1,4 @@
1
+ module MangoPay
2
+ class Errors
3
+ end
4
+ end
@@ -0,0 +1,53 @@
1
+ module MangoPay
2
+ module HTTPCalls
3
+ module Create
4
+ module ClassMethods
5
+
6
+ def create(*id, params)
7
+ id = id.empty? ? nil : id[0]
8
+ response = MangoPay.request(:post, url(id), params)
9
+ end
10
+ end
11
+
12
+ def self.included(base)
13
+ base.extend(ClassMethods)
14
+ end
15
+ end
16
+
17
+ module Update
18
+ module ClassMethods
19
+ def update(id = nil, params = {})
20
+ response = MangoPay.request(:put, url(id), params)
21
+ end
22
+ end
23
+
24
+ def self.included(base)
25
+ base.extend(ClassMethods)
26
+ end
27
+ end
28
+
29
+ module Fetch
30
+ module ClassMethods
31
+ def fetch(id = nil, filters = {})
32
+ response = MangoPay.request(:get, url(id), filters)
33
+ end
34
+ end
35
+
36
+ def self.included(base)
37
+ base.extend(ClassMethods)
38
+ end
39
+ end
40
+
41
+ module Refund
42
+ module ClassMethods
43
+ def refund(id = nil, params = {})
44
+ MangoPay.request(:post, url(id) + '/refunds', params)
45
+ end
46
+ end
47
+
48
+ def self.included(base)
49
+ base.extend(ClassMethods)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ module MangoPay
2
+ module JSON
3
+ if MultiJson.respond_to?(:dump)
4
+ def self.dump(*args)
5
+ MultiJson.dump(*args)
6
+ end
7
+
8
+ def self.load(*args)
9
+ MultiJson.load(*args)
10
+ end
11
+ else
12
+ def self.dump(*args)
13
+ MultiJson.encode(*args)
14
+ end
15
+
16
+ def self.load(*args)
17
+ MultiJson.decode(*args)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module MangoPay
2
+ class LegalUser < User
3
+
4
+ private
5
+
6
+ def self.url(id = nil)
7
+ if id
8
+ "/v2/#{MangoPay.configuration.client_id}/users/legal/#{CGI.escape(id)}"
9
+ else
10
+ "/v2/#{MangoPay.configuration.client_id}/users/legal"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module MangoPay
2
+ class NaturalUser < User
3
+
4
+ private
5
+
6
+ def self.url(id = nil)
7
+ if id
8
+ "/v2/#{MangoPay.configuration.client_id}/users/natural/#{CGI.escape(id)}"
9
+ else
10
+ "/v2/#{MangoPay.configuration.client_id}/users/natural"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module MangoPay
2
+ class PayIn < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+ include MangoPay::HTTPCalls::Refund
5
+ module Card
6
+ class Web < Resource
7
+ include MangoPay::HTTPCalls::Create
8
+
9
+ private
10
+
11
+ def self.url(id = nil)
12
+ "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module MangoPay
2
+ class PayOut < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+
5
+ class BankWire < Resource
6
+ include MangoPay::HTTPCalls::Create
7
+
8
+ private
9
+
10
+ def self.url(id = nil)
11
+ "/v2/#{MangoPay.configuration.client_id}/payouts/bankwire"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module MangoPay
2
+ # @abstract
3
+ class Resource
4
+
5
+ protected
6
+
7
+ def self.class_name
8
+ self.name.split('::')[-1]
9
+ end
10
+
11
+ def self.url(id = nil)
12
+ if self == Resource
13
+ raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
14
+ end
15
+ if id
16
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id)}"
17
+ else
18
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module MangoPay
2
+ class Transaction < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+
5
+ private
6
+
7
+ def self.url(id)
8
+ "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(id)}/transactions"
9
+ end
10
+ end
11
+ end
@@ -1,58 +1,7 @@
1
1
  module MangoPay
2
- # The Transfer class if you want to make any transfer between two wallets
3
- class Transfer < MangoPay::Ressource
4
-
5
- # Create a transfer from one personal wallet to another wallet
6
- #
7
- # * *Args* :
8
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
- # * [Tag]
10
- # * [PayerID]
11
- # * [BeneficiaryID]
12
- # * Amount
13
- # * [ClientFeeAmount] (In preproduction environnment only, soon in production)
14
- # * [PayerWalletID]
15
- # * [BeneficiaryWalletID]
16
- # * *Returns* :
17
- # - A transfer object
18
- #
19
- def self.create(data)
20
- post_request('transfers', data)
21
- end
22
-
23
- # Get a transfer
24
- #
25
- # * *Args* :
26
- # - +tranfer_id+ -> The id of the transfer you want to retrieve
27
- # * *Returns* :
28
- # - A transfer object
29
- #
30
- def self.details(transfer_id)
31
- get_request(File.join('transfers', transfer_id.to_s))
32
- end
33
-
34
- # Refund a contribution from a personal wallet to a shared walletTransferID
35
- #
36
- # * *Args* :
37
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
38
- # * TransfertID
39
- # * UserID
40
- # * *Returns* :
41
- # - A transfer refund object
42
- #
43
- def self.refund(data)
44
- post_request(File.join('transfer-refunds'), data)
45
- end
46
-
47
- # Get a refund transfer object
48
- #
49
- # * *Args* :
50
- # - +transfer_refund_id+ -> The id of the transfer refund you want to retrieve
51
- # * *Returns* :
52
- # - A transfer refund object
53
- #
54
- def self.get_refund(transfer_refund_id)
55
- get_request(File.join('transfer-refunds', transfer_refund_id.to_s))
56
- end
2
+ class Transfer < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Fetch
5
+ include MangoPay::HTTPCalls::Refund
57
6
  end
58
7
  end
data/lib/mangopay/user.rb CHANGED
@@ -1,148 +1,7 @@
1
1
  module MangoPay
2
- # Use the User class for any operations related to the user
3
- class User < MangoPay::Ressource
4
-
5
- # Create a new user
6
- #
7
- # * *Args* :
8
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
- # * [Tag]
10
- # * [Email]
11
- # * [FirstName]
12
- # * [LastName]
13
- # * [CanRegisterMeanOfPayment] true by default
14
- # * IP
15
- # * [Birthday]
16
- # * [Password]
17
- # * *Returns* :
18
- # - A user object
19
- #
20
- def self.create(data)
21
- post_request('users', data)
22
- end
23
-
24
- # Get a user
25
- #
26
- # * *Args* :
27
- # - +user_id+ -> The id of the user you want to retrieve
28
- # * *Returns* :
29
- # - A user object
30
- #
31
- def self.details(user_id)
32
- get_request(File.join('users', user_id.to_s))
33
- end
34
-
35
- # Update a given user
36
- #
37
- # * *Args* :
38
- # - +user_id+ -> The id of the user you want to update
39
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
40
- # * [Tag]
41
- # * [Email]
42
- # * [FirstName]
43
- # * [LastName]
44
- # * [CanRegisterMeanOfPayment]
45
- # * [Password]
46
- # * *Returns* :
47
- # - A user object
48
- #
49
- def self.update(user_id, data)
50
- put_request(File.join('users', user_id.to_s), data)
51
- end
52
-
53
- # Get a list of the given user wallets
54
- #
55
- # * *Args* :
56
- # - +user_id+ -> The id of the user you want to retrieve wallets from
57
- # * *Returns* :
58
- # - An array of wallets objects
59
- #
60
- def self.get_wallets(user_id)
61
- get_request(File.join('users', user_id.to_s, 'wallets'))
62
- end
63
-
64
- # Get a list of the given user payment cards
65
- #
66
- # * *Args* :
67
- # - +user_id+ -> The id of the user you want to retrieve cards from
68
- # * *Returns* :
69
- # - An array of registered payment cards objects
70
- #
71
- def self.cards(user_id)
72
- get_request(File.join('users', user_id.to_s, 'cards'))
73
- end
74
-
75
- # Get operations associated with a user
76
- #
77
- # * *Args* :
78
- # - +user_id+ -> The id of the user you want to retrieve operations from
79
- # * *Returns* :
80
- # - An array of operations objects
81
- #
82
- def self.operations(user_id)
83
- get_request(File.join('users', user_id.to_s, 'operations'))
84
- end
85
-
86
- # Get operations from the given user personal account
87
- #
88
- # * *Args* :
89
- # - +user_id+ -> The id of the user you want to retrieve operations from
90
- # * *Returns* :
91
- # - An array of operations objects
92
- #
93
- def self.personal_operations(user_id)
94
- get_request(File.join('users', user_id.to_s, 'operations', 'personal'))
95
- end
96
-
97
- # Create a request of strong user authentication.
98
- # If a strongAuthentication object already exist for the user, this request returns the existing object.
99
- #
100
- # * *Args* :
101
- # - +user_id+ -> The id of the user you want to strongly authenticate
102
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
103
- # * [Tag]
104
- # * *Returns* :
105
- # - A Strong Authentication object
106
- #
107
- def self.create_strong_authentication(user_id, data)
108
- post_request(File.join('users', user_id.to_s, 'strongAuthentication'), data)
109
- end
110
-
111
- # Get a Strong Authentication object
112
- #
113
- # * *Args* :
114
- # - +user_id+ -> The id of the user you want to retrieve the strong authentication object from
115
- # * *Returns* :
116
- # - A Strong Authentication object
117
- #
118
- def self.get_strong_authentication(user_id)
119
- get_request(File.join('users', user_id.to_s, 'strongAuthentication'))
120
- end
121
-
122
- # Update a Strong Authentication object
123
- #
124
- # * *Args* :
125
- # - +user_id+ -> The id of the user you want to update the strong authentication object from
126
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
127
- # * [Tag]
128
- # * [IsDocumentsTransmitted]
129
- # * *Returns* :
130
- # - A Strong Authentication object
131
- #
132
- def self.update_strong_authentication(user_id, data)
133
- put_request(File.join('users', user_id.to_s, 'strongAuthentication'), data)
134
- end
135
-
136
- # Get the expense sites for a given user
137
- #
138
- # * *Args* :
139
- # - +user_id+ -> The id of the user you want to retrieve the expense sites from
140
- # - +wallet_id+ -> The id of the wallet you want to retrieve the expense sites from
141
- # * *Returns* :
142
- # - An array of expense site objects
143
- #
144
- def self.expense_sites(user_id, wallet_id)
145
- get_request(File.join('expense-sites'), "userID=#{user_id.to_s}&walletID=#{wallet_id.to_s}")
146
- end
2
+ class User < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Update
5
+ include MangoPay::HTTPCalls::Fetch
147
6
  end
148
7
  end
@@ -0,0 +1,3 @@
1
+ module MangoPay
2
+ VERSION = '3.0.0'
3
+ end
@@ -1,93 +1,7 @@
1
1
  module MangoPay
2
- class Wallet < MangoPay::Ressource
3
-
4
- # Create a Wallet
5
- #
6
- # * *Args* :
7
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
8
- # * [Tag]
9
- # * Owners (an array of user IDs, but only one is supported now)
10
- # * [Name]
11
- # * [Description]
12
- # * [RaisingGoalAmount]
13
- # * [ContributionLimitDate]
14
- # * *Returns* :
15
- # - A wallet object
16
- #
17
- def self.create(data)
18
- post_request('wallets', data)
19
- end
20
-
21
- # Get a wallet
22
- #
23
- # * *Args* :
24
- # - +wallet_id+ -> The id of the wallet you want to retrieve
25
- # * *Returns* :
26
- # - A wallet object
27
- #
28
- def self.details(wallet_id)
29
- get_request(File.join('wallets', wallet_id.to_s))
30
- end
31
-
32
- # Update a wallet
33
- #
34
- # * *Args* :
35
- # - +wallet_id+ -> The id of the wallet you want to update
36
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
37
- # * [Name]
38
- # * [Description]
39
- # * [RaisingGoalAmount]
40
- # * [SuggestedAmount]
41
- # * [ExpirationDate] [Tag]
42
- # * *Returns* :
43
- # - A wallet object
44
- #
45
- def self.update(wallet_id, data)
46
- put_request(File.join('wallets', wallet_id.to_s), data)
47
- end
48
-
49
- # Get the owners of a wallet
50
- #
51
- # * *Args* :
52
- # - +wallet_id+ -> The id of the wallet you want to retrieve the owners from
53
- # * *Returns* :
54
- # - An array of users objects
55
- #
56
- def self.get_owners(wallet_id)
57
- get_request(File.join('wallets', wallet_id.to_s, 'users'), 'owners=1')
58
- end
59
-
60
- # Get the contributors of a wallet
61
- #
62
- # * *Args* :
63
- # - +wallet_id+ -> The id of the wallet you want to retrieve the contributors from
64
- # * *Returns* :
65
- # - An array of users objects
66
- #
67
- def self.get_contributors(wallet_id)
68
- get_request(File.join('wallets', wallet_id.to_s, 'users'), 'contributors=1')
69
- end
70
-
71
- # Get the refunded users of a wallet
72
- #
73
- # * *Args* :
74
- # - +wallet_id+ -> The id of the wallet you want to refunded users the owners from
75
- # * *Returns* :
76
- # - An array of users objects
77
- #
78
- def self.get_refunded(wallet_id)
79
- get_request(File.join('wallets', wallet_id.to_s, 'users'), 'refunded=1')
80
- end
81
-
82
- # Get the operations for a given wallet
83
- #
84
- # * *Args* :
85
- # - +wallet_id+ -> The is of the wallet you want to retrieve operations from
86
- # * *Returns* :
87
- # - An array of operations objects
88
- #
89
- def self.operations(wallet_id)
90
- get_request(File.join('wallets', wallet_id.to_s, 'operations'))
91
- end
2
+ class Wallet < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Update
5
+ include MangoPay::HTTPCalls::Fetch
92
6
  end
93
7
  end