mangopay 3.0.25 → 3.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +30 -28
  3. data/.rspec +2 -2
  4. data/.travis.yml +13 -4
  5. data/Gemfile +2 -2
  6. data/LICENSE +20 -20
  7. data/README.md +126 -126
  8. data/bin/mangopay +9 -9
  9. data/lib/generators/mangopay/install_generator.rb +60 -60
  10. data/lib/generators/templates/mangopay.rb.erb +5 -5
  11. data/lib/mangopay.rb +228 -225
  12. data/lib/mangopay/authorization_token.rb +88 -88
  13. data/lib/mangopay/bank_account.rb +38 -38
  14. data/lib/mangopay/bankingaliases.rb +29 -0
  15. data/lib/mangopay/bankingaliases_iban.rb +16 -0
  16. data/lib/mangopay/card.rb +8 -8
  17. data/lib/mangopay/card_registration.rb +9 -9
  18. data/lib/mangopay/client.rb +74 -74
  19. data/lib/mangopay/dispute.rb +130 -130
  20. data/lib/mangopay/errors.rb +61 -61
  21. data/lib/mangopay/event.rb +18 -18
  22. data/lib/mangopay/filter_parameters.rb +46 -46
  23. data/lib/mangopay/hook.rb +9 -9
  24. data/lib/mangopay/http_calls.rb +85 -85
  25. data/lib/mangopay/json.rb +14 -14
  26. data/lib/mangopay/kyc_document.rb +70 -70
  27. data/lib/mangopay/legal_user.rb +15 -15
  28. data/lib/mangopay/mandate.rb +32 -32
  29. data/lib/mangopay/natural_user.rb +14 -14
  30. data/lib/mangopay/pay_in.rb +96 -85
  31. data/lib/mangopay/pay_out.rb +14 -14
  32. data/lib/mangopay/pre_authorization.rb +13 -13
  33. data/lib/mangopay/refund.rb +7 -7
  34. data/lib/mangopay/report.rb +17 -17
  35. data/lib/mangopay/resource.rb +21 -21
  36. data/lib/mangopay/transaction.rb +24 -24
  37. data/lib/mangopay/transfer.rb +9 -9
  38. data/lib/mangopay/user.rb +43 -43
  39. data/lib/mangopay/version.rb +3 -3
  40. data/lib/mangopay/wallet.rb +17 -17
  41. data/mangopay.gemspec +30 -30
  42. data/spec/mangopay/authorization_token_spec.rb +70 -70
  43. data/spec/mangopay/bank_account_spec.rb +97 -97
  44. data/spec/mangopay/bankingaliases_spec.rb +29 -0
  45. data/spec/mangopay/card_registration_spec.rb +73 -73
  46. data/spec/mangopay/client_spec.rb +110 -110
  47. data/spec/mangopay/configuration_spec.rb +95 -95
  48. data/spec/mangopay/dispute_spec.rb +262 -262
  49. data/spec/mangopay/event_spec.rb +31 -31
  50. data/spec/mangopay/fetch_filters_spec.rb +63 -63
  51. data/spec/mangopay/hook_spec.rb +37 -37
  52. data/spec/mangopay/idempotency_spec.rb +41 -41
  53. data/spec/mangopay/kyc_document_spec.rb +103 -103
  54. data/spec/mangopay/log_requests_filter_spec.rb +25 -25
  55. data/spec/mangopay/mandate_spec.rb +92 -92
  56. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
  57. data/spec/mangopay/payin_card_direct_spec.rb +68 -68
  58. data/spec/mangopay/payin_card_web_spec.rb +47 -38
  59. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
  60. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
  61. data/spec/mangopay/payin_paypal_web_spec.rb +38 -38
  62. data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
  63. data/spec/mangopay/payout_bankwire_spec.rb +54 -54
  64. data/spec/mangopay/preauthorization_spec.rb +42 -42
  65. data/spec/mangopay/refund_spec.rb +21 -21
  66. data/spec/mangopay/report_spec.rb +39 -39
  67. data/spec/mangopay/shared_resources.rb +397 -381
  68. data/spec/mangopay/transaction_spec.rb +54 -54
  69. data/spec/mangopay/transfer_spec.rb +69 -69
  70. data/spec/mangopay/user_spec.rb +137 -137
  71. data/spec/mangopay/wallet_spec.rb +80 -80
  72. data/spec/spec_helper.rb +31 -31
  73. metadata +7 -6
  74. data/lib/mangopay/temp.rb +0 -74
  75. data/spec/mangopay/temp_paymentcard_spec.rb +0 -31
@@ -1,31 +1,31 @@
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
+ 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,63 +1,63 @@
1
- describe 'FETCH WITH FILTERS' do
2
- include_context 'users'
3
- include_context 'bank_accounts'
4
-
5
- describe 'FETCH USERS' do
6
-
7
- it 'returns single hash when called with id' do
8
- id = new_natural_user['Id']
9
- res = MangoPay::User.fetch(id)
10
- expect(res).to be_kind_of Hash
11
- expect(res['Id']).to eq id
12
- end
13
-
14
- it 'returns list of hashes with default pagination when called with no param' do
15
- res = MangoPay::User.fetch()
16
- expect(res).to be_kind_of Array
17
- expect(res.count).to eq 10
18
- end
19
-
20
- it 'returns list of hashes with default pagination when called with empty filters' do
21
- res = MangoPay::User.fetch(filters = {})
22
- expect(res).to be_kind_of Array
23
- expect(res.count).to eq 10
24
- expect(filters['total_items']).to be > 0
25
- expect(filters['total_pages']).to be > 0
26
- end
27
-
28
- it 'returns list of hashes with correct pagination when called with pagination filters' do
29
- res = MangoPay::User.fetch(filters = {page:2, per_page:3})
30
- expect(res).to be_kind_of Array
31
- expect(res.count).to eq 3 # 3 items per page as requested
32
- expect(filters['total_items']).to be > 0
33
- expect(filters['total_pages']).to be > 0
34
- end
35
- end
36
-
37
- describe 'FETCH BANK ACCOUNTS OF USER' do
38
-
39
- it 'returns single hash when called with user id and account id' do
40
- bank_account = new_bank_account
41
- res = MangoPay::BankAccount.fetch(bank_account['UserId'], bank_account['Id'])
42
- expect(res).to be_kind_of Hash
43
- expect(res['Id']).to eq bank_account['Id']
44
- end
45
-
46
- it 'returns list of hashes with default pagination when called with user id only' do
47
- bank_account = new_bank_account
48
- res = MangoPay::BankAccount.fetch(bank_account['UserId'])
49
- expect(res).to be_kind_of Array
50
- expect(res.count).to eq 1 # not enough items to fill-in whole page
51
- end
52
-
53
- it 'returns list of hashes with default pagination when called with empty filters' do
54
- bank_account = new_bank_account
55
- res = MangoPay::BankAccount.fetch(bank_account['UserId'], filters = {})
56
- expect(res).to be_kind_of Array
57
- expect(res.count).to eq 1 # not enough items to fill-in whole page
58
- expect(filters['total_items']).to eq 1
59
- expect(filters['total_pages']).to eq 1
60
- end
61
- end
62
-
63
- end
1
+ describe 'FETCH WITH FILTERS' do
2
+ include_context 'users'
3
+ include_context 'bank_accounts'
4
+
5
+ describe 'FETCH USERS' do
6
+
7
+ it 'returns single hash when called with id' do
8
+ id = new_natural_user['Id']
9
+ res = MangoPay::User.fetch(id)
10
+ expect(res).to be_kind_of Hash
11
+ expect(res['Id']).to eq id
12
+ end
13
+
14
+ it 'returns list of hashes with default pagination when called with no param' do
15
+ res = MangoPay::User.fetch()
16
+ expect(res).to be_kind_of Array
17
+ expect(res.count).to eq 10
18
+ end
19
+
20
+ it 'returns list of hashes with default pagination when called with empty filters' do
21
+ res = MangoPay::User.fetch(filters = {})
22
+ expect(res).to be_kind_of Array
23
+ expect(res.count).to eq 10
24
+ expect(filters['total_items']).to be > 0
25
+ expect(filters['total_pages']).to be > 0
26
+ end
27
+
28
+ it 'returns list of hashes with correct pagination when called with pagination filters' do
29
+ res = MangoPay::User.fetch(filters = {page:2, per_page:3})
30
+ expect(res).to be_kind_of Array
31
+ expect(res.count).to eq 3 # 3 items per page as requested
32
+ expect(filters['total_items']).to be > 0
33
+ expect(filters['total_pages']).to be > 0
34
+ end
35
+ end
36
+
37
+ describe 'FETCH BANK ACCOUNTS OF USER' do
38
+
39
+ it 'returns single hash when called with user id and account id' do
40
+ bank_account = new_bank_account
41
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'], bank_account['Id'])
42
+ expect(res).to be_kind_of Hash
43
+ expect(res['Id']).to eq bank_account['Id']
44
+ end
45
+
46
+ it 'returns list of hashes with default pagination when called with user id only' do
47
+ bank_account = new_bank_account
48
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'])
49
+ expect(res).to be_kind_of Array
50
+ expect(res.count).to eq 1 # not enough items to fill-in whole page
51
+ end
52
+
53
+ it 'returns list of hashes with default pagination when called with empty filters' do
54
+ bank_account = new_bank_account
55
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'], filters = {})
56
+ expect(res).to be_kind_of Array
57
+ expect(res.count).to eq 1 # not enough items to fill-in whole page
58
+ expect(filters['total_items']).to eq 1
59
+ expect(filters['total_pages']).to eq 1
60
+ end
61
+ end
62
+
63
+ end
@@ -1,37 +1,37 @@
1
- describe MangoPay::Hook do
2
- include_context 'hooks'
3
-
4
- describe 'CREATE' do
5
- it 'creates a hook' do
6
- expect(new_hook['Id']).to_not be_nil
7
- end
8
- end
9
-
10
- describe 'UPDATE' do
11
- it 'updates a hook' do
12
- new_url = new_hook['Url'] + '.com'
13
- updated_hook = MangoPay::Hook.update(new_hook['Id'], {
14
- Url: new_url,
15
- Tag: 'Updated Tag'
16
- })
17
- expect(updated_hook['Url']).to eq(new_url)
18
- expect(updated_hook['Tag']).to eq('Updated Tag')
19
- end
20
- end
21
-
22
- describe 'FETCH' do
23
-
24
- it 'fetches a hook' do
25
- hook = MangoPay::Hook.fetch(new_hook['Id'])
26
- expect(hook['Id']).to eq(new_hook['Id'])
27
- end
28
-
29
- it 'fetches all the hooks' do
30
- hooks = MangoPay::Hook.fetch()
31
- expect(hooks).to be_kind_of(Array)
32
- expect(hooks).not_to be_empty
33
- end
34
-
35
- end
36
-
37
- end
1
+ describe MangoPay::Hook do
2
+ include_context 'hooks'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a hook' do
6
+ expect(new_hook['Id']).to_not be_nil
7
+ end
8
+ end
9
+
10
+ describe 'UPDATE' do
11
+ it 'updates a hook' do
12
+ new_url = new_hook['Url'] + '.com'
13
+ updated_hook = MangoPay::Hook.update(new_hook['Id'], {
14
+ Url: new_url,
15
+ Tag: 'Updated Tag'
16
+ })
17
+ expect(updated_hook['Url']).to eq(new_url)
18
+ expect(updated_hook['Tag']).to eq('Updated Tag')
19
+ end
20
+ end
21
+
22
+ describe 'FETCH' do
23
+
24
+ it 'fetches a hook' do
25
+ hook = MangoPay::Hook.fetch(new_hook['Id'])
26
+ expect(hook['Id']).to eq(new_hook['Id'])
27
+ end
28
+
29
+ it 'fetches all the hooks' do
30
+ hooks = MangoPay::Hook.fetch()
31
+ expect(hooks).to be_kind_of(Array)
32
+ expect(hooks).not_to be_empty
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -1,41 +1,41 @@
1
- describe MangoPay do
2
-
3
- # see https://docs.mangopay.com/api-references/idempotency-support/
4
-
5
- include_context 'users'
6
- require 'securerandom'
7
-
8
- describe 'post requests' do
9
-
10
- it 'if called with no idempotency key, act independently' do
11
- u = define_new_natural_user
12
- u1 = MangoPay::NaturalUser.create(u)
13
- u2 = MangoPay::NaturalUser.create(u)
14
- expect(u2['Id']).to be > u1['Id']
15
- end
16
-
17
- it 'if called with same idempotency key, the 2nd call is blocked' do
18
- idempotency_key = SecureRandom.uuid
19
- u = define_new_natural_user
20
- u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
21
- expect {
22
- u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
23
- }.to raise_error(MangoPay::ResponseError)
24
- end
25
-
26
- it 'if called with different idempotency key, act independently and responses may be retreived later' do
27
- idempotency_key1 = SecureRandom.uuid
28
- idempotency_key2 = SecureRandom.uuid
29
- u = define_new_natural_user
30
- u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key1)
31
- u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key2)
32
- expect(u2['Id']).to be > u1['Id']
33
-
34
- resp1 = MangoPay.fetch_response(idempotency_key1)
35
- resp2 = MangoPay.fetch_response(idempotency_key2)
36
- expect(resp1['Resource']['Id']).to eq u1['Id']
37
- expect(resp2['Resource']['Id']).to eq u2['Id']
38
- end
39
-
40
- end
41
- end
1
+ describe MangoPay do
2
+
3
+ # see https://docs.mangopay.com/api-references/idempotency-support/
4
+
5
+ include_context 'users'
6
+ require 'securerandom'
7
+
8
+ describe 'post requests' do
9
+
10
+ it 'if called with no idempotency key, act independently' do
11
+ u = define_new_natural_user
12
+ u1 = MangoPay::NaturalUser.create(u)
13
+ u2 = MangoPay::NaturalUser.create(u)
14
+ expect(u2['Id']).to be > u1['Id']
15
+ end
16
+
17
+ it 'if called with same idempotency key, the 2nd call is blocked' do
18
+ idempotency_key = SecureRandom.uuid
19
+ u = define_new_natural_user
20
+ u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
21
+ expect {
22
+ u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
23
+ }.to raise_error(MangoPay::ResponseError)
24
+ end
25
+
26
+ it 'if called with different idempotency key, act independently and responses may be retreived later' do
27
+ idempotency_key1 = SecureRandom.uuid
28
+ idempotency_key2 = SecureRandom.uuid
29
+ u = define_new_natural_user
30
+ u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key1)
31
+ u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key2)
32
+ expect(u2['Id']).to be > u1['Id']
33
+
34
+ resp1 = MangoPay.fetch_response(idempotency_key1)
35
+ resp2 = MangoPay.fetch_response(idempotency_key2)
36
+ expect(resp1['Resource']['Id']).to eq u1['Id']
37
+ expect(resp2['Resource']['Id']).to eq u2['Id']
38
+ end
39
+
40
+ end
41
+ end
@@ -1,103 +1,103 @@
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
-
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
34
- end
35
-
36
- describe 'FETCH ALL' do
37
- it 'fetches a list of documents' do
38
- usr1 = create_new_natural_user()
39
- usr2 = create_new_natural_user()
40
- doc1 = create_new_document(usr1)
41
- doc2 = create_new_document(usr1)
42
- doc3 = create_new_document(usr2)
43
-
44
- # fetch all docs for user 1
45
- docs = MangoPay::KycDocument.fetch_all(usr1['Id'])
46
- expect(docs).to be_kind_of(Array)
47
- expect(docs.count).to eq 2
48
- expect(docs[0]['Id']).to eq doc1['Id']
49
- expect(docs[1]['Id']).to eq doc2['Id']
50
-
51
- # fetch all docs for user 2
52
- docs = MangoPay::KycDocument.fetch_all(usr2['Id'])
53
- expect(docs).to be_kind_of(Array)
54
- expect(docs.count).to eq 1
55
- expect(docs[0]['Id']).to eq doc3['Id']
56
-
57
- # fetch all docs ever
58
- docs = MangoPay::KycDocument.fetch_all()
59
- expect(docs).to be_kind_of(Array)
60
- expect(docs.count).to be >= 3 # at least last 3 docs, but probably many more
61
-
62
- # fetch last 3 docs (sorting by date descending)
63
- docs = MangoPay::KycDocument.fetch_all(nil, filter = {'page' => 1, 'per_page' => 3, 'sort' => 'CreationDate:desc'})
64
- expect(docs).to be_kind_of(Array)
65
- expect(docs.count).to eq 3
66
- # all 3 are at top as lastly created
67
- # but may share the same CreationDate
68
- # so the order between them is undetermined
69
- expect(docs).to include(doc1, doc2, doc3)
70
-
71
- end
72
- end
73
-
74
- describe 'CREATE PAGE' do
75
-
76
- def create_page(file)
77
- MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
78
- end
79
-
80
- it 'accepts Base64 encoded file content' do
81
- fnm = __FILE__.sub('.rb', '.png')
82
- bts = File.open(fnm, 'rb') { |f| f.read }
83
- b64 = Base64.encode64(bts)
84
- ret = create_page(b64)
85
- expect(ret).to be_nil
86
- end
87
-
88
- it 'accepts file path' do
89
- fnm = __FILE__.sub('.rb', '.png')
90
- ret = MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], nil, fnm)
91
- expect(ret).to be_nil
92
- end
93
-
94
- it 'fails when input string is not base64-encoded' do
95
- file = 'any file content...'
96
- expect { create_page(file) }.to raise_error { |err|
97
- expect(err).to be_a MangoPay::ResponseError
98
- expect(err.code).to eq '400'
99
- expect(err.type).to eq 'param_error'
100
- }
101
- end
102
- end
103
- 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
+
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
34
+ end
35
+
36
+ describe 'FETCH ALL' do
37
+ it 'fetches a list of documents' do
38
+ usr1 = create_new_natural_user()
39
+ usr2 = create_new_natural_user()
40
+ doc1 = create_new_document(usr1)
41
+ doc2 = create_new_document(usr1)
42
+ doc3 = create_new_document(usr2)
43
+
44
+ # fetch all docs for user 1
45
+ docs = MangoPay::KycDocument.fetch_all(usr1['Id'])
46
+ expect(docs).to be_kind_of(Array)
47
+ expect(docs.count).to eq 2
48
+ expect(docs[0]['Id']).to eq doc1['Id']
49
+ expect(docs[1]['Id']).to eq doc2['Id']
50
+
51
+ # fetch all docs for user 2
52
+ docs = MangoPay::KycDocument.fetch_all(usr2['Id'])
53
+ expect(docs).to be_kind_of(Array)
54
+ expect(docs.count).to eq 1
55
+ expect(docs[0]['Id']).to eq doc3['Id']
56
+
57
+ # fetch all docs ever
58
+ docs = MangoPay::KycDocument.fetch_all()
59
+ expect(docs).to be_kind_of(Array)
60
+ expect(docs.count).to be >= 3 # at least last 3 docs, but probably many more
61
+
62
+ # fetch last 3 docs (sorting by date descending)
63
+ docs = MangoPay::KycDocument.fetch_all(nil, filter = {'page' => 1, 'per_page' => 3, 'sort' => 'CreationDate:desc'})
64
+ expect(docs).to be_kind_of(Array)
65
+ expect(docs.count).to eq 3
66
+ # all 3 are at top as lastly created
67
+ # but may share the same CreationDate
68
+ # so the order between them is undetermined
69
+ expect(docs).to include(doc1, doc2, doc3)
70
+
71
+ end
72
+ end
73
+
74
+ describe 'CREATE PAGE' do
75
+
76
+ def create_page(file)
77
+ MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
78
+ end
79
+
80
+ it 'accepts Base64 encoded file content' do
81
+ fnm = __FILE__.sub('.rb', '.png')
82
+ bts = File.open(fnm, 'rb') { |f| f.read }
83
+ b64 = Base64.encode64(bts)
84
+ ret = create_page(b64)
85
+ expect(ret).to be_nil
86
+ end
87
+
88
+ it 'accepts file path' do
89
+ fnm = __FILE__.sub('.rb', '.png')
90
+ ret = MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], nil, fnm)
91
+ expect(ret).to be_nil
92
+ end
93
+
94
+ it 'fails when input string is not base64-encoded' do
95
+ file = 'any file content...'
96
+ expect { create_page(file) }.to raise_error { |err|
97
+ expect(err).to be_a MangoPay::ResponseError
98
+ expect(err.code).to eq '400'
99
+ expect(err.type).to eq 'param_error'
100
+ }
101
+ end
102
+ end
103
+ end