mangopay 3.0.20 → 3.0.21
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 +4 -4
- data/README.md +4 -0
- data/lib/mangopay.rb +2 -0
- data/lib/mangopay/authorization_token.rb +10 -1
- data/lib/mangopay/client.rb +35 -5
- data/lib/mangopay/dispute.rb +6 -0
- data/lib/mangopay/kyc_document.rb +2 -1
- data/lib/mangopay/mandate.rb +32 -0
- data/lib/mangopay/pay_in.rb +8 -0
- data/lib/mangopay/version.rb +1 -1
- data/mangopay.gemspec +4 -4
- data/spec/mangopay/client_spec.png +0 -0
- data/spec/mangopay/client_spec.rb +46 -0
- data/spec/mangopay/dispute_spec.rb +26 -12
- data/spec/mangopay/{idempotency_spec → idempotency_spec.rb} +0 -0
- data/spec/mangopay/kyc_document_spec.rb +5 -0
- data/spec/mangopay/mandate_spec.rb +92 -0
- data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -0
- data/spec/mangopay/shared_resources.rb +34 -0
- data/spec/spec_helper.rb +2 -6
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b80399ecc8d9221db114f107e954ab277b6c72
|
4
|
+
data.tar.gz: 2d995aaed246ba27847e7671efcf24b439025059
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 495dbecbf3a741693d4da00b4cab946b5267f3a71cded1dff692586df537c49832b5fbfb7e12b3500b71d3f9e42a7e000c544df0e55bd273e1931c4819bd2ff0
|
7
|
+
data.tar.gz: eafb9be0c814ca133d04fc8b5af5d4e7a33618e3805a8fa8b7907ef69bc9e00da659439c2104d50cb19cd66892ae4e5e7d9654b2f1745ca4d04bb3826779ccec
|
data/README.md
CHANGED
@@ -16,6 +16,10 @@ and is not backward compatible with 2.* series.
|
|
16
16
|
|
17
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
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
|
+
|
19
23
|
## Usage
|
20
24
|
|
21
25
|
### Install
|
data/lib/mangopay.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'cgi/util'
|
3
|
+
require 'digest/md5'
|
3
4
|
require 'multi_json'
|
4
5
|
|
5
6
|
# helpers
|
@@ -29,6 +30,7 @@ module MangoPay
|
|
29
30
|
autoload :Hook, 'mangopay/hook'
|
30
31
|
autoload :Refund, 'mangopay/refund'
|
31
32
|
autoload :Dispute, 'mangopay/dispute'
|
33
|
+
autoload :Mandate, 'mangopay/mandate'
|
32
34
|
autoload :JSON, 'mangopay/json'
|
33
35
|
autoload :AuthorizationToken, 'mangopay/authorization_token'
|
34
36
|
|
@@ -15,17 +15,26 @@ module MangoPay
|
|
15
15
|
|
16
16
|
def get_token
|
17
17
|
token = storage.get
|
18
|
-
|
18
|
+
env_key = get_environment_key_for_token
|
19
|
+
if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
|
19
20
|
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
|
20
21
|
cfg = MangoPay.configuration
|
21
22
|
req.basic_auth cfg.client_id, cfg.client_passphrase
|
22
23
|
req.body = 'grant_type=client_credentials'
|
23
24
|
end)
|
24
25
|
token['timestamp'] = Time.now + token['expires_in'].to_i
|
26
|
+
token['environment_key'] = env_key
|
25
27
|
storage.store token
|
26
28
|
end
|
27
29
|
token
|
28
30
|
end
|
31
|
+
|
32
|
+
def get_environment_key_for_token
|
33
|
+
cfg = MangoPay.configuration
|
34
|
+
key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_passphrase}"
|
35
|
+
key = Digest::MD5.hexdigest(key)
|
36
|
+
key
|
37
|
+
end
|
29
38
|
end
|
30
39
|
end
|
31
40
|
|
data/lib/mangopay/client.rb
CHANGED
@@ -1,11 +1,41 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
1
3
|
module MangoPay
|
2
4
|
class Client < Resource
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
'
|
8
|
-
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def create(params)
|
9
|
+
MangoPay.request(:post, '/clients/', params, {}, {
|
10
|
+
'user_agent' => "MangoPay V2 RubyBindings/#{VERSION}",
|
11
|
+
'Content-Type' => 'application/json'
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
16
|
+
def fetch()
|
17
|
+
MangoPay.request(:get, url())
|
18
|
+
end
|
19
|
+
|
20
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
21
|
+
def update(params)
|
22
|
+
MangoPay.request(:put, url(), params)
|
23
|
+
end
|
24
|
+
|
25
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
26
|
+
def upload_logo(file_content_base64, file_path = nil)
|
27
|
+
if file_content_base64.nil? && !file_path.nil?
|
28
|
+
bts = File.open(file_path, 'rb') { |f| f.read }
|
29
|
+
file_content_base64 = Base64.encode64(bts)
|
30
|
+
end
|
31
|
+
# normally it returns 204 HTTP code on success
|
32
|
+
begin
|
33
|
+
MangoPay.request(:put, url() + '/logo', {'File' => file_content_base64})
|
34
|
+
rescue ResponseError => ex
|
35
|
+
raise ex unless ex.code == '204'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
9
39
|
end
|
10
40
|
end
|
11
41
|
end
|
data/lib/mangopay/dispute.rb
CHANGED
@@ -55,6 +55,12 @@ module MangoPay
|
|
55
55
|
url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}/settlementtransfer/"
|
56
56
|
MangoPay.request(:post, url, params, {}, idempotency_key)
|
57
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
|
58
64
|
|
59
65
|
#####################################################
|
60
66
|
# documents
|
@@ -15,7 +15,8 @@ module MangoPay
|
|
15
15
|
|
16
16
|
# Fetches the KYC document belonging to the given +user_id+, with the given +document_id+.
|
17
17
|
def fetch(user_id, document_id)
|
18
|
-
|
18
|
+
url = (user_id) ? url(user_id, document_id) : "#{MangoPay.api_path}/KYC/documents/#{CGI.escape(document_id.to_s)}"
|
19
|
+
MangoPay.request(:get, url)
|
19
20
|
end
|
20
21
|
|
21
22
|
# Fetches list of KYC documents:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MangoPay
|
2
|
+
|
3
|
+
# See https://docs.mangopay.com/api-references/mandates/
|
4
|
+
class Mandate < Resource
|
5
|
+
include HTTPCalls::Fetch
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# +params+: hash; see https://docs.mangopay.com/api-references/mandates/
|
10
|
+
def create(params, idempotency_key = nil)
|
11
|
+
url = "#{MangoPay.api_path}/mandates/directdebit/web"
|
12
|
+
MangoPay.request(:post, url, params, {}, idempotency_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def cancel(id)
|
16
|
+
url = "#{MangoPay.api_path}/mandates/#{id}/cancel"
|
17
|
+
MangoPay.request(:put, url)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch_for_user(user_id, filters = {})
|
21
|
+
url = "#{MangoPay.api_path}/users/#{user_id}/mandates"
|
22
|
+
MangoPay.request(:get, url, {}, filters)
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch_for_user_bank_account(user_id, bank_account_id, filters = {})
|
26
|
+
url = "#{MangoPay.api_path}/users/#{user_id}/bankaccounts/#{bank_account_id}/mandates"
|
27
|
+
MangoPay.request(:get, url, {}, filters)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/mangopay/pay_in.rb
CHANGED
@@ -59,6 +59,14 @@ module MangoPay
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# See https://docs.mangopay.com/api-references/payins/direct-debit-pay-in-direct/
|
63
|
+
class Direct < Resource
|
64
|
+
include HTTPCalls::Create
|
65
|
+
def self.url(*)
|
66
|
+
"#{MangoPay.api_path}/payins/directdebit/#{CGI.escape(class_name.downcase)}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
62
70
|
end
|
63
71
|
|
64
72
|
end
|
data/lib/mangopay/version.rb
CHANGED
data/mangopay.gemspec
CHANGED
@@ -5,11 +5,11 @@ require 'mangopay/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'mangopay'
|
7
7
|
s.version = MangoPay::VERSION
|
8
|
-
s.summary = "Ruby bindings for the version 2 of the
|
8
|
+
s.summary = "Ruby bindings for the version 2 of the MANGOPAY API"
|
9
9
|
s.description = <<-EOF
|
10
|
-
The mangopay Gem makes interacting with
|
11
|
-
For any questions regarding the use of
|
12
|
-
You can find more documentation about
|
10
|
+
The mangopay Gem makes interacting with MANGOPAY Services much easier.
|
11
|
+
For any questions regarding the use of MANGOPAY's Services feel free to contact us at http://www.mangopay.com/get-started-2/
|
12
|
+
You can find more documentation about MANGOPAY Services at http://docs.mangopay.com/
|
13
13
|
EOF
|
14
14
|
s.authors = ['Geoffroy Lorieux', 'Sergiusz Woznicki']
|
15
15
|
s.email = 'support@mangopay.com'
|
Binary file
|
@@ -25,4 +25,50 @@ describe MangoPay::Client do
|
|
25
25
|
}.to raise_error MangoPay::ResponseError
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
describe 'FETCH' do
|
30
|
+
it 'fetches the current client details' do
|
31
|
+
clnt = MangoPay::Client.fetch
|
32
|
+
expect(clnt['ClientId']).to eq(MangoPay.configuration.client_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'UPDATE' do
|
37
|
+
it 'updates the current client details' do
|
38
|
+
clnt = MangoPay::Client.fetch
|
39
|
+
before = clnt['PrimaryThemeColour']
|
40
|
+
after = before == '#aaaaaa' ? '#bbbbbb' : '#aaaaaa' # change the color
|
41
|
+
clnt['PrimaryThemeColour'] = after
|
42
|
+
|
43
|
+
updated = MangoPay::Client.update(clnt)
|
44
|
+
expect(updated['ClientId']).to eq(MangoPay.configuration.client_id)
|
45
|
+
expect(updated['PrimaryThemeColour']).to eq(after)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'UPLOAD LOGO' do
|
50
|
+
it 'accepts Base64 encoded file content' do
|
51
|
+
fnm = __FILE__.sub('.rb', '.png')
|
52
|
+
bts = File.open(fnm, 'rb') { |f| f.read }
|
53
|
+
b64 = Base64.encode64(bts)
|
54
|
+
ret = MangoPay::Client.upload_logo(b64)
|
55
|
+
expect(ret).to be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'accepts file path' do
|
59
|
+
fnm = __FILE__.sub('.rb', '.png')
|
60
|
+
ret = MangoPay::Client.upload_logo(nil, fnm)
|
61
|
+
expect(ret).to be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'fails when input string is not base64-encoded' do
|
65
|
+
file = 'any file content...'
|
66
|
+
expect { MangoPay::Client.upload_logo(file) }.to raise_error { |err|
|
67
|
+
expect(err).to be_a MangoPay::ResponseError
|
68
|
+
expect(err.code).to eq '400'
|
69
|
+
expect(err.type).to eq 'param_error'
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
28
74
|
end
|
@@ -25,7 +25,8 @@ describe MangoPay::Dispute do
|
|
25
25
|
|
26
26
|
describe 'TRANSACTIONS' do
|
27
27
|
it 'fetches transactions for dispute' do
|
28
|
-
|
28
|
+
dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
|
29
|
+
id = dispute['Id']
|
29
30
|
transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
|
30
31
|
expect(transactions).to be_kind_of(Array)
|
31
32
|
expect(transactions).not_to be_empty
|
@@ -34,7 +35,8 @@ describe MangoPay::Dispute do
|
|
34
35
|
|
35
36
|
describe 'FETCH FOR USER AND WALLET' do
|
36
37
|
it 'fetches disputes for user' do
|
37
|
-
|
38
|
+
dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
|
39
|
+
id = dispute['Id']
|
38
40
|
transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
|
39
41
|
user_id = transactions[0]['AuthorId']
|
40
42
|
disputes = MangoPay::Dispute.fetch_for_user(user_id, {'per_page' => 1})
|
@@ -64,8 +66,8 @@ describe MangoPay::Dispute do
|
|
64
66
|
|
65
67
|
describe 'FETCH REPUDIATION' do
|
66
68
|
it 'fetches a repudiation' do
|
67
|
-
dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil}
|
68
|
-
expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no disputes with transaction ID in the disputes list."
|
69
|
+
dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil && disp['DisputeType'] == 'NOT_CONTESTABLE'}
|
70
|
+
expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no not contestable disputes with transaction ID in the disputes list."
|
69
71
|
transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
|
70
72
|
repudiation_id = transactions[0]['Id']
|
71
73
|
repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
|
@@ -74,10 +76,10 @@ describe MangoPay::Dispute do
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
describe 'CREATE SETTLEMENT TRANSFER' do
|
78
|
-
it 'creates settlement transfer' do
|
79
|
-
dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED'}
|
80
|
-
expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed disputes in the disputes list."
|
79
|
+
describe 'CREATE AND FETCH SETTLEMENT TRANSFER' do
|
80
|
+
it 'creates and fetches settlement transfer' do
|
81
|
+
dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED' && disp['DisputeType'] == 'NOT_CONTESTABLE'}
|
82
|
+
expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed, not contestable disputes in the disputes list."
|
81
83
|
transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
|
82
84
|
repudiation_id = transactions[0]['Id']
|
83
85
|
repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
|
@@ -87,9 +89,14 @@ describe MangoPay::Dispute do
|
|
87
89
|
Fees: {Currency: 'EUR', Amount: 0},
|
88
90
|
Tag: 'Custom tag data'
|
89
91
|
}
|
92
|
+
|
90
93
|
transfer = MangoPay::Dispute.create_settlement_transfer(repudiation_id, params)
|
91
94
|
expect(transfer['Type']).to eq('TRANSFER')
|
92
95
|
expect(transfer['Nature']).to eq('SETTLEMENT')
|
96
|
+
|
97
|
+
fetched_transfer = MangoPay::Dispute.fetch_settlement_transfer(transfer['Id'])
|
98
|
+
expect(fetched_transfer['Id']).to eq(transfer['Id'])
|
99
|
+
expect(fetched_transfer['CreationDate']).to eq(transfer['CreationDate'])
|
93
100
|
end
|
94
101
|
end
|
95
102
|
|
@@ -136,7 +143,10 @@ describe MangoPay::Dispute do
|
|
136
143
|
end
|
137
144
|
|
138
145
|
it 'fetches a list of documents' do
|
139
|
-
disp =
|
146
|
+
disp = @disputes.find {|disp| disp['Status'] == 'SUBMITTED'}
|
147
|
+
disp = test_contest_dispute if disp == nil
|
148
|
+
expect(disp).not_to be_nil, "Cannot test fetching dispute documents because there's no dispute with expected status in the disputes list."
|
149
|
+
|
140
150
|
doc1 = create_doc(disp)
|
141
151
|
doc2 = create_doc(disp) # for the same dispute
|
142
152
|
|
@@ -195,8 +205,7 @@ describe MangoPay::Dispute do
|
|
195
205
|
end
|
196
206
|
end
|
197
207
|
|
198
|
-
|
199
|
-
it 'contests a dispute' do
|
208
|
+
def test_contest_dispute
|
200
209
|
dispute = @disputes.find do |disp|
|
201
210
|
['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
|
202
211
|
['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
|
@@ -207,6 +216,12 @@ describe MangoPay::Dispute do
|
|
207
216
|
changed_dispute = MangoPay::Dispute.contest(id, contested_funds)
|
208
217
|
expect(changed_dispute['Id']).to eq(id)
|
209
218
|
expect(changed_dispute['Status']).to eq('SUBMITTED')
|
219
|
+
changed_dispute
|
220
|
+
end
|
221
|
+
|
222
|
+
describe 'CONTEST' do
|
223
|
+
it 'contests a dispute' do
|
224
|
+
test_contest_dispute
|
210
225
|
end
|
211
226
|
end
|
212
227
|
|
@@ -236,5 +251,4 @@ describe MangoPay::Dispute do
|
|
236
251
|
expect(changed_dispute['Status']).to eq('CLOSED')
|
237
252
|
end
|
238
253
|
end
|
239
|
-
|
240
254
|
end
|
File without changes
|
@@ -26,6 +26,11 @@ describe MangoPay::KycDocument do
|
|
26
26
|
document = MangoPay::KycDocument.fetch(new_natural_user['Id'], new_document['Id'])
|
27
27
|
expect(document['Id']).to eq(new_document['Id'])
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'fetches a document just by id' do
|
31
|
+
document = MangoPay::KycDocument.fetch(nil, new_document['Id'])
|
32
|
+
expect(document['Id']).to eq(new_document['Id'])
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
describe 'FETCH ALL' do
|
@@ -0,0 +1,92 @@
|
|
1
|
+
describe MangoPay::Mandate do
|
2
|
+
include_context 'mandates'
|
3
|
+
|
4
|
+
def check_status(mandate)
|
5
|
+
expect(mandate['Status']).to eq('CREATED')
|
6
|
+
expect(mandate['MandateType']).to eq('DIRECT_DEBIT')
|
7
|
+
expect(mandate['ExecutionType']).to eq('WEB')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'CREATE' do
|
11
|
+
it 'creates a mandate' do
|
12
|
+
mandate = new_mandate
|
13
|
+
expect(mandate['Id']).to_not be_nil
|
14
|
+
check_status(mandate)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'FETCH' do
|
19
|
+
|
20
|
+
it 'fetches a mandate' do
|
21
|
+
created = new_mandate
|
22
|
+
fetched = MangoPay::Mandate.fetch(created['Id'])
|
23
|
+
expect(fetched['Id']).to eq(created['Id'])
|
24
|
+
expect(fetched['CreationDate']).to eq(created['CreationDate'])
|
25
|
+
expect(fetched['UserId']).to eq(created['UserId'])
|
26
|
+
expect(fetched['BankAccountId']).to eq(created['BankAccountId'])
|
27
|
+
check_status(created)
|
28
|
+
check_status(fetched)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'fetches (all) mandates' do
|
32
|
+
created1 = create_new_mandate()
|
33
|
+
created2 = create_new_mandate()
|
34
|
+
fetched = MangoPay::Mandate.fetch({'per_page' => 2, 'sort' => 'CreationDate:desc'})
|
35
|
+
|
36
|
+
expect(fetched).to be_kind_of(Array)
|
37
|
+
expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
|
38
|
+
|
39
|
+
# all 2 are at top as lastly created
|
40
|
+
# but may share the same CreationDate
|
41
|
+
# so the order between them is undetermined
|
42
|
+
expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'FETCH FOR USER AND BANK ACCOUNT' do
|
48
|
+
|
49
|
+
it 'fetches mandates for user' do
|
50
|
+
created1 = create_new_mandate()
|
51
|
+
created2 = create_new_mandate()
|
52
|
+
expect(created1['UserId']).to eq(created2['UserId']) # both for same user
|
53
|
+
|
54
|
+
user_id = created1['UserId']
|
55
|
+
fetched = MangoPay::Mandate.fetch_for_user(user_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
|
56
|
+
|
57
|
+
expect(fetched).to be_kind_of(Array)
|
58
|
+
expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
|
59
|
+
expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
|
60
|
+
expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'fetches mandates for user bank account' do
|
64
|
+
created1 = create_new_mandate()
|
65
|
+
created2 = create_new_mandate()
|
66
|
+
expect(created1['UserId']).to eq(created2['UserId']) # both for same user
|
67
|
+
expect(created1['BankAccountId']).to eq(created2['BankAccountId']) # both for same bank account
|
68
|
+
|
69
|
+
user_id = created1['UserId']
|
70
|
+
bank_acc_id = created1['BankAccountId']
|
71
|
+
fetched = MangoPay::Mandate.fetch_for_user_bank_account(user_id, bank_acc_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
|
72
|
+
|
73
|
+
expect(fetched).to be_kind_of(Array)
|
74
|
+
expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
|
75
|
+
expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
|
76
|
+
expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'CANCEL' do
|
82
|
+
it 'cancels a mandate' do
|
83
|
+
created = new_mandate
|
84
|
+
expect { MangoPay::Mandate.cancel(created['Id']) }.to raise_error { |err|
|
85
|
+
expect(err).to be_a MangoPay::ResponseError
|
86
|
+
expect(err.code).to eq '400'
|
87
|
+
expect(err.type).to eq 'mandate_cannot_be_cancelled'
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe MangoPay::PayIn::DirectDebit::Direct, type: :feature do
|
2
|
+
include_context 'payins'
|
3
|
+
|
4
|
+
def check_type_and_status(payin)
|
5
|
+
expect(payin['Type']).to eq('PAYIN')
|
6
|
+
expect(payin['Nature']).to eq('REGULAR')
|
7
|
+
expect(payin['PaymentType']).to eq('DIRECT_DEBIT')
|
8
|
+
expect(payin['ExecutionType']).to eq('DIRECT')
|
9
|
+
|
10
|
+
# FAILED: the related Mandate is not confirmed yet
|
11
|
+
expect(payin['Status']).to eq('FAILED')
|
12
|
+
expect(payin['ResultMessage']).to eq('The Status of this Mandate does not allow for payments')
|
13
|
+
expect(payin['ExecutionDate']).to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'CREATE' do
|
17
|
+
it 'creates a directdebit direct payin' do
|
18
|
+
created = new_payin_directdebit_direct
|
19
|
+
expect(created['Id']).not_to be_nil
|
20
|
+
check_type_and_status(created)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'FETCH' do
|
25
|
+
it 'fetches a payin' do
|
26
|
+
created = new_payin_directdebit_direct
|
27
|
+
fetched = MangoPay::PayIn.fetch(created['Id'])
|
28
|
+
expect(fetched['Id']).to eq(created['Id'])
|
29
|
+
expect(fetched['CreationDate']).to eq(created['CreationDate'])
|
30
|
+
expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
|
31
|
+
expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
|
32
|
+
check_type_and_status(created)
|
33
|
+
check_type_and_status(fetched)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -146,6 +146,22 @@ shared_context 'bank_accounts' do
|
|
146
146
|
}
|
147
147
|
end
|
148
148
|
|
149
|
+
###############################################
|
150
|
+
shared_context 'mandates' do
|
151
|
+
###############################################
|
152
|
+
include_context 'bank_accounts'
|
153
|
+
|
154
|
+
let(:new_mandate) { create_new_mandate() }
|
155
|
+
def create_new_mandate()
|
156
|
+
MangoPay::Mandate.create({
|
157
|
+
BankAccountId: new_bank_account['Id'],
|
158
|
+
Culture: 'FR',
|
159
|
+
ReturnURL: MangoPay.configuration.root_url,
|
160
|
+
Tag: 'Test mandate'
|
161
|
+
})
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
149
165
|
###############################################
|
150
166
|
shared_context 'kyc_documents' do
|
151
167
|
###############################################
|
@@ -165,6 +181,7 @@ shared_context 'payins' do
|
|
165
181
|
###############################################
|
166
182
|
include_context 'users'
|
167
183
|
include_context 'wallets'
|
184
|
+
include_context 'mandates'
|
168
185
|
|
169
186
|
###############################################
|
170
187
|
# directdebit/web
|
@@ -184,6 +201,23 @@ shared_context 'payins' do
|
|
184
201
|
})
|
185
202
|
}
|
186
203
|
|
204
|
+
###############################################
|
205
|
+
# directdebit/direct
|
206
|
+
###############################################
|
207
|
+
|
208
|
+
let(:new_payin_directdebit_direct) {
|
209
|
+
MangoPay::PayIn::DirectDebit::Direct.create({
|
210
|
+
AuthorId: new_natural_user['Id'],
|
211
|
+
CreditedUserId: new_wallet['Owners'][0],
|
212
|
+
CreditedWalletId: new_wallet['Id'],
|
213
|
+
DebitedFunds: { Currency: 'EUR', Amount: 1000 },
|
214
|
+
Fees: { Currency: 'EUR', Amount: 0 },
|
215
|
+
MandateId: new_mandate['Id'],
|
216
|
+
ReturnURL: MangoPay.configuration.root_url,
|
217
|
+
Tag: 'Test PayIn/DirectDebit/Direct'
|
218
|
+
})
|
219
|
+
}
|
220
|
+
|
187
221
|
###############################################
|
188
222
|
# card/web
|
189
223
|
###############################################
|
data/spec/spec_helper.rb
CHANGED
@@ -10,12 +10,8 @@ def reset_mangopay_configuration
|
|
10
10
|
c.client_id = 'sdk-unit-tests'
|
11
11
|
|
12
12
|
# sandbox environment:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# test environment:
|
17
|
-
c.root_url = 'https://api-test.mangopay.com'
|
18
|
-
c.client_passphrase = '9RMGpwVUwFLK0SurxObJ2yaadDcO0zeKFKxWmthjB93SQjFzy0'
|
13
|
+
c.root_url = 'https://api.sandbox.mangopay.com'
|
14
|
+
c.client_passphrase = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
19
15
|
|
20
16
|
c.temp_dir = File.expand_path('../tmp', __FILE__)
|
21
17
|
require 'fileutils'
|
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.
|
4
|
+
version: 3.0.21
|
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: 2016-
|
12
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -54,9 +54,9 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 3.0.0
|
56
56
|
description: |2
|
57
|
-
The mangopay Gem makes interacting with
|
58
|
-
For any questions regarding the use of
|
59
|
-
You can find more documentation about
|
57
|
+
The mangopay Gem makes interacting with MANGOPAY Services much easier.
|
58
|
+
For any questions regarding the use of MANGOPAY's Services feel free to contact us at http://www.mangopay.com/get-started-2/
|
59
|
+
You can find more documentation about MANGOPAY Services at http://docs.mangopay.com/
|
60
60
|
email: support@mangopay.com
|
61
61
|
executables:
|
62
62
|
- mangopay
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/mangopay/json.rb
|
86
86
|
- lib/mangopay/kyc_document.rb
|
87
87
|
- lib/mangopay/legal_user.rb
|
88
|
+
- lib/mangopay/mandate.rb
|
88
89
|
- lib/mangopay/natural_user.rb
|
89
90
|
- lib/mangopay/pay_in.rb
|
90
91
|
- lib/mangopay/pay_out.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- spec/mangopay/authorization_token_spec.rb
|
102
103
|
- spec/mangopay/bank_account_spec.rb
|
103
104
|
- spec/mangopay/card_registration_spec.rb
|
105
|
+
- spec/mangopay/client_spec.png
|
104
106
|
- spec/mangopay/client_spec.rb
|
105
107
|
- spec/mangopay/configuration_spec.rb
|
106
108
|
- spec/mangopay/dispute_spec.png
|
@@ -108,12 +110,14 @@ files:
|
|
108
110
|
- spec/mangopay/event_spec.rb
|
109
111
|
- spec/mangopay/fetch_filters_spec.rb
|
110
112
|
- spec/mangopay/hook_spec.rb
|
111
|
-
- spec/mangopay/idempotency_spec
|
113
|
+
- spec/mangopay/idempotency_spec.rb
|
112
114
|
- spec/mangopay/kyc_document_spec.png
|
113
115
|
- spec/mangopay/kyc_document_spec.rb
|
116
|
+
- spec/mangopay/mandate_spec.rb
|
114
117
|
- spec/mangopay/payin_bankwire_direct_spec.rb
|
115
118
|
- spec/mangopay/payin_card_direct_spec.rb
|
116
119
|
- spec/mangopay/payin_card_web_spec.rb
|
120
|
+
- spec/mangopay/payin_directdebit_direct_spec.rb
|
117
121
|
- spec/mangopay/payin_directdebit_web_spec.rb
|
118
122
|
- spec/mangopay/payin_preauthorized_direct_spec.rb
|
119
123
|
- spec/mangopay/payout_bankwire_spec.rb
|
@@ -150,11 +154,12 @@ rubyforge_project:
|
|
150
154
|
rubygems_version: 2.4.5.1
|
151
155
|
signing_key:
|
152
156
|
specification_version: 4
|
153
|
-
summary: Ruby bindings for the version 2 of the
|
157
|
+
summary: Ruby bindings for the version 2 of the MANGOPAY API
|
154
158
|
test_files:
|
155
159
|
- spec/mangopay/authorization_token_spec.rb
|
156
160
|
- spec/mangopay/bank_account_spec.rb
|
157
161
|
- spec/mangopay/card_registration_spec.rb
|
162
|
+
- spec/mangopay/client_spec.png
|
158
163
|
- spec/mangopay/client_spec.rb
|
159
164
|
- spec/mangopay/configuration_spec.rb
|
160
165
|
- spec/mangopay/dispute_spec.png
|
@@ -162,12 +167,14 @@ test_files:
|
|
162
167
|
- spec/mangopay/event_spec.rb
|
163
168
|
- spec/mangopay/fetch_filters_spec.rb
|
164
169
|
- spec/mangopay/hook_spec.rb
|
165
|
-
- spec/mangopay/idempotency_spec
|
170
|
+
- spec/mangopay/idempotency_spec.rb
|
166
171
|
- spec/mangopay/kyc_document_spec.png
|
167
172
|
- spec/mangopay/kyc_document_spec.rb
|
173
|
+
- spec/mangopay/mandate_spec.rb
|
168
174
|
- spec/mangopay/payin_bankwire_direct_spec.rb
|
169
175
|
- spec/mangopay/payin_card_direct_spec.rb
|
170
176
|
- spec/mangopay/payin_card_web_spec.rb
|
177
|
+
- spec/mangopay/payin_directdebit_direct_spec.rb
|
171
178
|
- spec/mangopay/payin_directdebit_web_spec.rb
|
172
179
|
- spec/mangopay/payin_preauthorized_direct_spec.rb
|
173
180
|
- spec/mangopay/payout_bankwire_spec.rb
|