mangopay 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +51 -0
- data/Gemfile +3 -0
- data/README.md +138 -0
- data/Rakefile +5 -0
- data/lib/mangopay.rb +45 -0
- data/lib/mangopay/beneficiary.rb +72 -0
- data/lib/mangopay/card.rb +42 -0
- data/lib/mangopay/contribution.rb +61 -0
- data/lib/mangopay/expense.rb +17 -0
- data/lib/mangopay/immediate_contribution.rb +58 -0
- data/lib/mangopay/operation.rb +16 -0
- data/lib/mangopay/recurrent_contribution.rb +62 -0
- data/lib/mangopay/ressource.rb +96 -0
- data/lib/mangopay/strong_authentication.rb +28 -0
- data/lib/mangopay/transfer.rb +58 -0
- data/lib/mangopay/user.rb +148 -0
- data/lib/mangopay/wallet.rb +93 -0
- data/lib/mangopay/withdrawal.rb +40 -0
- data/lib/mangopay/withdrawal_contribution.rb +32 -0
- data/spec/lib/mangopay/beneficiary_spec.rb +124 -0
- data/spec/lib/mangopay/card_spec.rb +52 -0
- data/spec/lib/mangopay/contribution_spec.rb +65 -0
- data/spec/lib/mangopay/expense_spec.rb +10 -0
- data/spec/lib/mangopay/immediate_contribution_spec.rb +73 -0
- data/spec/lib/mangopay/operation_spec.rb +8 -0
- data/spec/lib/mangopay/recurrent_contribution_spec.rb +55 -0
- data/spec/lib/mangopay/ressource_spec.rb +5 -0
- data/spec/lib/mangopay/strong_authentication_spec.rb +82 -0
- data/spec/lib/mangopay/transfer_spec.rb +88 -0
- data/spec/lib/mangopay/user_spec.rb +124 -0
- data/spec/lib/mangopay/wallet_spec.rb +81 -0
- data/spec/lib/mangopay/withdrawal_contribution_spec.rb +44 -0
- data/spec/lib/mangopay/withdrawal_spec.rb +98 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support-files/example.pem +49 -0
- data/spec/support-files/test_upload.gif +0 -0
- data/spec/support-files/test_upload.jpg +0 -0
- data/spec/support-files/test_upload.pdf +0 -0
- data/spec/support-files/test_upload.png +0 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b09720dac2af9cba56800c7b8300b216bb9bdd55
|
4
|
+
data.tar.gz: 1980d47b7aa7bab13ad6dcb7e3ff4e94c2801592
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 971c9855f24cb3179100eb0a62255108361b6b40a668fc72ed77b5724c2351566cb13872321c4da0e0e12074b8d8e3189585e2dbe5b16ca74002bd08395e2040
|
7
|
+
data.tar.gz: cd6f739af9810c957411d8e330f9443b846d092089cb01137770b5d1d71aa2f7a2ac3c821c074a5727657c340ae7d71a3af53e67ea87109cab370e092d18c858
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,51 @@
|
|
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/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# mangopay
|
2
|
+
|
3
|
+
The gem for interacting with MangoPay API.
|
4
|
+
See the [API documentation](http://www.mangopay.com/api-references/) for more details on the API.
|
5
|
+
|
6
|
+
Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0
|
7
|
+
|
8
|
+
## Code Status
|
9
|
+
[![Build Status](https://travis-ci.org/MangoPay/mangopay.png?branch=master)](https://travis-ci.org/MangoPay/leetchi-api-ruby-sdk)
|
10
|
+
[![Code Climate](https://codeclimate.com/github/MangoPay/mangopay.png)](https://codeclimate.com/github/MangoPay/leetchi-api-ruby-sdk)
|
11
|
+
[![Dependency Status](https://gemnasium.com/MangoPay/mangopay.png)](https://gemnasium.com/MangoPay/leetchi-api-ruby-sdk)
|
12
|
+
|
13
|
+
## NEWS
|
14
|
+
|
15
|
+
### Version 2.0.0
|
16
|
+
** BREAKING CHANGES **
|
17
|
+
The Gem has been updated to 2.0.0
|
18
|
+
It has been renamed from leetchi-api-ruby-sdk to mangopay.
|
19
|
+
|
20
|
+
Please make sure you update all the internal calls from Leetchi to MangoPay.
|
21
|
+
|
22
|
+
## Requirements
|
23
|
+
|
24
|
+
This gem uses mainly ruby stdlib and the *json* gem.
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
|
28
|
+
Please note that the gem configuration process change between 0.0.1 and 1.0.0.
|
29
|
+
|
30
|
+
### Version 0.0.1
|
31
|
+
|
32
|
+
Setup the following ENV:
|
33
|
+
|
34
|
+
```
|
35
|
+
ENV['LEETCHI_API_BASE_URL'] = "https://api-preprod.leetchi.com" # once you've run your test using the preproduction environment use the production one
|
36
|
+
ENV['LEETCHI_KEY_PATH'] = "abcd" # the full path to your leetchi key
|
37
|
+
ENV['LEETCHI_PASSPHRASE'] = "efgh" # you key's passphrase (leave blank if none)
|
38
|
+
ENV['LEETCHI_PARTNER_ID'] = "myID" # your MangoPay API ID
|
39
|
+
```
|
40
|
+
|
41
|
+
### Version 1.0.0
|
42
|
+
|
43
|
+
You can now call the MangoPay.configure method like this:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
MangoPay.configure do |c|
|
47
|
+
c.preproduction = true
|
48
|
+
c.partner_id = 'example'
|
49
|
+
c.key_path = './spec/support-files/example.pem'
|
50
|
+
c.key_password = ''
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
The **preproduction** attribute let you specify if you want to use the preproduction api endpoint.
|
55
|
+
|
56
|
+
The **partner_id** is the id that was issue to you during you registration process.
|
57
|
+
|
58
|
+
The **key_path** and **key_password** arguments are here to let you use the key you've created before the registration process.
|
59
|
+
|
60
|
+
This configure method can of course be use to define a Ruby on Rails initialiser.
|
61
|
+
|
62
|
+
## Usage
|
63
|
+
|
64
|
+
The gem implements the following resources:
|
65
|
+
- Beneficiary
|
66
|
+
- Card
|
67
|
+
- Contribution
|
68
|
+
- Expense
|
69
|
+
- Operation
|
70
|
+
- Immediate Contribution
|
71
|
+
- Recurrent Contribution (only available in preproduction)
|
72
|
+
- Strong Authentication
|
73
|
+
- Transfer
|
74
|
+
- User
|
75
|
+
- Wallet
|
76
|
+
- Withdrawal
|
77
|
+
|
78
|
+
Each resource has specifics methods such has `create`, `details`, `update`, etc. Those methods must be called with an ID and / or an Object matching the MangoPay API.
|
79
|
+
Calling those methods return the MangoPay API response has an object. Every executions are made synchronously.
|
80
|
+
|
81
|
+
### Example
|
82
|
+
|
83
|
+
This example creates a user and returns its informations:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
MangoPay::User.create({
|
87
|
+
'Tag' => 'test',
|
88
|
+
'Email' => 'my@email.com',
|
89
|
+
'FistName' => 'Jack',
|
90
|
+
'LastName' => 'Nelson',
|
91
|
+
'CanRegisterMeanOfPayment' => true
|
92
|
+
})
|
93
|
+
```
|
94
|
+
|
95
|
+
This example returns a specific user's data:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
MangoPay::User.details(123)
|
99
|
+
```
|
100
|
+
|
101
|
+
### Tests
|
102
|
+
Make sure that you have run: ```bundle install```
|
103
|
+
Then you just have to run the rake task ```rake test``` to run all the test suite.
|
104
|
+
Feel free to report any test failure by creating an issue on the [Gem's Github](https://github.com/MangoPay/leetchi-api-ruby-sdk/issues)
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Take a look at the [CONTRIBUTING](https://github.com/Leetchi/mangopay/blob/master/CONTRIBUTING.md) file of this repo
|
109
|
+
|
110
|
+
1. Fork the repo.
|
111
|
+
|
112
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
113
|
+
to know that you have a clean slate: `bundle && bundle exec rake`
|
114
|
+
|
115
|
+
3. Add a test for your change. Only refactoring and documentation changes
|
116
|
+
require no new tests. If you are adding functionality or fixing a bug, we need
|
117
|
+
a test!
|
118
|
+
|
119
|
+
4. Make the test pass.
|
120
|
+
|
121
|
+
5. Push to your fork and submit a pull request.
|
122
|
+
|
123
|
+
At this point you're waiting on us. We like to at least comment on, if not
|
124
|
+
accept, pull requests within three business days (and, typically, one business
|
125
|
+
day). We may suggest some changes or improvements or alternatives.
|
126
|
+
|
127
|
+
Syntax:
|
128
|
+
|
129
|
+
* Two spaces, no tabs.
|
130
|
+
* No trailing whitespace. Blank lines should not have any space.
|
131
|
+
* Prefer &&/|| over and/or.
|
132
|
+
* MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
133
|
+
* a = b and not a=b.
|
134
|
+
* Follow the conventions you see used in the source already.
|
135
|
+
|
136
|
+
A contribution can also be as simple as a +1 on issues tickets to show us what you would like to see in this gem.
|
137
|
+
|
138
|
+
That's it for now. Good Hacking...
|
data/Rakefile
ADDED
data/lib/mangopay.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module MangoPay
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'base64'
|
5
|
+
require 'openssl'
|
6
|
+
require 'net/http'
|
7
|
+
require 'net/http/post/multipart'
|
8
|
+
|
9
|
+
require 'mangopay/ressource'
|
10
|
+
require 'mangopay/user'
|
11
|
+
require 'mangopay/wallet'
|
12
|
+
require 'mangopay/card'
|
13
|
+
require 'mangopay/contribution'
|
14
|
+
require 'mangopay/immediate_contribution'
|
15
|
+
require 'mangopay/withdrawal_contribution'
|
16
|
+
require 'mangopay/transfer'
|
17
|
+
require 'mangopay/beneficiary'
|
18
|
+
require 'mangopay/withdrawal'
|
19
|
+
require 'mangopay/strong_authentication'
|
20
|
+
require 'mangopay/operation'
|
21
|
+
require 'mangopay/expense'
|
22
|
+
require 'mangopay/recurrent_contribution'
|
23
|
+
|
24
|
+
|
25
|
+
class Configuration
|
26
|
+
attr_accessor :base_url, :partner_id, :key_path, :key_password, :preproduction
|
27
|
+
|
28
|
+
def preproduction
|
29
|
+
@preproduction || false
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
@base_url || (@preproduction == true ? "https://api-preprod.leetchi.com" : "https://api.leetchi.com")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
attr_accessor :configuration
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.configure
|
42
|
+
self.configuration ||= Configuration.new
|
43
|
+
yield configuration
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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
|
@@ -0,0 +1,61 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
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
|