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
data/CONTRIBUTING.md DELETED
@@ -1,51 +0,0 @@
1
- # Contributing to MangoPay
2
-
3
- ## Bugs
4
- A bug is a _demonstrable problem_ that is caused by the code in the repository. Good bug reports are extremely helpful - thank you!
5
-
6
- Guidelines for bug reports:
7
-
8
- 1. **Use the GitHub issue search**: check if the issue has already been reported.
9
-
10
- 2. **Check if the issue has been fixed**: try to reproduce it using the latest `master` branch in the repository.
11
-
12
- 3. **Isolate the problem**: ideally create a [reduced test case](http://css-tricks.com/6263-reduced-test-cases/) and a live example.
13
-
14
- A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. What is your environment? What steps will reproduce the issue? What browser(s) and OS experience the problem? What would you expect to be the outcome? All these details will help people to fix any potential bugs.
15
-
16
- Example:
17
-
18
- > Short and descriptive example bug report title
19
- >
20
- > A summary of the issue and the browser/OS environment in which it occurs.
21
- > If suitable, include the steps required to reproduce the bug.
22
- >
23
- > 1. This is the first step
24
- > 2. This is the second step
25
- > 3. Further steps, etc.
26
- >
27
- > `<url>` (a link to the reduced test case)
28
- >
29
- > Screenshots of the bug. (especially if it's a visual one)
30
- >
31
- > Any other information you want to share that is relevant to the issue being reported. This might include the lines of code that you have identified as causing the bug, and potential solutions (and your opinions on their merits).
32
- **[File a bug report](https://github.com/leetchi/mangopay/issues/)**
33
-
34
- ## Pull requests
35
- Good pull requests - patches, improvements, new features - are a fantastic help. They should remain focused in scope and avoid containing unrelated commits. If your contribution involves a significant amount of work or substantial changes to any part of the project, please open an issue to discuss it first.
36
-
37
- Make sure to adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.). Please update any documentation that is relevant to the change you're making.
38
-
39
- Please follow this process; it's the best way to get your work included in the project:
40
-
41
- 1. Create a new branch based on master
42
- 2. Once you've done your first commit on the newly created branch [Open a Pull Request](http://help.github.com/send-pull-requests/) with a clear title and description of the changes you intend to do
43
- 3. Every pull request will be attributed a version number following this schema: [MAJOR_VERSION_NUMBER].[MINOR_VERSION_NUMBER].[PATCH_VERSION_NUMBER]
44
- 4. Once your pull-request is fully tested, documented, and approved by everyone working on the project you will be ask to merge it with master.
45
-
46
- You can then make your first push to production. Enjoy :-)
47
-
48
- ## Do Not
49
- Please **do not** use the issue tracker for personal support requests.
50
-
51
- Please **do not** derail or troll issues. Keep the discussion on topic and respect the opinions of others.
data/Rakefile DELETED
@@ -1,5 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- RSpec::Core::RakeTask.new(:spec)
4
-
5
- task :default => :spec
@@ -1,72 +0,0 @@
1
- module MangoPay
2
- # A beneficiary is an item who is the target of withdrawal.
3
- # It's the object that contains the bank details for a withdrawal.
4
- # A beneficiary can be linked to a user.
5
- class Beneficiary < MangoPay::Ressource
6
-
7
- # Create a beneficiary
8
- #
9
- # * *Args* :
10
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
11
- # * [Tag]
12
- # * [UserID]
13
- # * BankAccountOwnerName
14
- # * BankAccountIBAN
15
- # * BankAccountBIC
16
- # * *Returns* :
17
- # - A beneficiary object in case of success
18
- #
19
- def self.create(data)
20
- post_request('beneficiaries', data)
21
- end
22
-
23
- # Get a beneficiary
24
- #
25
- # * *Args* :
26
- # - +beneficiary_id+ -> The id of the beneficiary you want to get
27
- # * *Returns* :
28
- # - A beneficiary object if it exists
29
- #
30
- def self.details(beneficiary_id)
31
- get_request(File.join('beneficiaries', beneficiary_id.to_s))
32
- end
33
-
34
- # Create a strong authentication for a given beneficiary
35
- #
36
- # * *Args* :
37
- # - +beneficiary_id+ -> The id of the beneficiary you want strongly authenticate
38
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
39
- # * [Tag]
40
- # * *Returns* :
41
- # - A strong authentication object
42
- #
43
- def self.create_strong_authentication(beneficiary_id, data)
44
- post_request(File.join('beneficiaries', beneficiary_id.to_s, 'strongAuthentication'), data)
45
- end
46
-
47
- # Get the strong authentication for a given beneficiary
48
- #
49
- # * *Args* :
50
- # - +beneficiary_id+ -> The id of the beneficiary you want strongly authenticate
51
- # * *Returns* :
52
- # - A strong authentication object
53
- #
54
- def self.get_strong_authentication(beneficiary_id)
55
- get_request(File.join('beneficiaries', beneficiary_id.to_s, 'strongAuthentication'))
56
- end
57
-
58
- # Update a strong authentication object for a given beneficiary
59
- #
60
- # * *Args* :
61
- # - +beneficiary_id+ -> The id of the beneficiary you want strongly authenticate
62
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
63
- # * [Tag]
64
- # * [IsDocumentsTransmitted]
65
- # * *Returns* :
66
- # - A strong authentication object
67
- #
68
- def self.update_strong_authentication(beneficiary_id, data)
69
- put_request(File.join('beneficiaries', beneficiary_id.to_s, 'strongAuthentication'), data)
70
- end
71
- end
72
- end
data/lib/mangopay/card.rb DELETED
@@ -1,42 +0,0 @@
1
- module MangoPay
2
- # A payment card.
3
- class Card < MangoPay::Ressource
4
-
5
- # Create a payment card
6
- #
7
- # * *Args* :
8
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
- # * [Tag]
10
- # * OwnerID
11
- # * ReturnURL
12
- # * [TemplateURL]
13
- # * *Returns* :
14
- # - A payment card object
15
- #
16
- def self.create(data)
17
- post_request('cards', data)
18
- end
19
-
20
- # Get a payment card
21
- #
22
- # * *Args* :
23
- # - +card_id+ -> The id of the card you want to retrieve
24
- # * *Returns* :
25
- # - A payment card object
26
- #
27
- def self.details(card_id)
28
- get_request(File.join('cards', card_id.to_s))
29
- end
30
-
31
- # Delete a payment card
32
- #
33
- # * *Args* :
34
- # - +card_id+ -> The id of the card you want to delete
35
- # * *Returns* :
36
- # - A "OK" string on success
37
- #
38
- def self.delete(card_id)
39
- delete_request(File.join('cards', card_id.to_s))
40
- end
41
- end
42
- end
@@ -1,61 +0,0 @@
1
- module MangoPay
2
- # A contribution help you deposit money to a wallet.
3
- class Contribution < MangoPay::Ressource
4
-
5
- # Create a contribution
6
- #
7
- # * *Args* :
8
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
- # * [Tag]
10
- # * UserID
11
- # * WalletID
12
- # * Amount
13
- # * [ClientFeeAmount]
14
- # * ReturnURL
15
- # * [TemplateURL]
16
- # * [RegisterMeanOfPayment]
17
- # * [PaymentCardID]
18
- # * *Returns* :
19
- # - A contribution object
20
- #
21
- def self.create(data)
22
- post_request('contributions', data)
23
- end
24
-
25
- # Get a contribution
26
- #
27
- # * *Args* :
28
- # - +contribution_id+ -> The id of the contribution you want to retrieve
29
- # * *Returns* :
30
- # - A contribution object
31
- #
32
- def self.details(contribution_id)
33
- get_request(File.join('contributions', contribution_id.to_s))
34
- end
35
-
36
- # Refund a given contribution
37
- #
38
- # * *Args* :
39
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
40
- # * [Tag]
41
- # * ContributionID
42
- # * UserID
43
- # * *Returns* :
44
- # - A refund object
45
- #
46
- def self.refund(data)
47
- post_request(File.join('refunds'), data)
48
- end
49
-
50
- # Get a refund object
51
- #
52
- # * *Args* :
53
- # - +contribution_refund_id+ -> The id of the refund you want to retrieve
54
- # * *Returns* :
55
- # - A refund object
56
- #
57
- def self.get_refund(contribution_refund_id)
58
- get_request(File.join('refunds', contribution_refund_id.to_s))
59
- end
60
- end
61
- end
@@ -1,17 +0,0 @@
1
- module MangoPay
2
- # In order to make an expense you need to get a list of expense sites and then redirect a user to ExpenseURL.
3
- # When the user selects a product and pays, you will be notified about an expense through the notification mechanism.
4
- class Expense < MangoPay::Ressource
5
-
6
- # Get an expense
7
- #
8
- # * *Args* :
9
- # - +expense_id+ -> The id of the expense you want to retrieve
10
- # * *Returns* :
11
- # - An expense object
12
- #
13
- def self.get(expense_id)
14
- get_request(File.join('expenses', expense_id.to_s))
15
- end
16
- end
17
- end
@@ -1,58 +0,0 @@
1
- module MangoPay
2
- # An immediate contribution is a request to process directly a payment with a payment card already registred by the user.
3
- class ImmediateContribution < MangoPay::Ressource
4
-
5
- # Create an immediate contribution
6
- #
7
- # * *Args* :
8
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
- # * [Tag]
10
- # * UserID
11
- # * WalletID
12
- # * Amount
13
- # * PaymentCardID
14
- # * [ClientFeeAmount]
15
- # * *Returns* :
16
- # - An immediate contribution object
17
- #
18
- def self.create(data)
19
- post_request('immediate-contributions', data)
20
- end
21
-
22
- # Get an immediate contribution
23
- #
24
- # * *Args* :
25
- # - +immediate_contribution_id+ -> The id of the immediate contribution you want to retrieve
26
- # * *Returns* :
27
- # - An immediate contribution object
28
- #
29
- def self.details(immediate_contribution_id)
30
- get_request(File.join('immediate-contributions', immediate_contribution_id.to_s))
31
- end
32
-
33
- # Refund a given immediate contribution
34
- #
35
- # * *Args* :
36
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
37
- # * [Tag]
38
- # * ImmediateContributionID
39
- # * UserID
40
- # * *Returns* :
41
- # - A refund object
42
- #
43
- def self.refund(data)
44
- post_request(File.join('refunds'), data)
45
- end
46
-
47
- # Get a refund object
48
- #
49
- # * *Args* :
50
- # - +immediate_contribution_refund_id+ -> The id of the refund you want to retrieve
51
- # * *Returns* :
52
- # - A refund object
53
- #
54
- def self.get_refund(immediate_contribution_refund_id)
55
- get_request(File.join('refunds', immediate_contribution_refund_id.to_s))
56
- end
57
- end
58
- end
@@ -1,16 +0,0 @@
1
- module MangoPay
2
- # Operation
3
- class Operation < MangoPay::Ressource
4
-
5
- # Get an operation
6
- #
7
- # * *Args* :
8
- # - +operation_id+ -> The id of the operation you want to retrieve
9
- # * *Returns* :
10
- # - An operation object
11
- #
12
- def self.get(operation_id)
13
- get_request(File.join('operations', operation_id.to_s))
14
- end
15
- end
16
- end
@@ -1,62 +0,0 @@
1
- module MangoPay
2
-
3
- # Recurrent Contribution are available in test environment only, soon in production.
4
- class RecurrentContribution < MangoPay::Ressource
5
-
6
- # Create a recurrent contribution
7
- #
8
- # * *Args* :
9
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
10
- # * [Tag]
11
- # * UserID
12
- # * WalletID
13
- # * Amount
14
- # * [ClientFeeAmount]
15
- # * ReturnURL
16
- # * [TemplateURL]
17
- # * StartDate
18
- # * FrequencyCode
19
- # * NumberOfExecutions
20
- # * *Returns* :
21
- # - A recurrent contribution object
22
- #
23
- def self.create(data)
24
- post_request('recurrent-contributions', data)
25
- end
26
-
27
- # Get a recurrent contribution
28
- #
29
- # * *Args* :
30
- # - +recurrent_contributions_id+ -> The id of the recurrent contribution you want to retrieve
31
- # * *Returns* :
32
- # - A recurrent contribution object
33
- #
34
- def self.get(recurrent_contributions_id)
35
- get_request(File.join('recurrent-contributions', recurrent_contributions_id.to_s))
36
- end
37
-
38
- # Update a recurrent contribution
39
- #
40
- # * *Args* :
41
- # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
42
- # * IsEnabled
43
- # * [Tag]
44
- # * *Returns* :
45
- # - A recurrent contribution object
46
- #
47
- def self.update(recurrent_contributions_id, data)
48
- put_request(File.join('recurrent-contributions', recurrent_contributions_id.to_s), data)
49
- end
50
-
51
- # Fetch the list of a recurrent contribution executions
52
- #
53
- # * *Args* :
54
- # - +recurrent_contributions_id+ -> The id of the recurrent contribution you want to retrieve operations from
55
- # * *Returns* :
56
- # - An array of payment execution
57
- #
58
- def self.get_executions(recurrent_contributions_id)
59
- get_request(File.join('recurrent-contributions', recurrent_contributions_id.to_s, 'executions'))
60
- end
61
- end
62
- end
@@ -1,96 +0,0 @@
1
- module MangoPay
2
- class Ressource
3
-
4
- protected
5
-
6
- def self.post_request(route, data)
7
- request('POST', route, data)
8
- end
9
-
10
- def self.get_request(route, options=nil)
11
- request('GET', route, nil, options)
12
- end
13
-
14
- def self.put_request(route, data)
15
- request('PUT', route, data)
16
- end
17
-
18
- def self.delete_request(route)
19
- request('DELETE', route)
20
- end
21
-
22
- def self.form_request(upload_url, file_name, file_path)
23
- url = URI(upload_url)
24
- File.open(file_path) do |file|
25
- req = Net::HTTP::Post::Multipart.new(url.request_uri, :file => UploadIO.new(file, file_type(file_path), file_name))
26
- res = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
27
- http.request(req)
28
- end
29
- res.code == "200" ? true : false
30
- end
31
- end
32
-
33
- private
34
-
35
- def self.request(method, route, data=nil, options=nil)
36
- path = path_for(route, options)
37
- uri = uri_for(path)
38
- method = method.upcase
39
- data = data.to_json unless data.nil?
40
- headers = header_for(method, path, data)
41
- res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
42
- case method
43
- when 'POST' then request = Net::HTTP::Post.new(uri.request_uri, headers)
44
- when 'GET' then request = Net::HTTP::Get.new(uri.request_uri, headers)
45
- when 'PUT' then request = Net::HTTP::Put.new(uri.request_uri, headers)
46
- when 'DELETE' then request = Net::HTTP::Delete.new(uri.request_uri, headers)
47
- else
48
- return {}
49
- end
50
- request.body = data unless data.nil?
51
- http.request request
52
- end
53
- begin
54
- JSON.parse(res.body)
55
- rescue JSON::ParserError
56
- res.body.is_a?(String) ? res.body : {' ErrorCode' => -1 }
57
- end
58
- end
59
-
60
- def self.key
61
- OpenSSL::PKey::RSA.new(File.read(MangoPay.configuration.key_path), MangoPay.configuration.key_password)
62
- end
63
-
64
- def self.path_for(route, options)
65
- File.join('', 'v1', 'partner', MangoPay.configuration.partner_id, route.to_s) + "?ts=#{Time.now.to_i.to_s}" + (options.nil? ? '' : ('&' + options))
66
- end
67
-
68
- def self.uri_for(path)
69
- URI(File.join(MangoPay.configuration.base_url, path))
70
- end
71
-
72
- def self.sign(data)
73
- Base64.encode64(key.sign('sha1', data)).to_s.chomp.gsub(/\n/, '')
74
- end
75
-
76
- def self.signature_for(method, path, data)
77
- sign("#{method}|#{path}|" + (data.nil? ? '' : "#{data}|"))
78
- end
79
-
80
- def self.header_for(method, path, data)
81
- { 'X-Leetchi-Signature' => signature_for(method, path, data), 'Content-Type' => 'application/json' }
82
- end
83
-
84
- def self.file_type(file_path)
85
- file_types = {
86
- 'jpg' => 'image/jpeg',
87
- 'jpeg' => 'image/jpeg',
88
- 'gif' => 'image/gif',
89
- 'png' => 'image/png',
90
- 'pdf' => 'image/pdf'
91
- }
92
- file_types[file_path.gsub(/^[^\.]+\./, "")]
93
- end
94
- end
95
- end
96
-