mangopay 3.0.9 → 3.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c3155df7c8b7d8eb28c67cd17e290b0b3494c87
4
- data.tar.gz: fdbea6236e07982dc34c46b2fe34a6c3873b2a6d
3
+ metadata.gz: 8ee60e9e4be478bcf133043dc0964460add92477
4
+ data.tar.gz: 9adb1bb50315612ad35daef622299e9ab8f88d6f
5
5
  SHA512:
6
- metadata.gz: 9961531e7b10868ef7d1e1a343fb1a1dd9928cfa9c7489fcc5b42444e7062068545486716a4876d7d67bb0d8af6a9e7ece7a0b9208e099bfb1de36618e02c6cd
7
- data.tar.gz: d29da37c98376db5bdca15321f0d21386f8fc06a76e2acf68d5b277f9e1f2aac78845dea2c0276ae5b657e93e516e5d082d223c01db361aca3edb453d13b3a4c
6
+ metadata.gz: 0c88319a7cc682c4c49efd3b144b0858eeebae0e04db3555c07cc3284dc264ce0f28d797dc4e27651e33d276ed32a6f17ee760e7ebe5a8390b88a05e5742329e
7
+ data.tar.gz: e5f074fc62347bb9cbfc5642ed316273222f99cba4583b46dfedbf57b79d24683d89c12f86729fc916ec11d0046eac7eb879fef269b6d7d11fe90ddd149de92e
@@ -18,7 +18,7 @@ module Mangopay
18
18
  remove_file 'config/initializers/mangopay.rb'
19
19
  @client_id = client_id
20
20
  @client_passphrase = client['Passphrase']
21
- template 'mangopay.rb', 'config/initializers/mangopay.rb'
21
+ template 'mangopay.rb.erb', 'config/initializers/mangopay.rb'
22
22
  rescue => e
23
23
  puts e.message
24
24
  end
data/lib/mangopay.rb CHANGED
@@ -27,6 +27,7 @@ require 'mangopay/card'
27
27
  require 'mangopay/event'
28
28
  require 'mangopay/kyc_document'
29
29
  require 'mangopay/hook'
30
+ require 'mangopay/refund'
30
31
 
31
32
  module MangoPay
32
33
 
@@ -128,7 +129,7 @@ module MangoPay
128
129
  def self.request_headers
129
130
  auth_token = MangoPay::AuthorizationToken::Manager.get_token
130
131
  headers = {
131
- 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
132
+ 'user_agent' => "MangoPay V2 RubyBindings/#{MangoPay::VERSION}",
132
133
  'Authorization' => "#{auth_token['token_type']} #{auth_token['access_token']}",
133
134
  'Content-Type' => 'application/json'
134
135
  }
@@ -1,76 +1,78 @@
1
- module MangoPay
2
- module AuthorizationToken
3
-
4
- class Manager
5
-
6
- class << self
7
- def storage
8
- @@storage ||= StaticStorage.new
9
- end
10
- def storage= (storage)
11
- @@storage = storage
12
- end
13
- end
14
-
15
- def self.get_token
16
- token = storage.get
17
- if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now
18
- token = MangoPay.request(:post, '/api/oauth/token', {}, {}, {}, Proc.new do |req|
19
- cfg = MangoPay.configuration
20
- req.basic_auth cfg.client_id, cfg.client_passphrase
21
- req.body = 'grant_type=client_credentials'
22
- end)
23
- token['timestamp'] = Time.now + token['expires_in'].to_i
24
- storage.store token
25
- end
26
- token
27
- end
28
- end
29
-
30
- class StaticStorage
31
- def get
32
- @@token ||= nil
33
- end
34
- def store(token)
35
- @@token = token
36
- end
37
- end
38
-
39
- class FileStorage
40
- require 'yaml'
41
- @temp_dir
42
-
43
- def initialize(temp_dir = nil)
44
- @temp_dir = temp_dir || MangoPay.configuration.temp_dir
45
- if !@temp_dir
46
- raise "Path to temporary folder is not defined"
47
- end
48
- end
49
-
50
- def get
51
- begin
52
- f = File.open(file_path, File::RDONLY)
53
- f.flock(File::LOCK_SH)
54
- txt = f.read
55
- f.close
56
- YAML.load(txt) || nil
57
- rescue Errno::ENOENT
58
- nil
59
- end
60
- end
61
-
62
- def store(token)
63
- File.open(file_path, File::RDWR|File::CREAT, 0644) do |f|
64
- f.flock(File::LOCK_EX)
65
- f.truncate(0)
66
- f.rewind
67
- f.puts(YAML.dump(token))
68
- end
69
- end
70
-
71
- def file_path
72
- File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp")
73
- end
74
- end
75
- end
76
- end
1
+ module MangoPay
2
+ module AuthorizationToken
3
+
4
+ class Manager
5
+
6
+ class << self
7
+ def storage
8
+ @@storage ||= StaticStorage.new
9
+ end
10
+
11
+ def storage= (storage)
12
+ @@storage = storage
13
+ end
14
+
15
+ def get_token
16
+ token = storage.get
17
+ if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now
18
+ token = MangoPay.request(:post, '/api/oauth/token', {}, {}, {}, Proc.new do |req|
19
+ cfg = MangoPay.configuration
20
+ req.basic_auth cfg.client_id, cfg.client_passphrase
21
+ req.body = 'grant_type=client_credentials'
22
+ end)
23
+ token['timestamp'] = Time.now + token['expires_in'].to_i
24
+ storage.store token
25
+ end
26
+ token
27
+ end
28
+ end
29
+ end
30
+
31
+ class StaticStorage
32
+ def get
33
+ @@token ||= nil
34
+ end
35
+
36
+ def store(token)
37
+ @@token = token
38
+ end
39
+ end
40
+
41
+ class FileStorage
42
+ require 'yaml'
43
+ @temp_dir
44
+
45
+ def initialize(temp_dir = nil)
46
+ @temp_dir = temp_dir || MangoPay.configuration.temp_dir
47
+ if !@temp_dir
48
+ raise "Path to temporary folder is not defined"
49
+ end
50
+ end
51
+
52
+ def get
53
+ begin
54
+ f = File.open(file_path, File::RDONLY)
55
+ f.flock(File::LOCK_SH)
56
+ txt = f.read
57
+ f.close
58
+ YAML.load(txt) || nil
59
+ rescue Errno::ENOENT
60
+ nil
61
+ end
62
+ end
63
+
64
+ def store(token)
65
+ File.open(file_path, File::RDWR|File::CREAT, 0644) do |f|
66
+ f.flock(File::LOCK_EX)
67
+ f.truncate(0)
68
+ f.rewind
69
+ f.puts(YAML.dump(token))
70
+ end
71
+ end
72
+
73
+ def file_path
74
+ File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,31 +1,30 @@
1
1
  module MangoPay
2
2
  class BankAccount < Resource
3
3
  include MangoPay::HTTPCalls::Fetch
4
+ class << self
5
+ def create(user_id, params)
6
+ type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') }
7
+ MangoPay.request(:post, "#{url(user_id)}/#{type}", params)
8
+ end
4
9
 
5
- def self.create(user_id, params)
6
- type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') }
7
- MangoPay.request(:post, "#{url(user_id)}/#{type}", params)
8
- end
9
-
10
- # Fetches:
11
- # - list of bank accounts belonging to the given +user_id+
12
- # - or single bank account belonging to the given +user_id+ with the given +bank_account_id+.
13
- #
14
- # In case of list query, optional +filters+ is a hash accepting pagination params
15
- # (+page+, +per_page+; see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
16
- #
17
- def self.fetch(user_id, bank_account_id_or_filters={})
18
- bank_account_id, filters = MangoPay::HTTPCalls::Fetch.parse_id_or_filters(bank_account_id_or_filters)
19
- MangoPay.request(:get, url(user_id, bank_account_id), {}, filters)
20
- end
21
-
22
- private
10
+ # Fetches:
11
+ # - list of bank accounts belonging to the given +user_id+
12
+ # - or single bank account belonging to the given +user_id+ with the given +bank_account_id+.
13
+ #
14
+ # In case of list query, optional +filters+ is a hash accepting pagination params
15
+ # (+page+, +per_page+; see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
16
+ #
17
+ def fetch(user_id, bank_account_id_or_filters={})
18
+ bank_account_id, filters = MangoPay::HTTPCalls::Fetch.parse_id_or_filters(bank_account_id_or_filters)
19
+ MangoPay.request(:get, url(user_id, bank_account_id), {}, filters)
20
+ end
23
21
 
24
- def self.url(user_id, bank_account_id = nil)
25
- if bank_account_id
26
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/bankaccounts/#{CGI.escape(bank_account_id.to_s)}"
27
- else
28
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/bankaccounts"
22
+ def url(user_id, bank_account_id = nil)
23
+ if bank_account_id
24
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/bankaccounts/#{CGI.escape(bank_account_id.to_s)}"
25
+ else
26
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/bankaccounts"
27
+ end
29
28
  end
30
29
  end
31
30
  end
data/lib/mangopay/card.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module MangoPay
2
2
  class Card < Resource
3
3
  include MangoPay::HTTPCalls::Fetch
4
+ include MangoPay::HTTPCalls::Update
4
5
  end
5
6
  end
@@ -1,11 +1,11 @@
1
- module MangoPay
2
- class Client < Resource
3
-
4
- def self.create(params)
5
- MangoPay.request(:post, '/api/clients/', params, {}, {
6
- 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
7
- 'Content-Type' => 'application/json'
8
- })
9
- end
10
- end
11
- end
1
+ module MangoPay
2
+ class Client < Resource
3
+
4
+ def self.create(params)
5
+ MangoPay.request(:post, '/api/clients/', params, {}, {
6
+ 'user_agent' => "MangoPay V2 RubyBindings/#{MangoPay::VERSION}",
7
+ 'Content-Type' => 'application/json'
8
+ })
9
+ end
10
+ end
11
+ end
@@ -5,7 +5,7 @@ module MangoPay
5
5
 
6
6
  def create(*id, params)
7
7
  id = id.empty? ? nil : id[0]
8
- response = MangoPay.request(:post, url(id), params)
8
+ MangoPay.request(:post, url(id), params)
9
9
  end
10
10
  end
11
11
 
@@ -17,7 +17,7 @@ module MangoPay
17
17
  module Update
18
18
  module ClassMethods
19
19
  def update(id = nil, params = {})
20
- response = MangoPay.request(:put, url(id), params)
20
+ MangoPay.request(:put, url(id), params)
21
21
  end
22
22
  end
23
23
 
data/lib/mangopay/json.rb CHANGED
@@ -1,20 +1,22 @@
1
1
  module MangoPay
2
2
  module JSON
3
- if MultiJson.respond_to?(:dump)
4
- def self.dump(*args)
5
- MultiJson.dump(*args)
6
- end
3
+ class << self
4
+ if MultiJson.respond_to?(:dump)
5
+ def dump(*args)
6
+ MultiJson.dump(*args)
7
+ end
7
8
 
8
- def self.load(*args)
9
- MultiJson.load(*args)
10
- end
11
- else
12
- def self.dump(*args)
13
- MultiJson.encode(*args)
14
- end
9
+ def load(*args)
10
+ MultiJson.load(*args)
11
+ end
12
+ else
13
+ def dump(*args)
14
+ MultiJson.encode(*args)
15
+ end
15
16
 
16
- def self.load(*args)
17
- MultiJson.decode(*args)
17
+ def load(*args)
18
+ MultiJson.decode(*args)
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -2,47 +2,46 @@ require 'base64'
2
2
 
3
3
  module MangoPay
4
4
  class KycDocument < Resource
5
+ class << self
6
+ def create(user_id, params)
7
+ MangoPay.request(:post, url(user_id), params)
8
+ end
5
9
 
6
- def self.create(user_id, params)
7
- MangoPay.request(:post, url(user_id), params)
8
- end
9
-
10
- def self.update(user_id, document_id, params = {})
11
- MangoPay.request(:put, url(user_id, document_id), params)
12
- end
13
-
14
- def self.fetch(user_id, document_id)
15
- MangoPay.request(:get, url(user_id, document_id))
16
- end
10
+ def update(user_id, document_id, params = {})
11
+ MangoPay.request(:put, url(user_id, document_id), params)
12
+ end
17
13
 
18
- # Adds the file page (attachment) to the given document.
19
- #
20
- # See http://docs.mangopay.com/api-references/kyc/pages/ :
21
- # - Document have to be in 'CREATED' Status
22
- # - You can create as many pages as needed
23
- # - Change Status to 'VALIDATION_ASKED' to submit KYC documents
24
- #
25
- # The file_or_base64 param may be:
26
- # - either a File instance
27
- # - or a string: in this case it has to be Base64 encoded!
28
- #
29
- def self.create_page(user_id, document_id, file_or_base64)
30
- base64 = (file_or_base64.is_a? File) ? Base64.encode64(file_or_base64.read) : file_or_base64;
31
- # normally it returns 204 HTTP code on success
32
- begin
33
- MangoPay.request(:post, url(user_id, document_id) + '/pages', {'File' => base64})
34
- rescue MangoPay::ResponseError => ex
35
- raise ex unless ex.code == '204'
14
+ def fetch(user_id, document_id)
15
+ MangoPay.request(:get, url(user_id, document_id))
36
16
  end
37
- end
38
17
 
39
- private
18
+ # Adds the file page (attachment) to the given document.
19
+ #
20
+ # See http://docs.mangopay.com/api-references/kyc/pages/ :
21
+ # - Document have to be in 'CREATED' Status
22
+ # - You can create as many pages as needed
23
+ # - Change Status to 'VALIDATION_ASKED' to submit KYC documents
24
+ #
25
+ # The file_or_base64 param may be:
26
+ # - either a File instance
27
+ # - or a string: in this case it has to be Base64 encoded!
28
+ #
29
+ def create_page(user_id, document_id, file_or_base64)
30
+ base64 = (file_or_base64.is_a? File) ? Base64.encode64(file_or_base64.read) : file_or_base64;
31
+ # normally it returns 204 HTTP code on success
32
+ begin
33
+ MangoPay.request(:post, url(user_id, document_id) + '/pages', {'File' => base64})
34
+ rescue MangoPay::ResponseError => ex
35
+ raise ex unless ex.code == '204'
36
+ end
37
+ end
40
38
 
41
- def self.url(user_id, document_id = nil)
42
- if document_id
43
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/KYC/documents/#{CGI.escape(document_id.to_s)}"
44
- else
45
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/KYC/documents"
39
+ def url(user_id, document_id = nil)
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)}"
42
+ else
43
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(user_id.to_s)}/KYC/documents"
44
+ end
46
45
  end
47
46
  end
48
47
  end
@@ -1,8 +1,6 @@
1
1
  module MangoPay
2
2
  class LegalUser < User
3
3
 
4
- private
5
-
6
4
  def self.url(id = nil)
7
5
  if id
8
6
  "/v2/#{MangoPay.configuration.client_id}/users/legal/#{CGI.escape(id.to_s)}"
@@ -1,8 +1,6 @@
1
1
  module MangoPay
2
2
  class NaturalUser < User
3
3
 
4
- private
5
-
6
4
  def self.url(id = nil)
7
5
  if id
8
6
  "/v2/#{MangoPay.configuration.client_id}/users/natural/#{CGI.escape(id.to_s)}"
@@ -7,7 +7,6 @@ module MangoPay
7
7
 
8
8
  class Web < Resource
9
9
  include MangoPay::HTTPCalls::Create
10
- private
11
10
  def self.url(*)
12
11
  "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
13
12
  end
@@ -15,7 +14,6 @@ module MangoPay
15
14
 
16
15
  class Direct < Resource
17
16
  include MangoPay::HTTPCalls::Create
18
- private
19
17
  def self.url(*)
20
18
  "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
21
19
  end
@@ -27,7 +25,6 @@ module MangoPay
27
25
 
28
26
  class Direct < Resource
29
27
  include MangoPay::HTTPCalls::Create
30
- private
31
28
  def self.url(*)
32
29
  "/v2/#{MangoPay.configuration.client_id}/payins/preauthorized/direct"
33
30
  end
@@ -39,7 +36,6 @@ module MangoPay
39
36
 
40
37
  class Direct < Resource
41
38
  include MangoPay::HTTPCalls::Create
42
- private
43
39
  def self.url(*)
44
40
  "/v2/#{MangoPay.configuration.client_id}/payins/bankwire/direct"
45
41
  end
@@ -5,8 +5,6 @@ module MangoPay
5
5
  class BankWire < Resource
6
6
  include MangoPay::HTTPCalls::Create
7
7
 
8
- private
9
-
10
8
  def self.url(*)
11
9
  "/v2/#{MangoPay.configuration.client_id}/payouts/bankwire"
12
10
  end
@@ -0,0 +1,5 @@
1
+ module MangoPay
2
+ class Refund < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+ end
5
+ end
@@ -1,21 +1,20 @@
1
1
  module MangoPay
2
2
  # @abstract
3
3
  class Resource
4
-
5
- protected
6
-
7
- def self.class_name
8
- self.name.split('::')[-1]
9
- end
10
-
11
- def self.url(id = nil)
12
- if self == Resource
13
- raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
4
+ class << self
5
+ def class_name
6
+ name.split('::')[-1]
14
7
  end
15
- if id
16
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id.to_s)}"
17
- else
18
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
8
+
9
+ def url(id = nil)
10
+ if self == Resource
11
+ raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
12
+ end
13
+ if id
14
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id.to_s)}"
15
+ else
16
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
17
+ end
19
18
  end
20
19
  end
21
20
  end
@@ -1,25 +1,24 @@
1
- module MangoPay
2
- class Transaction < Resource
3
-
4
- # Fetches list of transactions belonging to the given +wallet_id+.
5
- #
6
- # Optional +filters+ is a hash accepting following keys:
7
- # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
8
- # - +Status+: TransactionStatus {CREATED, SUCCEEDED, FAILED}
9
- # - +Type+: TransactionType {PAYIN, PAYOUT, TRANSFER}
10
- # - +Nature+: TransactionNature {NORMAL, REFUND, REPUDIATION}
11
- # - +Direction+: TransactionDirection {DEBIT, CREDIT}
12
- # - +BeforeDate+ (timestamp): filters transactions with CreationDate _before_ this date
13
- # - +AfterDate+ (timestamp): filters transactions with CreationDate _after_ this date
14
- #
15
- def self.fetch(wallet_id, filters={})
16
- MangoPay.request(:get, url(wallet_id), {}, filters)
17
- end
18
-
19
- private
20
-
21
- def self.url(wallet_id)
22
- "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(wallet_id.to_s)}/transactions"
23
- end
24
- end
25
- end
1
+ module MangoPay
2
+ class Transaction < Resource
3
+ class << self
4
+ # Fetches list of transactions belonging to the given +wallet_id+.
5
+ #
6
+ # Optional +filters+ is a hash accepting following keys:
7
+ # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
8
+ # - +Status+: TransactionStatus {CREATED, SUCCEEDED, FAILED}
9
+ # - +Type+: TransactionType {PAYIN, PAYOUT, TRANSFER}
10
+ # - +Nature+: TransactionNature {NORMAL, REFUND, REPUDIATION}
11
+ # - +Direction+: TransactionDirection {DEBIT, CREDIT}
12
+ # - +BeforeDate+ (timestamp): filters transactions with CreationDate _before_ this date
13
+ # - +AfterDate+ (timestamp): filters transactions with CreationDate _after_ this date
14
+ #
15
+ def fetch(wallet_id, filters={})
16
+ MangoPay.request(:get, url(wallet_id), {}, filters)
17
+ end
18
+
19
+ def url(wallet_id)
20
+ "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(wallet_id.to_s)}/transactions"
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/mangopay/user.rb CHANGED
@@ -3,27 +3,28 @@ module MangoPay
3
3
  include MangoPay::HTTPCalls::Create
4
4
  include MangoPay::HTTPCalls::Update
5
5
  include MangoPay::HTTPCalls::Fetch
6
+ class << self
7
+ # Fetches list of wallets belonging to the given +user_id+.
8
+ # Optional +filters+ is a hash accepting following keys:
9
+ # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
10
+ # - other keys specific for transactions filtering (see MangoPay::Transaction.fetch)
11
+ def wallets(user_id, filters={})
12
+ MangoPay.request(:get, url(user_id) + '/wallets', {}, filters)
13
+ end
6
14
 
7
- # Fetches list of wallets belonging to the given +user_id+.
8
- # Optional +filters+ is a hash accepting following keys:
9
- # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
10
- # - other keys specific for transactions filtering (see MangoPay::Transaction.fetch)
11
- def self.wallets(user_id, filters={})
12
- MangoPay.request(:get, url(user_id) + '/wallets', {}, filters)
13
- end
14
-
15
- # Fetches list of cards belonging to the given +user_id+.
16
- # Optional +filters+ is a hash accepting following keys:
17
- # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
18
- def self.cards(user_id, filters={})
19
- MangoPay.request(:get, url(user_id) + '/cards', {}, filters)
20
- end
15
+ # Fetches list of cards belonging to the given +user_id+.
16
+ # Optional +filters+ is a hash accepting following keys:
17
+ # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
18
+ def cards(user_id, filters={})
19
+ MangoPay.request(:get, url(user_id) + '/cards', {}, filters)
20
+ end
21
21
 
22
- # Fetches list of transactions belonging to the given +user_id+.
23
- # Optional +filters+ is a hash accepting following keys:
24
- # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
25
- def self.transactions(user_id, filters={})
26
- MangoPay.request(:get, url(user_id) + '/transactions', {}, filters)
22
+ # Fetches list of transactions belonging to the given +user_id+.
23
+ # Optional +filters+ is a hash accepting following keys:
24
+ # - +page+, +per_page+: pagination params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
25
+ def transactions(user_id, filters={})
26
+ MangoPay.request(:get, url(user_id) + '/transactions', {}, filters)
27
+ end
27
28
  end
28
29
  end
29
30
  end
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.0.9'
2
+ VERSION = '3.0.10'
3
3
  end
@@ -1,86 +1,86 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::BankAccount do
4
- include_context 'bank_accounts'
5
-
6
- def create(params)
7
- params_fixed = { OwnerName: 'John', OwnerAddress: 'Here' }.merge(params)
8
- MangoPay::BankAccount.create(new_natural_user['Id'], params_fixed)
9
- end
10
-
11
- describe 'CREATE' do
12
-
13
- it 'creates a new IBAN bank detail' do
14
- expect(new_bank_account['Id']).not_to be_nil
15
- end
16
-
17
- it 'creates a new GB bank detail' do
18
- created = create({
19
- Type: 'GB',
20
- AccountNumber: '234234234234',
21
- SortCode: '234334',
22
- })
23
- expect(created['Id']).not_to be_nil
24
- expect(created['Type']).to eq('GB')
25
- expect(created['AccountNumber']).to eq('234234234234')
26
- expect(created['SortCode']).to eq('234334')
27
- end
28
-
29
- it 'creates a new US bank detail' do
30
- created = create({
31
- Type: 'US',
32
- AccountNumber: '234234234234',
33
- ABA: '234334789',
34
- })
35
- expect(created['Id']).not_to be_nil
36
- expect(created['Type']).to eq('US')
37
- expect(created['AccountNumber']).to eq('234234234234')
38
- expect(created['ABA']).to eq('234334789')
39
- end
40
-
41
- it 'creates a new CA bank detail' do
42
- created = create({
43
- Type: 'CA',
44
- BankName: 'TestBankName',
45
- BranchCode: '12345',
46
- AccountNumber: '234234234234',
47
- InstitutionNumber: '123',
48
- })
49
- expect(created['Id']).not_to be_nil
50
- expect(created['Type']).to eq('CA')
51
- expect(created['BankName']).to eq('TestBankName')
52
- expect(created['BranchCode']).to eq('12345')
53
- expect(created['AccountNumber']).to eq('234234234234')
54
- expect(created['InstitutionNumber']).to eq('123')
55
- end
56
-
57
- it 'creates a new OTHER bank detail' do
58
- created = create({
59
- Type: 'OTHER',
60
- Country: 'FR',
61
- AccountNumber: '234234234234',
62
- BIC: 'BINAADADXXX',
63
- })
64
- expect(created['Id']).not_to be_nil
65
- expect(created['Type']).to eq('OTHER')
66
- expect(created['Country']).to eq('FR')
67
- expect(created['AccountNumber']).to eq('234234234234')
68
- expect(created['BIC']).to eq('BINAADADXXX')
69
- end
70
-
71
- end
72
-
73
- describe 'FETCH' do
74
-
75
- it 'fetches all the bank details' do
76
- list = MangoPay::BankAccount.fetch(new_bank_account['UserId'])
77
- expect(list).to be_kind_of(Array)
78
- expect(list[0]['Id']).to eq(new_bank_account['Id'])
79
- end
80
-
81
- it 'fetches single bank detail' do
82
- single = MangoPay::BankAccount.fetch(new_bank_account['UserId'], new_bank_account['Id'])
83
- expect(single['Id']).to eq(new_bank_account['Id'])
84
- end
85
- end
86
- end
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::BankAccount do
4
+ include_context 'bank_accounts'
5
+
6
+ def create(params)
7
+ params_fixed = { OwnerName: 'John', OwnerAddress: 'Here' }.merge(params)
8
+ MangoPay::BankAccount.create(new_natural_user['Id'], params_fixed)
9
+ end
10
+
11
+ describe 'CREATE' do
12
+
13
+ it 'creates a new IBAN bank detail' do
14
+ expect(new_bank_account['Id']).not_to be_nil
15
+ end
16
+
17
+ it 'creates a new GB bank detail' do
18
+ created = create({
19
+ Type: 'GB',
20
+ AccountNumber: '18329068',
21
+ SortCode: '306541',
22
+ })
23
+ expect(created['Id']).not_to be_nil
24
+ expect(created['Type']).to eq('GB')
25
+ expect(created['AccountNumber']).to eq('18329068')
26
+ expect(created['SortCode']).to eq('306541')
27
+ end
28
+
29
+ it 'creates a new US bank detail' do
30
+ created = create({
31
+ Type: 'US',
32
+ AccountNumber: '234234234234',
33
+ ABA: '234334789',
34
+ })
35
+ expect(created['Id']).not_to be_nil
36
+ expect(created['Type']).to eq('US')
37
+ expect(created['AccountNumber']).to eq('234234234234')
38
+ expect(created['ABA']).to eq('234334789')
39
+ end
40
+
41
+ it 'creates a new CA bank detail' do
42
+ created = create({
43
+ Type: 'CA',
44
+ BankName: 'TestBankName',
45
+ BranchCode: '12345',
46
+ AccountNumber: '234234234234',
47
+ InstitutionNumber: '123',
48
+ })
49
+ expect(created['Id']).not_to be_nil
50
+ expect(created['Type']).to eq('CA')
51
+ expect(created['BankName']).to eq('TestBankName')
52
+ expect(created['BranchCode']).to eq('12345')
53
+ expect(created['AccountNumber']).to eq('234234234234')
54
+ expect(created['InstitutionNumber']).to eq('123')
55
+ end
56
+
57
+ it 'creates a new OTHER bank detail' do
58
+ created = create({
59
+ Type: 'OTHER',
60
+ Country: 'FR',
61
+ AccountNumber: '234234234234',
62
+ BIC: 'BINAADADXXX',
63
+ })
64
+ expect(created['Id']).not_to be_nil
65
+ expect(created['Type']).to eq('OTHER')
66
+ expect(created['Country']).to eq('FR')
67
+ expect(created['AccountNumber']).to eq('234234234234')
68
+ expect(created['BIC']).to eq('BINAADADXXX')
69
+ end
70
+
71
+ end
72
+
73
+ describe 'FETCH' do
74
+
75
+ it 'fetches all the bank details' do
76
+ list = MangoPay::BankAccount.fetch(new_bank_account['UserId'])
77
+ expect(list).to be_kind_of(Array)
78
+ expect(list[0]['Id']).to eq(new_bank_account['Id'])
79
+ end
80
+
81
+ it 'fetches single bank detail' do
82
+ single = MangoPay::BankAccount.fetch(new_bank_account['UserId'], new_bank_account['Id'])
83
+ expect(single['Id']).to eq(new_bank_account['Id'])
84
+ end
85
+ end
86
+ end
@@ -58,6 +58,17 @@ describe MangoPay::CardRegistration do
58
58
  # ...and points to existing (newly created) card
59
59
  card = MangoPay::Card.fetch(card_id)
60
60
  expect(card['Id']).to eq card_id
61
+
62
+ ################################################################################
63
+ # cannot test updating: one can only put a CARD from "VALID" to "INVALID"
64
+ # # let's test updating the card too
65
+ # expect(card['Validity']).to eq 'UNKNOWN'
66
+ # card_updated = MangoPay::Card.update(card_id ,{
67
+ # Validity: 'INVALID'
68
+ # })
69
+ # expect(card_updated['Validity']).to eq 'INVALID'
70
+ # expect(MangoPay::Card.fetch(card_id)['Validity']).to eq 'INVALID'
71
+ ################################################################################
61
72
  end
62
73
  end
63
74
 
@@ -0,0 +1,23 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Refund do
4
+ include_context 'transfers'
5
+
6
+ describe 'FETCH' do
7
+ it 'fetches a refund' do
8
+ transfer = new_transfer
9
+ resource = MangoPay::Transfer.refund(transfer['Id'], { AuthorId: transfer['AuthorId'] })
10
+
11
+ refund = MangoPay::Refund.fetch(resource['Id'])
12
+
13
+ expect(refund['Id']).not_to be_nil
14
+ expect(refund['Status']).to eq('SUCCEEDED')
15
+ expect(refund['Type']).to eq('TRANSFER')
16
+ expect(refund['Nature']).to eq('REFUND')
17
+ expect(refund['InitialTransactionType']).to eq('TRANSFER')
18
+ expect(refund['InitialTransactionId']).to eq(transfer['Id'])
19
+ expect(refund['DebitedWalletId']).to eq(transfer['CreditedWalletId'])
20
+ expect(refund['CreditedWalletId']).to eq(transfer['DebitedWalletId'])
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangopay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Lorieux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-05 00:00:00.000000000 Z
12
+ date: 2014-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -112,7 +112,7 @@ files:
112
112
  - README.md
113
113
  - bin/mangopay
114
114
  - lib/generators/mangopay/install_generator.rb
115
- - lib/generators/templates/mangopay.rb
115
+ - lib/generators/templates/mangopay.rb.erb
116
116
  - lib/mangopay.rb
117
117
  - lib/mangopay/authorization_token.rb
118
118
  - lib/mangopay/bank_account.rb
@@ -130,6 +130,7 @@ files:
130
130
  - lib/mangopay/payin.rb
131
131
  - lib/mangopay/payout.rb
132
132
  - lib/mangopay/preauthorization.rb
133
+ - lib/mangopay/refund.rb
133
134
  - lib/mangopay/resource.rb
134
135
  - lib/mangopay/transaction.rb
135
136
  - lib/mangopay/transfer.rb
@@ -152,6 +153,7 @@ files:
152
153
  - spec/lib/mangopay/payin_preauthorized_direct_spec.rb
153
154
  - spec/lib/mangopay/payout_bankwire_spec.rb
154
155
  - spec/lib/mangopay/preauthorization_spec.rb
156
+ - spec/lib/mangopay/refund_spec.rb
155
157
  - spec/lib/mangopay/shared_resources.rb
156
158
  - spec/lib/mangopay/transaction_spec.rb
157
159
  - spec/lib/mangopay/transfer_spec.rb
@@ -199,6 +201,7 @@ test_files:
199
201
  - spec/lib/mangopay/payin_preauthorized_direct_spec.rb
200
202
  - spec/lib/mangopay/payout_bankwire_spec.rb
201
203
  - spec/lib/mangopay/preauthorization_spec.rb
204
+ - spec/lib/mangopay/refund_spec.rb
202
205
  - spec/lib/mangopay/shared_resources.rb
203
206
  - spec/lib/mangopay/transaction_spec.rb
204
207
  - spec/lib/mangopay/transfer_spec.rb