mangopay 3.0.11 → 3.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/README.md +26 -0
- data/lib/mangopay.rb +97 -105
- data/lib/mangopay/bank_account.rb +4 -4
- data/lib/mangopay/card.rb +2 -2
- data/lib/mangopay/card_registration.rb +3 -3
- data/lib/mangopay/client.rb +1 -1
- data/lib/mangopay/errors.rb +35 -1
- data/lib/mangopay/event.rb +16 -16
- data/lib/mangopay/hook.rb +3 -3
- data/lib/mangopay/http_calls.rb +1 -1
- data/lib/mangopay/json.rb +6 -15
- data/lib/mangopay/kyc_document.rb +3 -3
- data/lib/mangopay/legal_user.rb +2 -2
- data/lib/mangopay/natural_user.rb +2 -2
- data/lib/mangopay/pay_in.rb +47 -0
- data/lib/mangopay/pay_out.rb +13 -0
- data/lib/mangopay/pre_authorization.rb +11 -0
- data/lib/mangopay/refund.rb +1 -1
- data/lib/mangopay/resource.rb +3 -3
- data/lib/mangopay/transaction.rb +1 -1
- data/lib/mangopay/transfer.rb +3 -3
- data/lib/mangopay/user.rb +3 -3
- data/lib/mangopay/version.rb +1 -1
- data/lib/mangopay/wallet.rb +5 -5
- data/mangopay.gemspec +3 -6
- data/spec/{lib/mangopay → mangopay}/authorization_token_spec.rb +70 -72
- data/spec/{lib/mangopay → mangopay}/bank_account_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/card_registration_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/client_spec.rb +2 -4
- data/spec/{lib/mangopay → mangopay}/configuration_spec.rb +18 -20
- data/spec/{lib/mangopay → mangopay}/event_spec.rb +31 -33
- data/spec/{lib/mangopay → mangopay}/fetch_filters_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/hook_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/kyc_document_spec.rb +58 -60
- data/spec/{lib/mangopay → mangopay}/payin_bankwire_direct_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/payin_card_direct_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/payin_card_web_spec.rb +54 -56
- data/spec/{lib/mangopay → mangopay}/payin_preauthorized_direct_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/payout_bankwire_spec.rb +54 -56
- data/spec/{lib/mangopay → mangopay}/preauthorization_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/refund_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/shared_resources.rb +0 -4
- data/spec/{lib/mangopay → mangopay}/transaction_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/transfer_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/user_spec.rb +0 -2
- data/spec/{lib/mangopay → mangopay}/wallet_spec.rb +87 -89
- data/spec/spec_helper.rb +28 -20
- metadata +53 -95
- data/lib/mangopay/payin.rb +0 -47
- data/lib/mangopay/payout.rb +0 -13
- data/lib/mangopay/preauthorization.rb +0 -11
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
1
|
describe MangoPay::Client do
|
4
2
|
include_context 'clients'
|
5
3
|
|
@@ -12,8 +10,8 @@ describe MangoPay::Client do
|
|
12
10
|
|
13
11
|
it 'refuses the client id' do
|
14
12
|
expect { wrong_client['errors'] }.to raise_error { |err|
|
15
|
-
err.
|
16
|
-
err.type.
|
13
|
+
expect(err).to be_a MangoPay::ResponseError
|
14
|
+
expect(err.type).to eq 'param_error'
|
17
15
|
}
|
18
16
|
end
|
19
17
|
|
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
c =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
1
|
+
describe MangoPay::Configuration do
|
2
|
+
|
3
|
+
it 'fails when calling with wrong client credentials' do
|
4
|
+
expect {
|
5
|
+
c = MangoPay.configuration
|
6
|
+
c.client_id = 'test_asd'
|
7
|
+
c.client_passphrase = '00000'
|
8
|
+
MangoPay::User.fetch()
|
9
|
+
}.to raise_error(MangoPay::ResponseError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'goes ok when calling with correct client credentials' do
|
13
|
+
reset_mangopay_configuration
|
14
|
+
users = MangoPay::User.fetch()
|
15
|
+
expect(users).to be_kind_of(Array)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,33 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
events
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
events
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
events
|
28
|
-
expect(events).to
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
1
|
+
describe MangoPay::Event do
|
2
|
+
|
3
|
+
include_context 'payins'
|
4
|
+
include_context 'payouts'
|
5
|
+
|
6
|
+
describe 'FETCH' do
|
7
|
+
|
8
|
+
it 'accepts filtering params' do
|
9
|
+
|
10
|
+
# let's have at least 2 events
|
11
|
+
payin = new_payin_card_direct
|
12
|
+
create_new_payout_bankwire(payin)
|
13
|
+
|
14
|
+
# get all
|
15
|
+
events = MangoPay::Event.fetch()
|
16
|
+
expect(events).to be_kind_of(Array)
|
17
|
+
expect(events.count).to be >= 2
|
18
|
+
|
19
|
+
# only one per page
|
20
|
+
events = MangoPay::Event.fetch({'per_page' => 1})
|
21
|
+
expect(events).to be_kind_of(Array)
|
22
|
+
expect(events.count).to eq 1
|
23
|
+
|
24
|
+
# filter by date
|
25
|
+
events = MangoPay::Event.fetch({'AfterDate' => payin['CreationDate'], 'BeforeDate' => payin['CreationDate']})
|
26
|
+
expect(events).to be_kind_of(Array)
|
27
|
+
expect(events.count).to be >= 1
|
28
|
+
expect(events.count { |e| e['ResourceId'] == payin['Id'] }).to be >= 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,60 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
expect(new_document['
|
9
|
-
expect(new_document['
|
10
|
-
expect(new_document['
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
err.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
1
|
+
describe MangoPay::KycDocument do
|
2
|
+
include_context 'kyc_documents'
|
3
|
+
|
4
|
+
describe 'CREATE' do
|
5
|
+
it 'creates a document' do
|
6
|
+
expect(new_document['Id']).to_not be_nil
|
7
|
+
expect(new_document['Type']).to eq('IDENTITY_PROOF')
|
8
|
+
expect(new_document['Status']).to eq('CREATED')
|
9
|
+
expect(new_document['RefusedReasonType']).to be_nil
|
10
|
+
expect(new_document['RefusedReasonMessage']).to be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'UPDATE' do
|
15
|
+
it 'updates a document' do
|
16
|
+
updated_document = MangoPay::KycDocument.update(new_natural_user['Id'], new_document['Id'], {
|
17
|
+
Status: 'VALIDATION_ASKED'
|
18
|
+
})
|
19
|
+
expect(updated_document['Id']).to eq(new_document['Id'])
|
20
|
+
expect(updated_document['Status']).to eq('VALIDATION_ASKED')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'FETCH' do
|
25
|
+
it 'fetches a document' do
|
26
|
+
document = MangoPay::KycDocument.fetch(new_natural_user['Id'], new_document['Id'])
|
27
|
+
expect(document['Id']).to eq(new_document['Id'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'CREATE PAGE' do
|
32
|
+
|
33
|
+
def create_page(file)
|
34
|
+
MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'accepts File instance' do
|
38
|
+
file = File.open(__FILE__)
|
39
|
+
ret = create_page(file)
|
40
|
+
expect(ret).to be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'accepts base64-encoded string' do
|
44
|
+
file = Base64.encode64('any file content...')
|
45
|
+
ret = create_page(file)
|
46
|
+
expect(ret).to be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'fails when input string is not base64-encoded' do
|
50
|
+
file = 'any file content...'
|
51
|
+
expect { create_page(file) }.to raise_error { |err|
|
52
|
+
expect(err).to be_a MangoPay::ResponseError
|
53
|
+
expect(err.code).to eq '400'
|
54
|
+
expect(err.type).to eq 'param_error'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,56 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
expect(payin['
|
8
|
-
expect(payin['
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
expect(payin['
|
14
|
-
expect(payin['
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
created
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
created
|
30
|
-
fetched
|
31
|
-
expect(fetched['
|
32
|
-
expect(fetched['
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
refund
|
44
|
-
expect(refund['
|
45
|
-
expect(refund['
|
46
|
-
expect(refund['
|
47
|
-
expect(refund['
|
48
|
-
expect(refund['
|
49
|
-
expect(refund['
|
50
|
-
expect(refund['
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
1
|
+
describe MangoPay::PayIn::Card::Web, 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('CARD')
|
8
|
+
expect(payin['ExecutionType']).to eq('WEB')
|
9
|
+
|
10
|
+
# not SUCCEEDED yet: waiting for processing
|
11
|
+
expect(payin['Status']).to eq('CREATED')
|
12
|
+
expect(payin['ResultCode']).to be_nil
|
13
|
+
expect(payin['ResultMessage']).to be_nil
|
14
|
+
expect(payin['ExecutionDate']).to be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'CREATE' do
|
18
|
+
it 'creates a card web payin' do
|
19
|
+
created = new_payin_card_web
|
20
|
+
expect(created['Id']).not_to be_nil
|
21
|
+
check_type_and_status(created)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'FETCH' do
|
26
|
+
it 'fetches a payin' do
|
27
|
+
created = new_payin_card_web
|
28
|
+
fetched = MangoPay::PayIn.fetch(created['Id'])
|
29
|
+
expect(fetched['Id']).to eq(created['Id'])
|
30
|
+
expect(fetched['CreationDate']).to eq(created['CreationDate'])
|
31
|
+
expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
|
32
|
+
expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
|
33
|
+
check_type_and_status(created)
|
34
|
+
check_type_and_status(fetched)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'REFUND' do
|
39
|
+
it 'refunds a payin' do
|
40
|
+
payin = new_payin_card_web
|
41
|
+
refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
|
42
|
+
expect(refund['Id']).not_to be_nil
|
43
|
+
expect(refund['Type']).to eq('PAYOUT')
|
44
|
+
expect(refund['Nature']).to eq('REFUND')
|
45
|
+
expect(refund['InitialTransactionType']).to eq('PAYIN')
|
46
|
+
expect(refund['InitialTransactionId']).to eq(payin['Id'])
|
47
|
+
expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
|
48
|
+
expect(refund['Status']).to eq('FAILED')
|
49
|
+
expect(refund['ResultCode']).to eq('001001')
|
50
|
+
expect(refund['ResultMessage']).to eq('Unsufficient wallet balance')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -1,56 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
include_context '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
expect(payout['
|
10
|
-
expect(payout['
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
expect(payout['
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
payout
|
30
|
-
expect(payout['
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
payout
|
38
|
-
|
39
|
-
expect(payout['
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
created
|
48
|
-
fetched
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
1
|
+
describe MangoPay::PayOut::BankWire, type: :feature do
|
2
|
+
include_context 'bank_accounts'
|
3
|
+
include_context 'payins'
|
4
|
+
include_context 'payouts'
|
5
|
+
|
6
|
+
def check_type_and_status(payout, check_status = true)
|
7
|
+
expect(payout['Type']).to eq('PAYOUT')
|
8
|
+
expect(payout['Nature']).to eq('REGULAR')
|
9
|
+
expect(payout['PaymentType']).to eq('BANK_WIRE')
|
10
|
+
expect(payout['ExecutionDate']).to be_nil
|
11
|
+
|
12
|
+
# linked to correct bank account
|
13
|
+
expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
|
14
|
+
|
15
|
+
if (check_status)
|
16
|
+
# not SUCCEEDED yet: waiting for processing
|
17
|
+
expect(payout['Status']).to eq('CREATED')
|
18
|
+
expect(payout['ResultCode']).to be_nil
|
19
|
+
expect(payout['ResultMessage']).to be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'CREATE' do
|
24
|
+
|
25
|
+
it 'creates a bank wire payout' do
|
26
|
+
payin = new_payin_card_direct # this payin is successfull so payout may happen
|
27
|
+
payout = create_new_payout_bankwire(payin)
|
28
|
+
expect(payout['Id']).not_to be_nil
|
29
|
+
check_type_and_status(payout)
|
30
|
+
expect(payout['DebitedWalletId']).to eq(payin['CreditedWalletId'])
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'fails if not enough money' do
|
34
|
+
payin = new_payin_card_web # this payin is NOT processed yet so payout may NOT happen
|
35
|
+
payout = create_new_payout_bankwire(payin)
|
36
|
+
check_type_and_status(payout, false)
|
37
|
+
expect(payout['Status']).to eq('FAILED')
|
38
|
+
expect(payout['ResultCode']).to eq('001001')
|
39
|
+
expect(payout['ResultMessage']).to eq('Unsufficient wallet balance')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'FETCH' do
|
44
|
+
it 'fetches a payout' do
|
45
|
+
created = new_payout_bankwire
|
46
|
+
fetched = MangoPay::PayOut.fetch(created['Id'])
|
47
|
+
expect(fetched['Id']).to eq(created['Id'])
|
48
|
+
expect(fetched['CreationDate']).to eq(created['CreationDate'])
|
49
|
+
check_type_and_status(created)
|
50
|
+
check_type_and_status(fetched)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|