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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +28 -26
  3. data/.rspec +2 -2
  4. data/.travis.yml +13 -0
  5. data/Gemfile +2 -2
  6. data/LICENSE +20 -20
  7. data/README.md +126 -123
  8. data/bin/mangopay +9 -9
  9. data/lib/generators/mangopay/install_generator.rb +60 -60
  10. data/lib/generators/templates/mangopay.rb.erb +5 -5
  11. data/lib/mangopay.rb +225 -158
  12. data/lib/mangopay/authorization_token.rb +88 -88
  13. data/lib/mangopay/bank_account.rb +38 -38
  14. data/lib/mangopay/card.rb +8 -8
  15. data/lib/mangopay/card_registration.rb +9 -9
  16. data/lib/mangopay/client.rb +74 -74
  17. data/lib/mangopay/dispute.rb +130 -130
  18. data/lib/mangopay/errors.rb +61 -61
  19. data/lib/mangopay/event.rb +18 -18
  20. data/lib/mangopay/filter_parameters.rb +46 -0
  21. data/lib/mangopay/hook.rb +9 -9
  22. data/lib/mangopay/http_calls.rb +85 -85
  23. data/lib/mangopay/json.rb +14 -14
  24. data/lib/mangopay/kyc_document.rb +70 -70
  25. data/lib/mangopay/legal_user.rb +15 -15
  26. data/lib/mangopay/mandate.rb +32 -32
  27. data/lib/mangopay/natural_user.rb +14 -14
  28. data/lib/mangopay/pay_in.rb +85 -73
  29. data/lib/mangopay/pay_out.rb +14 -14
  30. data/lib/mangopay/pre_authorization.rb +13 -13
  31. data/lib/mangopay/refund.rb +7 -7
  32. data/lib/mangopay/report.rb +17 -17
  33. data/lib/mangopay/resource.rb +21 -21
  34. data/lib/mangopay/temp.rb +74 -74
  35. data/lib/mangopay/transaction.rb +24 -24
  36. data/lib/mangopay/transfer.rb +9 -9
  37. data/lib/mangopay/user.rb +43 -35
  38. data/lib/mangopay/version.rb +3 -3
  39. data/lib/mangopay/wallet.rb +17 -17
  40. data/mangopay.gemspec +31 -30
  41. data/spec/mangopay/authorization_token_spec.rb +70 -70
  42. data/spec/mangopay/bank_account_spec.rb +97 -97
  43. data/spec/mangopay/card_registration_spec.rb +73 -73
  44. data/spec/mangopay/client_spec.rb +110 -110
  45. data/spec/mangopay/configuration_spec.rb +95 -18
  46. data/spec/mangopay/dispute_spec.rb +262 -262
  47. data/spec/mangopay/event_spec.rb +31 -31
  48. data/spec/mangopay/fetch_filters_spec.rb +63 -63
  49. data/spec/mangopay/hook_spec.rb +37 -37
  50. data/spec/mangopay/idempotency_spec.rb +41 -41
  51. data/spec/mangopay/kyc_document_spec.rb +103 -103
  52. data/spec/mangopay/log_requests_filter_spec.rb +25 -0
  53. data/spec/mangopay/mandate_spec.rb +92 -92
  54. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
  55. data/spec/mangopay/payin_card_direct_spec.rb +68 -68
  56. data/spec/mangopay/payin_card_web_spec.rb +38 -38
  57. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
  58. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
  59. data/spec/mangopay/payin_paypal_web_spec.rb +38 -0
  60. data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
  61. data/spec/mangopay/payout_bankwire_spec.rb +54 -54
  62. data/spec/mangopay/preauthorization_spec.rb +42 -42
  63. data/spec/mangopay/refund_spec.rb +21 -21
  64. data/spec/mangopay/report_spec.rb +39 -39
  65. data/spec/mangopay/shared_resources.rb +381 -365
  66. data/spec/mangopay/temp_paymentcard_spec.rb +31 -31
  67. data/spec/mangopay/transaction_spec.rb +54 -54
  68. data/spec/mangopay/transfer_spec.rb +69 -69
  69. data/spec/mangopay/user_spec.rb +137 -122
  70. data/spec/mangopay/wallet_spec.rb +80 -80
  71. data/spec/spec_helper.rb +31 -31
  72. metadata +11 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66c9892c195aece2222cf16271e0f667feb321fe
4
- data.tar.gz: d1b4c622c63bbc55a6689bbf458d9aaabb9f157d
3
+ metadata.gz: 59750018709e9f6cc230860a7a5da0087d6d4c90
4
+ data.tar.gz: 565a81ec2033f943679745f2b5a8afd856042b26
5
5
  SHA512:
6
- metadata.gz: 9d95ae1f194bf4b1efa39c4ecc353fd93b77b59ce838f17efea87fa13ef20d8f200f9c5d0deb6aa931948f559d03df7846db703be45f7b79103c3fd140c3e850
7
- data.tar.gz: 8c3f0400d5f58c06f9f0af78e83329b4dd1c1170d210da2b1a677fc03f7854f965572eeb1ace71cd0257b5051cd9392312ef8ac4dca97c0705ffeaab9d5815b3
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
- ** BREAKING CHANGES **
13
- This version (3.*) of the gem is targeting the Mangopay API Version 2.
14
- It has a brand new structure to make the api calls easier to use
15
- and is not backward compatible with 2.* series.
16
-
17
- 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/))
18
-
19
- Account creation
20
- -------------------------------------------------
21
- 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).
22
-
23
- ## Usage
24
-
25
- ### Install
26
- * 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).
27
-
28
- * Install the gem by either running ```gem install mangopay```
29
- or by adding it to your Gemfile ```gem 'mangopay'```
30
-
31
- * Using the credential info from the signup process above, call ```MangoPay.configure``` in your script as shown in the snippet below.
32
-
33
- ### Examples
34
-
35
- ```ruby
36
- require 'mangopay'
37
-
38
-
39
- # configuration
40
- MangoPay.configure do |c|
41
- c.preproduction = true
42
- c.client_id = 'YOUR_CLIENT_ID'
43
- c.client_passphrase = 'YOUR_CLIENT_PASSWORD'
44
- end
45
-
46
-
47
- # get some user by id
48
- john = MangoPay::User.fetch(john_id) # => {FirstName"=>"John", "LastName"=>"Doe", ...}
49
-
50
-
51
- # update some of his data
52
- MangoPay::NaturalUser.update(john_id, {'LastName' => 'CHANGED'}) # => {FirstName"=>"John", "LastName"=>"CHANGED", ...}
53
-
54
-
55
- # get all users (with pagination)
56
- pagination = {'page' => 1, 'per_page' => 8} # get 1st page, 8 items per page
57
- users = MangoPay::User.fetch(pagination) # => [{...}, ...]: list of 8 users data hashes
58
- pagination # => {"page"=>1, "per_page"=>8, "total_pages"=>748, "total_items"=>5978}
59
-
60
-
61
- # get John's bank accounts
62
- accounts = MangoPay::BankAccount.fetch(john_id) # => [{...}, ...]: list of accounts data hashes (10 per page by default)
63
-
64
-
65
- # error handling
66
- begin
67
- MangoPay::NaturalUser.create({})
68
- rescue MangoPay::ResponseError => ex
69
-
70
- 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.>
71
-
72
- ex.details # => {
73
- # "Message"=>"One or several required parameters are missing or incorrect. [...]",
74
- # "Type"=>"param_error",
75
- # "Id"=>"5c080105-4da3-467d-820d-0906164e55fe",
76
- # "Date"=>1409048671.0,
77
- # "errors"=>{
78
- # "FirstName"=>"The FirstName field is required.",
79
- # "LastName"=>"The LastName field is required.", ...},
80
- # "Code"=>"400",
81
- # "Url"=>"/v2/.../users/natural"
82
- # }
83
- end
84
- ```
85
-
86
- ### Tests
87
- Make sure that you have run: ```bundle install```
88
- Then you just have to run rspec ```rspec``` to run all the test suite.
89
- Feel free to report any test failure by creating an issue
90
- on the [Gem's Github](https://github.com/Mangopay/mangopay2-ruby-sdk/issues)
91
-
92
- ## Contributing
93
-
94
- 1. Fork the repo.
95
-
96
- 2. Run the tests. We only take pull requests with passing tests, and it's great
97
- to know that you have a clean slate: `bundle && bundle exec rspec`
98
-
99
- 3. Add a test for your change. Only refactoring and documentation changes
100
- require no new tests. If you are adding functionality or fixing a bug, we need
101
- a test!
102
-
103
- 4. Make the test pass.
104
-
105
- 5. Push to your fork and submit a pull request.
106
-
107
- At this point you're waiting on us. We like to at least comment on, if not
108
- accept, pull requests within three business days (and, typically, one business
109
- day). We may suggest some changes or improvements or alternatives.
110
-
111
- Syntax:
112
-
113
- * Two spaces, no tabs.
114
- * No trailing whitespace. Blank lines should not have any space.
115
- * Prefer &&/|| over and/or.
116
- * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
117
- * a = b and not a=b.
118
- * Follow the conventions you see used in the source already.
119
-
120
- A contribution can also be as simple as a +1 on issues tickets to show us
121
- what you would like to see in this gem.
122
-
123
- That's it for now. Good Hacking...
1
+ # Mangopay Ruby SDK [![Build Status](https://travis-ci.org/Mangopay/mangopay2-ruby-sdk.svg?branch=master)](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