mangopay 3.0.23 → 3.0.25.pre.alpha.pre.20
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,38 +1,38 @@
|
|
1
|
-
module MangoPay
|
2
|
-
|
3
|
-
# See http://docs.mangopay.com/api-references/bank-accounts/
|
4
|
-
class BankAccount < Resource
|
5
|
-
include HTTPCalls::Fetch
|
6
|
-
class << self
|
7
|
-
def create(user_id, params, idempotency_key = nil)
|
8
|
-
type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') }
|
9
|
-
MangoPay.request(:post, "#{url(user_id)}/#{type}", params, {}, idempotency_key)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Fetches:
|
13
|
-
# - list of bank accounts belonging to the given +user_id+
|
14
|
-
# - or single bank account belonging to the given +user_id+ with the given +bank_account_id+.
|
15
|
-
#
|
16
|
-
# In case of list query, optional +filters+ is a hash accepting pagination and sorting params
|
17
|
-
# (+page+, +per_page+, +sort+; see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
18
|
-
#
|
19
|
-
def fetch(user_id, bank_account_id_or_filters={})
|
20
|
-
bank_account_id, filters = HTTPCalls::Fetch.parse_id_or_filters(bank_account_id_or_filters)
|
21
|
-
MangoPay.request(:get, url(user_id, bank_account_id), {}, filters)
|
22
|
-
end
|
23
|
-
|
24
|
-
# see https://docs.mangopay.com/endpoints/v2.01/bank-accounts#e306_disactivate-a-bank-account
|
25
|
-
def update(user_id, bank_account_id, params = {})
|
26
|
-
MangoPay.request(:put, url(user_id, bank_account_id), params)
|
27
|
-
end
|
28
|
-
|
29
|
-
def url(user_id, bank_account_id = nil)
|
30
|
-
if bank_account_id
|
31
|
-
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts/#{CGI.escape(bank_account_id.to_s)}"
|
32
|
-
else
|
33
|
-
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module MangoPay
|
2
|
+
|
3
|
+
# See http://docs.mangopay.com/api-references/bank-accounts/
|
4
|
+
class BankAccount < Resource
|
5
|
+
include HTTPCalls::Fetch
|
6
|
+
class << self
|
7
|
+
def create(user_id, params, idempotency_key = nil)
|
8
|
+
type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') }
|
9
|
+
MangoPay.request(:post, "#{url(user_id)}/#{type}", params, {}, idempotency_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Fetches:
|
13
|
+
# - list of bank accounts belonging to the given +user_id+
|
14
|
+
# - or single bank account belonging to the given +user_id+ with the given +bank_account_id+.
|
15
|
+
#
|
16
|
+
# In case of list query, optional +filters+ is a hash accepting pagination and sorting params
|
17
|
+
# (+page+, +per_page+, +sort+; see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
18
|
+
#
|
19
|
+
def fetch(user_id, bank_account_id_or_filters={})
|
20
|
+
bank_account_id, filters = HTTPCalls::Fetch.parse_id_or_filters(bank_account_id_or_filters)
|
21
|
+
MangoPay.request(:get, url(user_id, bank_account_id), {}, filters)
|
22
|
+
end
|
23
|
+
|
24
|
+
# see https://docs.mangopay.com/endpoints/v2.01/bank-accounts#e306_disactivate-a-bank-account
|
25
|
+
def update(user_id, bank_account_id, params = {})
|
26
|
+
MangoPay.request(:put, url(user_id, bank_account_id), params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def url(user_id, bank_account_id = nil)
|
30
|
+
if bank_account_id
|
31
|
+
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts/#{CGI.escape(bank_account_id.to_s)}"
|
32
|
+
else
|
33
|
+
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/mangopay/card.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module MangoPay
|
2
|
-
|
3
|
-
# See http://docs.mangopay.com/api-references/card/
|
4
|
-
class Card < Resource
|
5
|
-
include HTTPCalls::Fetch
|
6
|
-
include HTTPCalls::Update
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module MangoPay
|
2
|
+
|
3
|
+
# See http://docs.mangopay.com/api-references/card/
|
4
|
+
class Card < Resource
|
5
|
+
include HTTPCalls::Fetch
|
6
|
+
include HTTPCalls::Update
|
7
|
+
end
|
8
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module MangoPay
|
2
|
-
|
3
|
-
# See http://docs.mangopay.com/api-references/card-registration/
|
4
|
-
class CardRegistration < Resource
|
5
|
-
include HTTPCalls::Create
|
6
|
-
include HTTPCalls::Update
|
7
|
-
include HTTPCalls::Fetch
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module MangoPay
|
2
|
+
|
3
|
+
# See http://docs.mangopay.com/api-references/card-registration/
|
4
|
+
class CardRegistration < Resource
|
5
|
+
include HTTPCalls::Create
|
6
|
+
include HTTPCalls::Update
|
7
|
+
include HTTPCalls::Fetch
|
8
|
+
end
|
9
|
+
end
|
data/lib/mangopay/client.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
module MangoPay
|
4
|
-
class Client < Resource
|
5
|
-
|
6
|
-
class << self
|
7
|
-
|
8
|
-
# see https://docs.mangopay.com/api-references/client-details/
|
9
|
-
def fetch()
|
10
|
-
MangoPay.request(:get, url())
|
11
|
-
end
|
12
|
-
|
13
|
-
# see https://docs.mangopay.com/api-references/client-details/
|
14
|
-
def update(params)
|
15
|
-
MangoPay.request(:put, url(), params)
|
16
|
-
end
|
17
|
-
|
18
|
-
# see https://docs.mangopay.com/api-references/client-details/
|
19
|
-
def upload_logo(file_content_base64, file_path = nil)
|
20
|
-
if file_content_base64.nil? && !file_path.nil?
|
21
|
-
bts = File.open(file_path, 'rb') { |f| f.read }
|
22
|
-
file_content_base64 = Base64.encode64(bts)
|
23
|
-
end
|
24
|
-
# normally it returns 204 HTTP code on success
|
25
|
-
begin
|
26
|
-
MangoPay.request(:put, url() + '/logo', {'File' => file_content_base64})
|
27
|
-
rescue ResponseError => ex
|
28
|
-
raise ex unless ex.code == '204'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Fetch all your client wallets;
|
33
|
-
# +funds_type+ may be:
|
34
|
-
# - nil: all wallets
|
35
|
-
# - 'fees': fees wallets
|
36
|
-
# - 'credit': credit wallets
|
37
|
-
# see https://docs.mangopay.com/api-references/client-wallets/
|
38
|
-
def fetch_wallets(funds_type = nil)
|
39
|
-
MangoPay.request(:get, url() + "/wallets/#{funds_type}")
|
40
|
-
end
|
41
|
-
|
42
|
-
# Fetch one of your client wallets (fees or credit) with a particular currency;
|
43
|
-
# +funds_type+ may be:
|
44
|
-
# - nil: all wallets
|
45
|
-
# - 'fees': fees wallets
|
46
|
-
# - 'credit': credit wallets
|
47
|
-
# +currency_iso_code+ is currncy ISO code
|
48
|
-
# see https://docs.mangopay.com/api-references/client-wallets/
|
49
|
-
def fetch_wallet(funds_type, currency_iso_code)
|
50
|
-
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}")
|
51
|
-
end
|
52
|
-
|
53
|
-
# Fetch transactions for all your client wallets.
|
54
|
-
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
55
|
-
# See https://docs.mangopay.com/api-references/client-wallets/
|
56
|
-
def fetch_wallets_transactions(filters = {})
|
57
|
-
MangoPay.request(:get, url() + "/transactions", {}, filters)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Fetch transactions for one of your client wallets (fees or credit) with a particular currency;
|
61
|
-
# +funds_type+ may be:
|
62
|
-
# - nil: all wallets
|
63
|
-
# - 'fees': fees wallets
|
64
|
-
# - 'credit': credit wallets
|
65
|
-
# +currency_iso_code+ is currncy ISO code
|
66
|
-
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
67
|
-
# See https://docs.mangopay.com/api-references/client-wallets/
|
68
|
-
def fetch_wallet_transactions(funds_type, currency_iso_code, filters = {})
|
69
|
-
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}/transactions", {}, filters)
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module MangoPay
|
4
|
+
class Client < Resource
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
9
|
+
def fetch()
|
10
|
+
MangoPay.request(:get, url())
|
11
|
+
end
|
12
|
+
|
13
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
14
|
+
def update(params)
|
15
|
+
MangoPay.request(:put, url(), params)
|
16
|
+
end
|
17
|
+
|
18
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
19
|
+
def upload_logo(file_content_base64, file_path = nil)
|
20
|
+
if file_content_base64.nil? && !file_path.nil?
|
21
|
+
bts = File.open(file_path, 'rb') { |f| f.read }
|
22
|
+
file_content_base64 = Base64.encode64(bts)
|
23
|
+
end
|
24
|
+
# normally it returns 204 HTTP code on success
|
25
|
+
begin
|
26
|
+
MangoPay.request(:put, url() + '/logo', {'File' => file_content_base64})
|
27
|
+
rescue ResponseError => ex
|
28
|
+
raise ex unless ex.code == '204'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Fetch all your client wallets;
|
33
|
+
# +funds_type+ may be:
|
34
|
+
# - nil: all wallets
|
35
|
+
# - 'fees': fees wallets
|
36
|
+
# - 'credit': credit wallets
|
37
|
+
# see https://docs.mangopay.com/api-references/client-wallets/
|
38
|
+
def fetch_wallets(funds_type = nil)
|
39
|
+
MangoPay.request(:get, url() + "/wallets/#{funds_type}")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Fetch one of your client wallets (fees or credit) with a particular currency;
|
43
|
+
# +funds_type+ may be:
|
44
|
+
# - nil: all wallets
|
45
|
+
# - 'fees': fees wallets
|
46
|
+
# - 'credit': credit wallets
|
47
|
+
# +currency_iso_code+ is currncy ISO code
|
48
|
+
# see https://docs.mangopay.com/api-references/client-wallets/
|
49
|
+
def fetch_wallet(funds_type, currency_iso_code)
|
50
|
+
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Fetch transactions for all your client wallets.
|
54
|
+
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
55
|
+
# See https://docs.mangopay.com/api-references/client-wallets/
|
56
|
+
def fetch_wallets_transactions(filters = {})
|
57
|
+
MangoPay.request(:get, url() + "/transactions", {}, filters)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Fetch transactions for one of your client wallets (fees or credit) with a particular currency;
|
61
|
+
# +funds_type+ may be:
|
62
|
+
# - nil: all wallets
|
63
|
+
# - 'fees': fees wallets
|
64
|
+
# - 'credit': credit wallets
|
65
|
+
# +currency_iso_code+ is currncy ISO code
|
66
|
+
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
67
|
+
# See https://docs.mangopay.com/api-references/client-wallets/
|
68
|
+
def fetch_wallet_transactions(funds_type, currency_iso_code, filters = {})
|
69
|
+
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}/transactions", {}, filters)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/mangopay/dispute.rb
CHANGED
@@ -1,130 +1,130 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
module MangoPay
|
4
|
-
|
5
|
-
# See https://docs.mangopay.com/api-references/disputes/disputes/
|
6
|
-
class Dispute < Resource
|
7
|
-
include HTTPCalls::Fetch
|
8
|
-
include HTTPCalls::Update
|
9
|
-
class << self
|
10
|
-
|
11
|
-
def close(dispute_id)
|
12
|
-
url = url(dispute_id) + "/close/"
|
13
|
-
MangoPay.request(:put, url)
|
14
|
-
end
|
15
|
-
|
16
|
-
# +contested_funds+: Money hash
|
17
|
-
# see 'Contest' section @ https://docs.mangopay.com/api-references/disputes/disputes/
|
18
|
-
def contest(dispute_id, contested_funds)
|
19
|
-
url = url(dispute_id) + "/submit/"
|
20
|
-
MangoPay.request(:put, url, {ContestedFunds: contested_funds})
|
21
|
-
end
|
22
|
-
|
23
|
-
def resubmit(dispute_id)
|
24
|
-
url = url(dispute_id) + "/submit/"
|
25
|
-
MangoPay.request(:put, url)
|
26
|
-
end
|
27
|
-
|
28
|
-
def transactions(dispute_id, filters = {})
|
29
|
-
url = url(dispute_id) + "/transactions/"
|
30
|
-
MangoPay.request(:get, url, {}, filters)
|
31
|
-
end
|
32
|
-
|
33
|
-
def fetch_for_user(user_id, filters = {})
|
34
|
-
url = "#{MangoPay.api_path}/users/#{user_id}/disputes"
|
35
|
-
MangoPay.request(:get, url, {}, filters)
|
36
|
-
end
|
37
|
-
|
38
|
-
def fetch_for_wallet(wallet_id, filters = {})
|
39
|
-
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/disputes"
|
40
|
-
MangoPay.request(:get, url, {}, filters)
|
41
|
-
end
|
42
|
-
|
43
|
-
#####################################################
|
44
|
-
# repudiations / settlement transfers
|
45
|
-
#####################################################
|
46
|
-
|
47
|
-
# see https://docs.mangopay.com/api-references/disputes/repudiations/
|
48
|
-
def fetch_repudiation(repudiation_id)
|
49
|
-
url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}"
|
50
|
-
MangoPay.request(:get, url)
|
51
|
-
end
|
52
|
-
|
53
|
-
# +params+: hash; see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
|
54
|
-
def create_settlement_transfer(repudiation_id, params, idempotency_key = nil)
|
55
|
-
url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}/settlementtransfer/"
|
56
|
-
MangoPay.request(:post, url, params, {}, idempotency_key)
|
57
|
-
end
|
58
|
-
|
59
|
-
# see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
|
60
|
-
def fetch_settlement_transfer(transfer_id)
|
61
|
-
url = "#{MangoPay.api_path}/settlements/#{transfer_id}"
|
62
|
-
MangoPay.request(:get, url)
|
63
|
-
end
|
64
|
-
|
65
|
-
#####################################################
|
66
|
-
# documents
|
67
|
-
#####################################################
|
68
|
-
|
69
|
-
# +params+: hash; see https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
70
|
-
def create_document(dispute_id, params, idempotency_key = nil)
|
71
|
-
url = url(dispute_id) + "/documents/"
|
72
|
-
MangoPay.request(:post, url, params, {}, idempotency_key)
|
73
|
-
end
|
74
|
-
|
75
|
-
def fetch_document(document_id)
|
76
|
-
url = "#{MangoPay.api_path}/dispute-documents/#{document_id}"
|
77
|
-
MangoPay.request(:get, url)
|
78
|
-
end
|
79
|
-
|
80
|
-
# +params+: hash; see 'Edit' section @ https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
81
|
-
def update_document(dispute_id, document_id, params)
|
82
|
-
url = url(dispute_id) + "/documents/#{document_id}"
|
83
|
-
MangoPay.request(:put, url, params)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Fetches list of dispute documents:
|
87
|
-
# - for the particular dispute if +dispute_id+ is provided (not nil)
|
88
|
-
# - or for all disputes otherwise.
|
89
|
-
#
|
90
|
-
# Optional +filters+ is a hash accepting following keys:
|
91
|
-
# - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
92
|
-
# - filters such as +Type+ (e.g. 'REFUND_PROOF') and +Status+ (e.g. 'VALIDATED')
|
93
|
-
# - +BeforeDate+ (timestamp): filters documents with CreationDate _before_ this date
|
94
|
-
# - +AfterDate+ (timestamp): filters documents with CreationDate _after_ this date
|
95
|
-
#
|
96
|
-
# See https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
97
|
-
#
|
98
|
-
def fetch_documents(dispute_id = nil, filters = {})
|
99
|
-
url = (dispute_id) ? url(dispute_id) + "/documents/" : "#{MangoPay.api_path}/dispute-documents/"
|
100
|
-
MangoPay.request(:get, url, {}, filters)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Adds the file page (attachment) to the given document.
|
104
|
-
#
|
105
|
-
# See https://docs.mangopay.com/api-references/disputes/dispute-document-pages/ :
|
106
|
-
# - Document have to be in 'CREATED' Status
|
107
|
-
# - You can create as many pages as needed
|
108
|
-
# - Change Status to 'VALIDATION_ASKED' to submit dispute documents
|
109
|
-
#
|
110
|
-
# The file_content_base64 param may be:
|
111
|
-
# - Base64 encoded file content
|
112
|
-
# - or nil: in this case pass the file path in the next param
|
113
|
-
#
|
114
|
-
def create_document_page(dispute_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil)
|
115
|
-
if file_content_base64.nil? && !file_path.nil?
|
116
|
-
bts = File.open(file_path, 'rb') { |f| f.read }
|
117
|
-
file_content_base64 = Base64.encode64(bts)
|
118
|
-
end
|
119
|
-
# normally it returns 204 HTTP code on success
|
120
|
-
begin
|
121
|
-
url = url(dispute_id) + "/documents/#{document_id}/pages"
|
122
|
-
MangoPay.request(:post, url, {'File' => file_content_base64}, {}, idempotency_key)
|
123
|
-
rescue ResponseError => ex
|
124
|
-
raise ex unless ex.code == '204'
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module MangoPay
|
4
|
+
|
5
|
+
# See https://docs.mangopay.com/api-references/disputes/disputes/
|
6
|
+
class Dispute < Resource
|
7
|
+
include HTTPCalls::Fetch
|
8
|
+
include HTTPCalls::Update
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def close(dispute_id)
|
12
|
+
url = url(dispute_id) + "/close/"
|
13
|
+
MangoPay.request(:put, url)
|
14
|
+
end
|
15
|
+
|
16
|
+
# +contested_funds+: Money hash
|
17
|
+
# see 'Contest' section @ https://docs.mangopay.com/api-references/disputes/disputes/
|
18
|
+
def contest(dispute_id, contested_funds)
|
19
|
+
url = url(dispute_id) + "/submit/"
|
20
|
+
MangoPay.request(:put, url, {ContestedFunds: contested_funds})
|
21
|
+
end
|
22
|
+
|
23
|
+
def resubmit(dispute_id)
|
24
|
+
url = url(dispute_id) + "/submit/"
|
25
|
+
MangoPay.request(:put, url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def transactions(dispute_id, filters = {})
|
29
|
+
url = url(dispute_id) + "/transactions/"
|
30
|
+
MangoPay.request(:get, url, {}, filters)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_for_user(user_id, filters = {})
|
34
|
+
url = "#{MangoPay.api_path}/users/#{user_id}/disputes"
|
35
|
+
MangoPay.request(:get, url, {}, filters)
|
36
|
+
end
|
37
|
+
|
38
|
+
def fetch_for_wallet(wallet_id, filters = {})
|
39
|
+
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/disputes"
|
40
|
+
MangoPay.request(:get, url, {}, filters)
|
41
|
+
end
|
42
|
+
|
43
|
+
#####################################################
|
44
|
+
# repudiations / settlement transfers
|
45
|
+
#####################################################
|
46
|
+
|
47
|
+
# see https://docs.mangopay.com/api-references/disputes/repudiations/
|
48
|
+
def fetch_repudiation(repudiation_id)
|
49
|
+
url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}"
|
50
|
+
MangoPay.request(:get, url)
|
51
|
+
end
|
52
|
+
|
53
|
+
# +params+: hash; see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
|
54
|
+
def create_settlement_transfer(repudiation_id, params, idempotency_key = nil)
|
55
|
+
url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}/settlementtransfer/"
|
56
|
+
MangoPay.request(:post, url, params, {}, idempotency_key)
|
57
|
+
end
|
58
|
+
|
59
|
+
# see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
|
60
|
+
def fetch_settlement_transfer(transfer_id)
|
61
|
+
url = "#{MangoPay.api_path}/settlements/#{transfer_id}"
|
62
|
+
MangoPay.request(:get, url)
|
63
|
+
end
|
64
|
+
|
65
|
+
#####################################################
|
66
|
+
# documents
|
67
|
+
#####################################################
|
68
|
+
|
69
|
+
# +params+: hash; see https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
70
|
+
def create_document(dispute_id, params, idempotency_key = nil)
|
71
|
+
url = url(dispute_id) + "/documents/"
|
72
|
+
MangoPay.request(:post, url, params, {}, idempotency_key)
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_document(document_id)
|
76
|
+
url = "#{MangoPay.api_path}/dispute-documents/#{document_id}"
|
77
|
+
MangoPay.request(:get, url)
|
78
|
+
end
|
79
|
+
|
80
|
+
# +params+: hash; see 'Edit' section @ https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
81
|
+
def update_document(dispute_id, document_id, params)
|
82
|
+
url = url(dispute_id) + "/documents/#{document_id}"
|
83
|
+
MangoPay.request(:put, url, params)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Fetches list of dispute documents:
|
87
|
+
# - for the particular dispute if +dispute_id+ is provided (not nil)
|
88
|
+
# - or for all disputes otherwise.
|
89
|
+
#
|
90
|
+
# Optional +filters+ is a hash accepting following keys:
|
91
|
+
# - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
92
|
+
# - filters such as +Type+ (e.g. 'REFUND_PROOF') and +Status+ (e.g. 'VALIDATED')
|
93
|
+
# - +BeforeDate+ (timestamp): filters documents with CreationDate _before_ this date
|
94
|
+
# - +AfterDate+ (timestamp): filters documents with CreationDate _after_ this date
|
95
|
+
#
|
96
|
+
# See https://docs.mangopay.com/api-references/disputes/dispute-documents/
|
97
|
+
#
|
98
|
+
def fetch_documents(dispute_id = nil, filters = {})
|
99
|
+
url = (dispute_id) ? url(dispute_id) + "/documents/" : "#{MangoPay.api_path}/dispute-documents/"
|
100
|
+
MangoPay.request(:get, url, {}, filters)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Adds the file page (attachment) to the given document.
|
104
|
+
#
|
105
|
+
# See https://docs.mangopay.com/api-references/disputes/dispute-document-pages/ :
|
106
|
+
# - Document have to be in 'CREATED' Status
|
107
|
+
# - You can create as many pages as needed
|
108
|
+
# - Change Status to 'VALIDATION_ASKED' to submit dispute documents
|
109
|
+
#
|
110
|
+
# The file_content_base64 param may be:
|
111
|
+
# - Base64 encoded file content
|
112
|
+
# - or nil: in this case pass the file path in the next param
|
113
|
+
#
|
114
|
+
def create_document_page(dispute_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil)
|
115
|
+
if file_content_base64.nil? && !file_path.nil?
|
116
|
+
bts = File.open(file_path, 'rb') { |f| f.read }
|
117
|
+
file_content_base64 = Base64.encode64(bts)
|
118
|
+
end
|
119
|
+
# normally it returns 204 HTTP code on success
|
120
|
+
begin
|
121
|
+
url = url(dispute_id) + "/documents/#{document_id}/pages"
|
122
|
+
MangoPay.request(:post, url, {'File' => file_content_base64}, {}, idempotency_key)
|
123
|
+
rescue ResponseError => ex
|
124
|
+
raise ex unless ex.code == '204'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|