mangopay 2.0.0 → 3.0.0

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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b09720dac2af9cba56800c7b8300b216bb9bdd55
4
- data.tar.gz: 1980d47b7aa7bab13ad6dcb7e3ff4e94c2801592
3
+ metadata.gz: 70750c7027d98926cc945a63e4a3ec94b72da433
4
+ data.tar.gz: 7804bbb5e621985168b1956879efd2a05793708e
5
5
  SHA512:
6
- metadata.gz: 971c9855f24cb3179100eb0a62255108361b6b40a668fc72ed77b5724c2351566cb13872321c4da0e0e12074b8d8e3189585e2dbe5b16ca74002bd08395e2040
7
- data.tar.gz: cd6f739af9810c957411d8e330f9443b846d092089cb01137770b5d1d71aa2f7a2ac3c821c074a5727657c340ae7d71a3af53e67ea87109cab370e092d18c858
6
+ metadata.gz: a771d8de26c6dbec506734008b57bbd7ad133a48ec8feba3af8a90d545f209a0574d64723460157ea742a69c82c5be0c8980e7ca40beef7dfe0c6053f329cb80
7
+ data.tar.gz: 65b199274b1b0f8c975fc6021a03f9a9c99da6d5ef3c94fe4ef7fae95149474c995c83c189dd4df1c93fabd971c99e2bef326f4f2c4f5850990b454187230b4c
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ 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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --profile
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
- source 'https://rubygems.org'
2
-
1
+ source "https://rubygems.org"
3
2
  gemspec
data/LICENSE ADDED
@@ -0,0 +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.
data/README.md CHANGED
@@ -1,112 +1,40 @@
1
- # mangopay
1
+ # MangoPay2 Ruby SDK
2
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.
3
+ The gem for interacting with the version 2 of the MangoPay API.
4
+ See the [API documentation]() for more details on the API.
5
5
 
6
6
  Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0
7
7
 
8
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)
9
+ [![Build Status]()]()
10
+ [![Code Climate]()]()
11
+ [![Dependency Status]()]()
12
12
 
13
13
  ## NEWS
14
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.
15
+ ### Version 3.0.0
16
+ ** BREAKING CHANGES **
17
+ This version of the gem is targeting the MangoPay API Version 2.
18
+ It has a brand new structure to make the api calls easier to use
19
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.
20
+ ## Usage
57
21
 
58
- The **key_path** and **key_password** arguments are here to let you use the key you've created before the registration process.
22
+ ### Install
23
+ * Install the gem by either running ```gem install mangopay``` or by adding it to your Gemfile ```gem 'mangopay'```
59
24
 
60
- This configure method can of course be use to define a Ruby on Rails initialiser.
25
+ * The Rails users will be happy to know that there is a new generator script that will help you configure your access to the MangoPay API version 2.
26
+ Simply run ``rails generate mangopay:install CLIENT_ID CLIENT_NAME`` where CLIENT_ID is the id you will use to connect to the api and CLIENT_NAME is a full name that will be use to identify all communications between you and the MangoPay Team.
61
27
 
62
- ## Usage
28
+ ### Examples
63
29
 
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
30
 
101
31
  ### Tests
102
32
  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)
33
+ Then you just have to run rspec ```rspec``` to run all the test suite.
34
+ Feel free to report any test failure by creating an issue on the [Gem's Github](https://github.com/MangoPay/mangopay2-ruby-sdk/issues)
105
35
 
106
36
  ## Contributing
107
37
 
108
- Take a look at the [CONTRIBUTING](https://github.com/Leetchi/mangopay/blob/master/CONTRIBUTING.md) file of this repo
109
-
110
38
  1. Fork the repo.
111
39
 
112
40
  2. Run the tests. We only take pull requests with passing tests, and it's great
@@ -136,3 +64,4 @@ Syntax:
136
64
  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
65
 
138
66
  That's it for now. Good Hacking...
67
+ >>>>>>> dev
data/bin/mangopay ADDED
@@ -0,0 +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}"
@@ -0,0 +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', '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
@@ -0,0 +1,5 @@
1
+ MangoPay.configure do |c|
2
+ c.preproduction = <%= options[:preproduction] %>
3
+ c.client_id = '<%= @client_id %>'
4
+ c.client_passphrase = '<%= @client_passphrase %>'
5
+ end
data/lib/mangopay.rb CHANGED
@@ -1,36 +1,40 @@
1
- module MangoPay
1
+ require 'net/http'
2
+ require 'multi_json'
3
+
4
+ # Version
5
+ require 'mangopay/version'
6
+
7
+ # JSON
8
+ require 'mangopay/json'
2
9
 
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'
10
+ # Resources
11
+ require 'mangopay/http_calls'
12
+ require 'mangopay/resource'
13
+ require 'mangopay/client'
14
+ require 'mangopay/user'
15
+ require 'mangopay/natural_user'
16
+ require 'mangopay/legal_user'
17
+ require 'mangopay/payin'
18
+ require 'mangopay/payout'
19
+ require 'mangopay/transfer'
20
+ require 'mangopay/transaction'
21
+ require 'mangopay/wallet'
22
+ require 'mangopay/bank_account'
23
23
 
24
+ # Errors
25
+ require 'mangopay/errors'
26
+
27
+ module MangoPay
24
28
 
25
29
  class Configuration
26
- attr_accessor :base_url, :partner_id, :key_path, :key_password, :preproduction
30
+ attr_accessor :root_url, :client_id, :client_passphrase, :preproduction
27
31
 
28
32
  def preproduction
29
33
  @preproduction || false
30
34
  end
31
35
 
32
- def base_url
33
- @base_url || (@preproduction == true ? "https://api-preprod.leetchi.com" : "https://api.leetchi.com")
36
+ def root_url
37
+ @root_url || (@preproduction == true ? "https://mangopay-api-inte.leetchi.com" : "https://api.leetchi.com")
34
38
  end
35
39
  end
36
40
 
@@ -42,4 +46,70 @@ module MangoPay
42
46
  self.configuration ||= Configuration.new
43
47
  yield configuration
44
48
  end
49
+
50
+ def self.api_uri(url='')
51
+ URI(configuration.root_url + url)
52
+ end
53
+
54
+ def self.request(method, url, params={}, headers={})
55
+ uri = api_uri(url)
56
+
57
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
58
+ request = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, request_headers)
59
+ request.body = MangoPay::JSON.dump(params)
60
+ http.request request
61
+ end
62
+ MangoPay::JSON.load(res.body)
63
+ end
64
+
65
+ def self.user_agent
66
+ @uname ||= get_uname
67
+
68
+ {
69
+ bindings_version: MangoPay::VERSION,
70
+ lang: 'ruby',
71
+ lang_version: "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
72
+ platform: RUBY_PLATFORM,
73
+ uname: @uname
74
+ }
75
+ end
76
+
77
+ def self.get_uname
78
+ `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
79
+ rescue Errno::ENOMEM
80
+ 'uname lookup failed'
81
+ end
82
+
83
+ def self.get_oauth_token
84
+ if @auth_timestamp.nil? || @auth_timestamp <= Time.now || @auth_token.nil?
85
+ uri = api_uri('/api/oauth/token')
86
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
87
+ req = Net::HTTP::Post.new(uri.request_uri)
88
+ req.basic_auth configuration.client_id, configuration.client_passphrase
89
+ req.body = 'grant_type=client_credentials'
90
+ http.request req
91
+ end
92
+ @auth_token = MangoPay::JSON.load(res.body)
93
+ @auth_timestamp = Time.now + @auth_token['expires_in'].to_i
94
+ end
95
+ @auth_token
96
+ end
97
+
98
+ def self.oauth_token
99
+ oauth = get_oauth_token
100
+ "#{oauth['token_type']} #{oauth['access_token']}"
101
+ end
102
+
103
+ def self.request_headers
104
+ headers = {
105
+ 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
106
+ 'Authorization' => oauth_token,
107
+ 'Content-Type' => 'application/json'
108
+ }
109
+ begin
110
+ headers.update('x_mangopay_client_user_agent' => MangoPay::JSON.dump(user_agent))
111
+ rescue => e
112
+ headers.update('x_mangopay_client_raw_user_agent' => user_agent.inspect, error: "#{e} (#{e.class})")
113
+ end
114
+ end
45
115
  end
@@ -0,0 +1,21 @@
1
+ module MangoPay
2
+ class BankAccount < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Fetch
5
+
6
+ def self.fetch(*ids)
7
+ url = ids.length == 1 ? url(ids[0]) : url(ids[0], ids[1])
8
+ MangoPay.request(:get, url)
9
+ end
10
+
11
+ private
12
+
13
+ def self.url(*id)
14
+ if id.length == 1
15
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts"
16
+ else
17
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts/#{CGI.escape(id[1])}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module MangoPay
2
+ class Client < Resource
3
+
4
+ def self.create(params)
5
+ uri = URI(MangoPay.configuration.root_url + '/api/clients/')
6
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
7
+ request = Net::HTTP::Post.new(uri.request_uri, {
8
+ 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
9
+ 'Content-Type' => 'application/json'
10
+ })
11
+ request.body = MangoPay::JSON.dump(params)
12
+ http.request request
13
+ end
14
+ MangoPay::JSON.load(res.body)
15
+ end
16
+ end
17
+ end