mangopay 3.0.11 → 3.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/README.md +26 -0
  4. data/lib/mangopay.rb +97 -105
  5. data/lib/mangopay/bank_account.rb +4 -4
  6. data/lib/mangopay/card.rb +2 -2
  7. data/lib/mangopay/card_registration.rb +3 -3
  8. data/lib/mangopay/client.rb +1 -1
  9. data/lib/mangopay/errors.rb +35 -1
  10. data/lib/mangopay/event.rb +16 -16
  11. data/lib/mangopay/hook.rb +3 -3
  12. data/lib/mangopay/http_calls.rb +1 -1
  13. data/lib/mangopay/json.rb +6 -15
  14. data/lib/mangopay/kyc_document.rb +3 -3
  15. data/lib/mangopay/legal_user.rb +2 -2
  16. data/lib/mangopay/natural_user.rb +2 -2
  17. data/lib/mangopay/pay_in.rb +47 -0
  18. data/lib/mangopay/pay_out.rb +13 -0
  19. data/lib/mangopay/pre_authorization.rb +11 -0
  20. data/lib/mangopay/refund.rb +1 -1
  21. data/lib/mangopay/resource.rb +3 -3
  22. data/lib/mangopay/transaction.rb +1 -1
  23. data/lib/mangopay/transfer.rb +3 -3
  24. data/lib/mangopay/user.rb +3 -3
  25. data/lib/mangopay/version.rb +1 -1
  26. data/lib/mangopay/wallet.rb +5 -5
  27. data/mangopay.gemspec +3 -6
  28. data/spec/{lib/mangopay → mangopay}/authorization_token_spec.rb +70 -72
  29. data/spec/{lib/mangopay → mangopay}/bank_account_spec.rb +0 -2
  30. data/spec/{lib/mangopay → mangopay}/card_registration_spec.rb +0 -2
  31. data/spec/{lib/mangopay → mangopay}/client_spec.rb +2 -4
  32. data/spec/{lib/mangopay → mangopay}/configuration_spec.rb +18 -20
  33. data/spec/{lib/mangopay → mangopay}/event_spec.rb +31 -33
  34. data/spec/{lib/mangopay → mangopay}/fetch_filters_spec.rb +0 -2
  35. data/spec/{lib/mangopay → mangopay}/hook_spec.rb +0 -2
  36. data/spec/{lib/mangopay → mangopay}/kyc_document_spec.rb +58 -60
  37. data/spec/{lib/mangopay → mangopay}/payin_bankwire_direct_spec.rb +0 -2
  38. data/spec/{lib/mangopay → mangopay}/payin_card_direct_spec.rb +0 -2
  39. data/spec/{lib/mangopay → mangopay}/payin_card_web_spec.rb +54 -56
  40. data/spec/{lib/mangopay → mangopay}/payin_preauthorized_direct_spec.rb +0 -2
  41. data/spec/{lib/mangopay → mangopay}/payout_bankwire_spec.rb +54 -56
  42. data/spec/{lib/mangopay → mangopay}/preauthorization_spec.rb +0 -2
  43. data/spec/{lib/mangopay → mangopay}/refund_spec.rb +0 -2
  44. data/spec/{lib/mangopay → mangopay}/shared_resources.rb +0 -4
  45. data/spec/{lib/mangopay → mangopay}/transaction_spec.rb +0 -2
  46. data/spec/{lib/mangopay → mangopay}/transfer_spec.rb +0 -2
  47. data/spec/{lib/mangopay → mangopay}/user_spec.rb +0 -2
  48. data/spec/{lib/mangopay → mangopay}/wallet_spec.rb +87 -89
  49. data/spec/spec_helper.rb +28 -20
  50. metadata +53 -95
  51. data/lib/mangopay/payin.rb +0 -47
  52. data/lib/mangopay/payout.rb +0 -13
  53. data/lib/mangopay/preauthorization.rb +0 -11
data/lib/mangopay/hook.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module MangoPay
2
2
  class Hook < Resource
3
- include MangoPay::HTTPCalls::Create
4
- include MangoPay::HTTPCalls::Update
5
- include MangoPay::HTTPCalls::Fetch
3
+ include HTTPCalls::Create
4
+ include HTTPCalls::Update
5
+ include HTTPCalls::Fetch
6
6
  end
7
7
  end
@@ -46,7 +46,7 @@ module MangoPay
46
46
  # filter # => {"page"=>2, "per_page"=>3, "total_pages"=>1969, "total_items"=>5905}
47
47
  #
48
48
  def fetch(id_or_filters = nil)
49
- id, filters = MangoPay::HTTPCalls::Fetch.parse_id_or_filters(id_or_filters)
49
+ id, filters = HTTPCalls::Fetch.parse_id_or_filters(id_or_filters)
50
50
  response = MangoPay.request(:get, url(id), {}, filters)
51
51
  end
52
52
  end
data/lib/mangopay/json.rb CHANGED
@@ -1,22 +1,13 @@
1
+ # We can use MultiJson directly , why do we even have this module ?
1
2
  module MangoPay
2
3
  module JSON
3
4
  class << self
4
- if MultiJson.respond_to?(:dump)
5
- def dump(*args)
6
- MultiJson.dump(*args)
7
- end
8
-
9
- def load(*args)
10
- MultiJson.load(*args)
11
- end
12
- else
13
- def dump(*args)
14
- MultiJson.encode(*args)
15
- end
5
+ def dump(*args)
6
+ MultiJson.dump(*args)
7
+ end
16
8
 
17
- def load(*args)
18
- MultiJson.decode(*args)
19
- end
9
+ def load(*args)
10
+ MultiJson.load(*args)
20
11
  end
21
12
  end
22
13
  end
@@ -31,16 +31,16 @@ module MangoPay
31
31
  # normally it returns 204 HTTP code on success
32
32
  begin
33
33
  MangoPay.request(:post, url(user_id, document_id) + '/pages', {'File' => base64})
34
- rescue MangoPay::ResponseError => ex
34
+ rescue ResponseError => ex
35
35
  raise ex unless ex.code == '204'
36
36
  end
37
37
  end
38
38
 
39
39
  def url(user_id, document_id = nil)
40
40
  if document_id
41
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/KYC/documents/#{CGI.escape(document_id.to_s)}"
41
+ "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents/#{CGI.escape(document_id.to_s)}"
42
42
  else
43
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/KYC/documents"
43
+ "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents"
44
44
  end
45
45
  end
46
46
  end
@@ -3,9 +3,9 @@ module MangoPay
3
3
 
4
4
  def self.url(id = nil)
5
5
  if id
6
- "/v2/#{MangoPay.configuration.client_id}/users/legal/#{CGI.escape(id.to_s)}"
6
+ "#{MangoPay.api_path}/users/legal/#{CGI.escape(id.to_s)}"
7
7
  else
8
- "/v2/#{MangoPay.configuration.client_id}/users/legal"
8
+ "#{MangoPay.api_path}/users/legal"
9
9
  end
10
10
  end
11
11
  end
@@ -3,9 +3,9 @@ module MangoPay
3
3
 
4
4
  def self.url(id = nil)
5
5
  if id
6
- "/v2/#{MangoPay.configuration.client_id}/users/natural/#{CGI.escape(id.to_s)}"
6
+ "#{MangoPay.api_path}/users/natural/#{CGI.escape(id.to_s)}"
7
7
  else
8
- "/v2/#{MangoPay.configuration.client_id}/users/natural"
8
+ "#{MangoPay.api_path}/users/natural"
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,47 @@
1
+ module MangoPay
2
+ class PayIn < Resource
3
+ include HTTPCalls::Fetch
4
+ include HTTPCalls::Refund
5
+
6
+ module Card
7
+
8
+ class Web < Resource
9
+ include HTTPCalls::Create
10
+ def self.url(*)
11
+ "#{MangoPay.api_path}/payins/card/#{CGI.escape(class_name.downcase)}"
12
+ end
13
+ end
14
+
15
+ class Direct < Resource
16
+ include HTTPCalls::Create
17
+ def self.url(*)
18
+ "#{MangoPay.api_path}/payins/card/#{CGI.escape(class_name.downcase)}"
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ module PreAuthorized
25
+
26
+ class Direct < Resource
27
+ include HTTPCalls::Create
28
+ def self.url(*)
29
+ "#{MangoPay.api_path}/payins/preauthorized/direct"
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ module BankWire
36
+
37
+ class Direct < Resource
38
+ include HTTPCalls::Create
39
+ def self.url(*)
40
+ "#{MangoPay.api_path}/payins/bankwire/direct"
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module MangoPay
2
+ class PayOut < Resource
3
+ include HTTPCalls::Fetch
4
+
5
+ class BankWire < Resource
6
+ include HTTPCalls::Create
7
+
8
+ def self.url(*)
9
+ "#{MangoPay.api_path}/payouts/bankwire"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module MangoPay
2
+ class PreAuthorization < Resource
3
+ include HTTPCalls::Update
4
+ include HTTPCalls::Fetch
5
+
6
+ def self.create(params)
7
+ MangoPay.request(:post, "#{url}/card/direct", params)
8
+ end
9
+
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module MangoPay
2
2
  class Refund < Resource
3
- include MangoPay::HTTPCalls::Fetch
3
+ include HTTPCalls::Fetch
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ module MangoPay
3
3
  class Resource
4
4
  class << self
5
5
  def class_name
6
- name.split('::')[-1]
6
+ name.split('::').last
7
7
  end
8
8
 
9
9
  def url(id = nil)
@@ -11,9 +11,9 @@ module MangoPay
11
11
  raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
12
12
  end
13
13
  if id
14
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id.to_s)}"
14
+ "#{MangoPay.api_path}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id.to_s)}"
15
15
  else
16
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
16
+ "#{MangoPay.api_path}/#{CGI.escape(class_name.downcase)}s"
17
17
  end
18
18
  end
19
19
  end
@@ -17,7 +17,7 @@ module MangoPay
17
17
  end
18
18
 
19
19
  def url(wallet_id)
20
- "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(wallet_id.to_s)}/transactions"
20
+ "#{MangoPay.api_path}/wallets/#{CGI.escape(wallet_id.to_s)}/transactions"
21
21
  end
22
22
  end
23
23
  end
@@ -1,7 +1,7 @@
1
1
  module MangoPay
2
2
  class Transfer < Resource
3
- include MangoPay::HTTPCalls::Create
4
- include MangoPay::HTTPCalls::Fetch
5
- include MangoPay::HTTPCalls::Refund
3
+ include HTTPCalls::Create
4
+ include HTTPCalls::Fetch
5
+ include HTTPCalls::Refund
6
6
  end
7
7
  end
data/lib/mangopay/user.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module MangoPay
2
2
  class User < Resource
3
- include MangoPay::HTTPCalls::Create
4
- include MangoPay::HTTPCalls::Update
5
- include MangoPay::HTTPCalls::Fetch
3
+ include HTTPCalls::Create
4
+ include HTTPCalls::Update
5
+ include HTTPCalls::Fetch
6
6
  class << self
7
7
  # Fetches list of wallets belonging to the given +user_id+.
8
8
  # Optional +filters+ is a hash accepting following keys:
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.0.11'
2
+ VERSION = '3.0.12'
3
3
  end
@@ -1,15 +1,15 @@
1
1
  module MangoPay
2
2
  class Wallet < Resource
3
- include MangoPay::HTTPCalls::Create
4
- include MangoPay::HTTPCalls::Update
5
- include MangoPay::HTTPCalls::Fetch
3
+ include HTTPCalls::Create
4
+ include HTTPCalls::Update
5
+ include HTTPCalls::Fetch
6
6
 
7
7
  # Fetches list of transactions belonging to the given +wallet_id+.
8
8
  # Optional +filters+ is a hash accepting following keys:
9
9
  # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
10
10
  # - other keys specific for transactions filtering (see MangoPay::Transaction.fetch)
11
- def self.transactions(wallet_id, filters={})
12
- MangoPay::Transaction.fetch(wallet_id, filters)
11
+ def self.transactions(wallet_id, filters = {})
12
+ Transaction.fetch(wallet_id, filters)
13
13
  end
14
14
  end
15
15
  end
data/mangopay.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
3
  require 'mangopay/version'
4
4
 
@@ -20,11 +20,8 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency('multi_json', '>= 1.7.7')
22
22
 
23
- s.add_development_dependency('rake', '~> 10.1.0')
24
- s.add_development_dependency('rspec', '~> 2.14.1')
25
- s.add_development_dependency('capybara', '~> 2.1.0')
26
- s.add_development_dependency('capybara-webkit', '~> 1.0.0')
27
- s.add_development_dependency('rails', '~> 4.0.0')
23
+ s.add_development_dependency('rake', '>= 10.1.0')
24
+ s.add_development_dependency('rspec', '>= 3.0.0')
28
25
 
29
26
  s.files = `git ls-files`.split("\n")
30
27
  s.test_files = `git ls-files -- spec/*`.split("\n")
@@ -1,72 +1,70 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::AuthorizationToken do
4
-
5
- _default_static_storage = MangoPay::AuthorizationToken::Manager.storage
6
- _new_file_storage = MangoPay::AuthorizationToken::FileStorage.new
7
-
8
- it 'uses StaticStorage strategy by default' do
9
- storage = _default_static_storage
10
- expect(storage).to be_kind_of MangoPay::AuthorizationToken::StaticStorage
11
- end
12
-
13
- it 'allows set different storage strategies' do
14
-
15
- # set to FileStorage
16
- file_storage = _new_file_storage
17
- MangoPay::AuthorizationToken::Manager.storage = file_storage
18
- storage = MangoPay::AuthorizationToken::Manager.storage
19
- expect(storage).to be file_storage
20
-
21
- # reset to StaticStorage
22
- static_storage = _default_static_storage
23
- MangoPay::AuthorizationToken::Manager.storage = static_storage
24
- storage = MangoPay::AuthorizationToken::Manager.storage
25
- expect(storage).to be static_storage
26
- end
27
-
28
- describe MangoPay::AuthorizationToken::StaticStorage do
29
- it 'shares tokens between calls' do
30
- MangoPay::AuthorizationToken::Manager.storage = _default_static_storage
31
- users1 = MangoPay::User.fetch()
32
- token1 = MangoPay::AuthorizationToken::Manager.get_token
33
- users2 = MangoPay::User.fetch()
34
- token2 = MangoPay::AuthorizationToken::Manager.get_token
35
- expect(token1).to eq token2
36
- expect(token1).to be token2 # moreover, it's the same instance
37
- end
38
- end
39
-
40
- describe MangoPay::AuthorizationToken::FileStorage do
41
- it 'shares tokens between calls' do
42
- MangoPay::AuthorizationToken::Manager.storage = _new_file_storage
43
-
44
- users1 = MangoPay::User.fetch()
45
- token1 = MangoPay::AuthorizationToken::Manager.get_token
46
- users2 = MangoPay::User.fetch()
47
- token2 = MangoPay::AuthorizationToken::Manager.get_token
48
- expect(token1).to eq token2
49
- expect(token1).not_to be token2 # it's NOT the same instance
50
-
51
- MangoPay::AuthorizationToken::Manager.storage = _default_static_storage # cleanup
52
- end
53
-
54
- it 'uses temp file with serialized token' do
55
- MangoPay::AuthorizationToken::Manager.storage = _new_file_storage
56
-
57
- file_path = _new_file_storage.file_path
58
- dir_path = MangoPay.configuration.temp_dir
59
- expect(file_path.start_with? dir_path).to be_true
60
-
61
- token = MangoPay::AuthorizationToken::Manager.get_token
62
- expect(File.exists? file_path).to be_true
63
-
64
- f = File.open(file_path, File::RDONLY)
65
- txt = f.read
66
- f.close
67
- expect(txt.include? token['access_token']).to be_true
68
-
69
- MangoPay::AuthorizationToken::Manager.storage = _default_static_storage # cleanup
70
- end
71
- end
72
- end
1
+ describe MangoPay::AuthorizationToken do
2
+
3
+ _default_static_storage = MangoPay::AuthorizationToken::Manager.storage
4
+ _new_file_storage = MangoPay::AuthorizationToken::FileStorage.new
5
+
6
+ it 'uses StaticStorage strategy by default' do
7
+ storage = _default_static_storage
8
+ expect(storage).to be_kind_of MangoPay::AuthorizationToken::StaticStorage
9
+ end
10
+
11
+ it 'allows set different storage strategies' do
12
+
13
+ # set to FileStorage
14
+ file_storage = _new_file_storage
15
+ MangoPay::AuthorizationToken::Manager.storage = file_storage
16
+ storage = MangoPay::AuthorizationToken::Manager.storage
17
+ expect(storage).to be file_storage
18
+
19
+ # reset to StaticStorage
20
+ static_storage = _default_static_storage
21
+ MangoPay::AuthorizationToken::Manager.storage = static_storage
22
+ storage = MangoPay::AuthorizationToken::Manager.storage
23
+ expect(storage).to be static_storage
24
+ end
25
+
26
+ describe MangoPay::AuthorizationToken::StaticStorage do
27
+ it 'shares tokens between calls' do
28
+ MangoPay::AuthorizationToken::Manager.storage = _default_static_storage
29
+ users1 = MangoPay::User.fetch
30
+ token1 = MangoPay::AuthorizationToken::Manager.get_token
31
+ users2 = MangoPay::User.fetch
32
+ token2 = MangoPay::AuthorizationToken::Manager.get_token
33
+ expect(token1).to eq token2
34
+ expect(token1).to be token2 # moreover, it's the same instance
35
+ end
36
+ end
37
+
38
+ describe MangoPay::AuthorizationToken::FileStorage do
39
+ it 'shares tokens between calls' do
40
+ MangoPay::AuthorizationToken::Manager.storage = _new_file_storage
41
+
42
+ users1 = MangoPay::User.fetch
43
+ token1 = MangoPay::AuthorizationToken::Manager.get_token
44
+ users2 = MangoPay::User.fetch
45
+ token2 = MangoPay::AuthorizationToken::Manager.get_token
46
+ expect(token1).to eq token2
47
+ expect(token1).not_to be token2 # it's NOT the same instance
48
+
49
+ MangoPay::AuthorizationToken::Manager.storage = _default_static_storage # cleanup
50
+ end
51
+
52
+ it 'uses temp file with serialized token' do
53
+ MangoPay::AuthorizationToken::Manager.storage = _new_file_storage
54
+
55
+ file_path = _new_file_storage.file_path
56
+ dir_path = MangoPay.configuration.temp_dir
57
+ expect(file_path.start_with? dir_path).to be(true)
58
+
59
+ token = MangoPay::AuthorizationToken::Manager.get_token
60
+ expect(File.exists? file_path).to be(true)
61
+
62
+ f = File.open(file_path, File::RDONLY)
63
+ txt = f.read
64
+ f.close
65
+ expect(txt.include? token['access_token']).to be(true)
66
+
67
+ MangoPay::AuthorizationToken::Manager.storage = _default_static_storage # cleanup
68
+ end
69
+ end
70
+ end
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::BankAccount do
4
2
  include_context 'bank_accounts'
5
3
 
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::CardRegistration do
4
2
  include_context 'users'
5
3
  include_context 'payins'