mangopay 3.0.23 → 3.0.25.pre.alpha.pre.20
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.
- checksums.yaml +4 -4
- data/.gitignore +28 -26
- data/.rspec +2 -2
- data/.travis.yml +13 -0
- data/Gemfile +2 -2
- data/LICENSE +20 -20
- data/README.md +126 -123
- data/bin/mangopay +9 -9
- data/lib/generators/mangopay/install_generator.rb +60 -60
- data/lib/generators/templates/mangopay.rb.erb +5 -5
- data/lib/mangopay.rb +225 -158
- data/lib/mangopay/authorization_token.rb +88 -88
- data/lib/mangopay/bank_account.rb +38 -38
- data/lib/mangopay/card.rb +8 -8
- data/lib/mangopay/card_registration.rb +9 -9
- data/lib/mangopay/client.rb +74 -74
- data/lib/mangopay/dispute.rb +130 -130
- data/lib/mangopay/errors.rb +61 -61
- data/lib/mangopay/event.rb +18 -18
- data/lib/mangopay/filter_parameters.rb +46 -0
- data/lib/mangopay/hook.rb +9 -9
- data/lib/mangopay/http_calls.rb +85 -85
- data/lib/mangopay/json.rb +14 -14
- data/lib/mangopay/kyc_document.rb +70 -70
- data/lib/mangopay/legal_user.rb +15 -15
- data/lib/mangopay/mandate.rb +32 -32
- data/lib/mangopay/natural_user.rb +14 -14
- data/lib/mangopay/pay_in.rb +85 -73
- data/lib/mangopay/pay_out.rb +14 -14
- data/lib/mangopay/pre_authorization.rb +13 -13
- data/lib/mangopay/refund.rb +7 -7
- data/lib/mangopay/report.rb +17 -17
- data/lib/mangopay/resource.rb +21 -21
- data/lib/mangopay/temp.rb +74 -74
- data/lib/mangopay/transaction.rb +24 -24
- data/lib/mangopay/transfer.rb +9 -9
- data/lib/mangopay/user.rb +43 -35
- data/lib/mangopay/version.rb +3 -3
- data/lib/mangopay/wallet.rb +17 -17
- data/mangopay.gemspec +31 -30
- data/spec/mangopay/authorization_token_spec.rb +70 -70
- data/spec/mangopay/bank_account_spec.rb +97 -97
- data/spec/mangopay/card_registration_spec.rb +73 -73
- data/spec/mangopay/client_spec.rb +110 -110
- data/spec/mangopay/configuration_spec.rb +95 -18
- data/spec/mangopay/dispute_spec.rb +262 -262
- data/spec/mangopay/event_spec.rb +31 -31
- data/spec/mangopay/fetch_filters_spec.rb +63 -63
- data/spec/mangopay/hook_spec.rb +37 -37
- data/spec/mangopay/idempotency_spec.rb +41 -41
- data/spec/mangopay/kyc_document_spec.rb +103 -103
- data/spec/mangopay/log_requests_filter_spec.rb +25 -0
- data/spec/mangopay/mandate_spec.rb +92 -92
- data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
- data/spec/mangopay/payin_card_direct_spec.rb +68 -68
- data/spec/mangopay/payin_card_web_spec.rb +38 -38
- data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
- data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
- data/spec/mangopay/payin_paypal_web_spec.rb +38 -0
- data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
- data/spec/mangopay/payout_bankwire_spec.rb +54 -54
- data/spec/mangopay/preauthorization_spec.rb +42 -42
- data/spec/mangopay/refund_spec.rb +21 -21
- data/spec/mangopay/report_spec.rb +39 -39
- data/spec/mangopay/shared_resources.rb +381 -365
- data/spec/mangopay/temp_paymentcard_spec.rb +31 -31
- data/spec/mangopay/transaction_spec.rb +54 -54
- data/spec/mangopay/transfer_spec.rb +69 -69
- data/spec/mangopay/user_spec.rb +137 -122
- data/spec/mangopay/wallet_spec.rb +80 -80
- data/spec/spec_helper.rb +31 -31
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59750018709e9f6cc230860a7a5da0087d6d4c90
|
4
|
+
data.tar.gz: 565a81ec2033f943679745f2b5a8afd856042b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f3a0c1a213e312f95406483006fa78a5bcf228ad49c1ada12596d66622920065cf1ea8636d5356c2a019ab2de4625ca09b7627eb7f037fb19660b328efe203
|
7
|
+
data.tar.gz: 6dc436c68121b7c9649c0264ee108dc3db0f625abe6941038550441ef7c784ea3d41c8f961952266f008f99eb1edb74751d756964b7fbc483b2b73b6056cb963
|
data/.gitignore
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
coverage
|
6
|
-
InstalledFiles
|
7
|
-
lib/bundler/man
|
8
|
-
pkg
|
9
|
-
rdoc
|
10
|
-
spec/reports
|
11
|
-
spec/tmp/*.tmp
|
12
|
-
test/tmp
|
13
|
-
test/version_tmp
|
14
|
-
tags
|
15
|
-
|
16
|
-
# YARD artifacts
|
17
|
-
.yardoc
|
18
|
-
_yardoc
|
19
|
-
doc/
|
20
|
-
|
21
|
-
.DS_Store
|
22
|
-
.rvmrc
|
23
|
-
/Gemfile.lock
|
24
|
-
/mangopay-*.gem
|
25
|
-
|
26
|
-
/nbproject/
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
spec/tmp/*.tmp
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tags
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
.DS_Store
|
22
|
+
.rvmrc
|
23
|
+
/Gemfile.lock
|
24
|
+
/mangopay-*.gem
|
25
|
+
|
26
|
+
/nbproject/
|
27
|
+
|
28
|
+
/*.sublime-*
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--color
|
2
|
-
--profile
|
1
|
+
--color
|
2
|
+
--profile
|
3
3
|
--r spec_helper
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
script: bundle exec rspec
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: gvlnYEh9cyL+mYeudKzlD+2Po+LgIzCjHzggJH+WDcbtgxlGAFpxbVJOOm/KY8VKhMgIudNV7FJl4Gl4rrG8JjNxbb+qM57ypU3yyDcUesQ+uj0DnN+xszv7M+XtcRQMlhkStawoj/E0QMYBPkAAr1lBpPIFQdC17GDkdn5XvaQ=
|
9
|
+
gem: mangopay
|
10
|
+
on:
|
11
|
+
tags: false
|
12
|
+
repo: Mangopay/mangopay2-ruby-sdk
|
13
|
+
branch: MPSDK-23-configure-gem-deployment
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2013 Mangopay
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
7
|
-
the Software without restriction, including without limitation the rights to
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Mangopay
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,123 +1,126 @@
|
|
1
|
-
# Mangopay Ruby SDK
|
2
|
-
|
3
|
-
The gem for interacting with the version 2 of the Mangopay API.
|
4
|
-
See the [API documentation](http://docs.mangopay.com/api-references/)
|
5
|
-
for more details on the API.
|
6
|
-
|
7
|
-
Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0
|
8
|
-
|
9
|
-
## NEWS
|
10
|
-
|
11
|
-
### Version 3.*
|
12
|
-
**
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
*
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
c.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
pagination
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
ex # =>
|
71
|
-
|
72
|
-
|
73
|
-
# "
|
74
|
-
# "
|
75
|
-
# "
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
1
|
+
# Mangopay Ruby SDK [](https://travis-ci.org/Mangopay/mangopay2-ruby-sdk)
|
2
|
+
|
3
|
+
The gem for interacting with the version 2 of the Mangopay API.
|
4
|
+
See the [API documentation](http://docs.mangopay.com/api-references/)
|
5
|
+
for more details on the API.
|
6
|
+
|
7
|
+
Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0
|
8
|
+
|
9
|
+
## NEWS
|
10
|
+
|
11
|
+
### Version 3.*
|
12
|
+
**BREAKING CHANGES:** This version (3.\*) of the gem is targeting the Mangopay API Version 2. It has a brand new structure to make the api calls easier to use and is not backward compatible with 2.\* series.
|
13
|
+
|
14
|
+
Since [v3.0.17](https://github.com/Mangopay/mangopay2-ruby-sdk/releases/tag/v3.0.17) of the SDK, you must be using at least v2.01 of the API (more information about the changes required [here](https://docs.mangopay.com/api-v2-01-overview/))
|
15
|
+
|
16
|
+
Account creation
|
17
|
+
-------------------------------------------------
|
18
|
+
You can get yourself a [free sandbox account](https://www.mangopay.com/signup/create-sandbox/) or sign up for a [production account](https://www.mangopay.com/signup/submit-your-app/go-live/) (note that validation of your production account can take a few days, so think about doing it in advance of when you actually want to go live).
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Install
|
23
|
+
* You can get yourself a [free sandbox account](https://www.mangopay.com/get-started/create-sandbox/) or sign up for a [production account](https://www.mangopay.com/get-started/submit-your-app/create-credentials/) (note that validation of your production account can take a few days, so think about doing it in advance of when you actually want to go live).
|
24
|
+
|
25
|
+
* Install the gem by either running ```gem install mangopay```
|
26
|
+
or by adding it to your Gemfile ```gem 'mangopay'```
|
27
|
+
|
28
|
+
* Using the credential info from the signup process above, call ```MangoPay.configure``` in your script as shown in the snippet below.
|
29
|
+
|
30
|
+
### Examples
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'mangopay'
|
34
|
+
|
35
|
+
|
36
|
+
# configuration
|
37
|
+
MangoPay.configure do |c|
|
38
|
+
c.preproduction = true
|
39
|
+
c.client_id = 'YOUR_CLIENT_ID'
|
40
|
+
c.client_passphrase = 'YOUR_CLIENT_PASSWORD'
|
41
|
+
c.log_file = File.join('mypath', 'mangopay.log')
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# get some user by id
|
46
|
+
john = MangoPay::User.fetch(john_id) # => {FirstName"=>"John", "LastName"=>"Doe", ...}
|
47
|
+
|
48
|
+
|
49
|
+
# update some of his data
|
50
|
+
MangoPay::NaturalUser.update(john_id, {'LastName' => 'CHANGED'}) # => {FirstName"=>"John", "LastName"=>"CHANGED", ...}
|
51
|
+
|
52
|
+
|
53
|
+
# get all users (with pagination)
|
54
|
+
pagination = {'page' => 1, 'per_page' => 8} # get 1st page, 8 items per page
|
55
|
+
users = MangoPay::User.fetch(pagination) # => [{...}, ...]: list of 8 users data hashes
|
56
|
+
pagination # => {"page"=>1, "per_page"=>8, "total_pages"=>748, "total_items"=>5978}
|
57
|
+
|
58
|
+
|
59
|
+
# get John's bank accounts
|
60
|
+
accounts = MangoPay::BankAccount.fetch(john_id) # => [{...}, ...]: list of accounts data hashes (10 per page by default)
|
61
|
+
|
62
|
+
|
63
|
+
# error handling
|
64
|
+
begin
|
65
|
+
MangoPay::NaturalUser.create({})
|
66
|
+
rescue MangoPay::ResponseError => ex
|
67
|
+
|
68
|
+
ex # => #<MangoPay::ResponseError: One or several required parameters are missing or incorrect. [...] FirstName: The FirstName field is required. LastName: The LastName field is required. Nationality: The Nationality field is required.>
|
69
|
+
|
70
|
+
ex.details # => {
|
71
|
+
# "Message"=>"One or several required parameters are missing or incorrect. [...]",
|
72
|
+
# "Type"=>"param_error",
|
73
|
+
# "Id"=>"5c080105-4da3-467d-820d-0906164e55fe",
|
74
|
+
# "Date"=>1409048671.0,
|
75
|
+
# "errors"=>{
|
76
|
+
# "FirstName"=>"The FirstName field is required.",
|
77
|
+
# "LastName"=>"The LastName field is required.", ...},
|
78
|
+
# "Code"=>"400",
|
79
|
+
# "Url"=>"/v2/.../users/natural"
|
80
|
+
# }
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
### Log requests and responses
|
85
|
+
You can easily enable logs by setting the ```log_file``` configuration option (see the section **configuration** above). If you don't want logs, remove the ```log_file``` line.
|
86
|
+
|
87
|
+
Requests and responses are filtered, so confidential data is not saved in logs.
|
88
|
+
|
89
|
+
### Tests
|
90
|
+
Make sure that you have run: ```bundle install```
|
91
|
+
Then you just have to run rspec ```rspec``` to run all the test suite.
|
92
|
+
Feel free to report any test failure by creating an issue
|
93
|
+
on the [Gem's Github](https://github.com/Mangopay/mangopay2-ruby-sdk/issues)
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork the repo.
|
98
|
+
|
99
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
100
|
+
to know that you have a clean slate: `bundle && bundle exec rspec`
|
101
|
+
|
102
|
+
3. Add a test for your change. Only refactoring and documentation changes
|
103
|
+
require no new tests. If you are adding functionality or fixing a bug, we need
|
104
|
+
a test!
|
105
|
+
|
106
|
+
4. Make the test pass.
|
107
|
+
|
108
|
+
5. Push to your fork and submit a pull request.
|
109
|
+
|
110
|
+
At this point you're waiting on us. We like to at least comment on, if not
|
111
|
+
accept, pull requests within three business days (and, typically, one business
|
112
|
+
day). We may suggest some changes or improvements or alternatives.
|
113
|
+
|
114
|
+
Syntax:
|
115
|
+
|
116
|
+
* Two spaces, no tabs.
|
117
|
+
* No trailing whitespace. Blank lines should not have any space.
|
118
|
+
* Prefer &&/|| over and/or.
|
119
|
+
* MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
120
|
+
* a = b and not a=b.
|
121
|
+
* Follow the conventions you see used in the source already.
|
122
|
+
|
123
|
+
A contribution can also be as simple as a +1 on issues tickets to show us
|
124
|
+
what you would like to see in this gem.
|
125
|
+
|
126
|
+
That's it for now. Good Hacking...
|
data/bin/mangopay
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/mangopay'}"
|
7
|
-
|
8
|
-
puts "Loading MangoPay gem"
|
9
|
-
exec "#{irb} #{libs}"
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/mangopay'}"
|
7
|
+
|
8
|
+
puts "Loading MangoPay gem"
|
9
|
+
exec "#{irb} #{libs}"
|
@@ -1,60 +1,60 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
require 'mangopay'
|
3
|
-
|
4
|
-
module Mangopay
|
5
|
-
module Generators
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
source_root File.expand_path('../../templates', __FILE__)
|
8
|
-
argument :client_id, type: :string,
|
9
|
-
desc: 'The id you want to use to query the MangoPay API (must match with the regex ^[a-z0-9_-]{4,20}$)'
|
10
|
-
argument :client_name, type: :string, desc: "Full name of you're organization"
|
11
|
-
argument :client_email, type: :string, desc: "An email for future contacts"
|
12
|
-
class_option :preproduction, type: :boolean, default: true, desc: 'Whether or not use the preproduction environment'
|
13
|
-
|
14
|
-
desc 'Installs all the basic configuration of the mangopay gem'
|
15
|
-
def setup
|
16
|
-
begin
|
17
|
-
client = client_id_valid?
|
18
|
-
remove_file 'config/initializers/mangopay.rb'
|
19
|
-
@client_id = client_id
|
20
|
-
@client_passphrase = client['Passphrase']
|
21
|
-
template 'mangopay.rb.erb', 'config/initializers/mangopay.rb'
|
22
|
-
rescue => e
|
23
|
-
puts e.message
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
|
29
|
-
def client_id_valid?
|
30
|
-
check_client_id_validity
|
31
|
-
check_client_id_availablility
|
32
|
-
end
|
33
|
-
|
34
|
-
def check_client_id_validity
|
35
|
-
if (/^[a-z0-9_-]{4,20}$/ =~ client_id).nil?
|
36
|
-
raise "The client_id must match the regexp ^[a-z0-9_-]{4,20}$"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def check_client_id_availablility
|
41
|
-
client = create_client
|
42
|
-
if client['Type'] == 'ClientID_already_exist'
|
43
|
-
raise client['Message']
|
44
|
-
end
|
45
|
-
client
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_client
|
49
|
-
MangoPay.configure do |c|
|
50
|
-
c.preproduction = options[:preproduction]
|
51
|
-
end
|
52
|
-
MangoPay::Client.create({
|
53
|
-
ClientID: client_id,
|
54
|
-
Name: client_name,
|
55
|
-
Email: client_email
|
56
|
-
})
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'mangopay'
|
3
|
+
|
4
|
+
module Mangopay
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../../templates', __FILE__)
|
8
|
+
argument :client_id, type: :string,
|
9
|
+
desc: 'The id you want to use to query the MangoPay API (must match with the regex ^[a-z0-9_-]{4,20}$)'
|
10
|
+
argument :client_name, type: :string, desc: "Full name of you're organization"
|
11
|
+
argument :client_email, type: :string, desc: "An email for future contacts"
|
12
|
+
class_option :preproduction, type: :boolean, default: true, desc: 'Whether or not use the preproduction environment'
|
13
|
+
|
14
|
+
desc 'Installs all the basic configuration of the mangopay gem'
|
15
|
+
def setup
|
16
|
+
begin
|
17
|
+
client = client_id_valid?
|
18
|
+
remove_file 'config/initializers/mangopay.rb'
|
19
|
+
@client_id = client_id
|
20
|
+
@client_passphrase = client['Passphrase']
|
21
|
+
template 'mangopay.rb.erb', 'config/initializers/mangopay.rb'
|
22
|
+
rescue => e
|
23
|
+
puts e.message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def client_id_valid?
|
30
|
+
check_client_id_validity
|
31
|
+
check_client_id_availablility
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_client_id_validity
|
35
|
+
if (/^[a-z0-9_-]{4,20}$/ =~ client_id).nil?
|
36
|
+
raise "The client_id must match the regexp ^[a-z0-9_-]{4,20}$"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_client_id_availablility
|
41
|
+
client = create_client
|
42
|
+
if client['Type'] == 'ClientID_already_exist'
|
43
|
+
raise client['Message']
|
44
|
+
end
|
45
|
+
client
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_client
|
49
|
+
MangoPay.configure do |c|
|
50
|
+
c.preproduction = options[:preproduction]
|
51
|
+
end
|
52
|
+
MangoPay::Client.create({
|
53
|
+
ClientID: client_id,
|
54
|
+
Name: client_name,
|
55
|
+
Email: client_email
|
56
|
+
})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|