mangopay-v4 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.rspec +4 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +13 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +380 -0
- data/bin/mangopay +9 -0
- data/lib/mangopay.rb +133 -0
- data/lib/mangopay/api/api.rb +9 -0
- data/lib/mangopay/api/api_methods.rb +137 -0
- data/lib/mangopay/api/auth_token_manager.rb +173 -0
- data/lib/mangopay/api/http_client.rb +325 -0
- data/lib/mangopay/api/service/bank_accounts.rb +146 -0
- data/lib/mangopay/api/service/cards.rb +152 -0
- data/lib/mangopay/api/service/client_wallets.rb +89 -0
- data/lib/mangopay/api/service/clients.rb +68 -0
- data/lib/mangopay/api/service/dispute_documents.rb +158 -0
- data/lib/mangopay/api/service/disputes.rb +187 -0
- data/lib/mangopay/api/service/e_money.rb +42 -0
- data/lib/mangopay/api/service/events.rb +47 -0
- data/lib/mangopay/api/service/hooks.rb +93 -0
- data/lib/mangopay/api/service/kyc_documents.rb +153 -0
- data/lib/mangopay/api/service/mandates.rb +142 -0
- data/lib/mangopay/api/service/oauth_tokens.rb +25 -0
- data/lib/mangopay/api/service/pay_ins.rb +260 -0
- data/lib/mangopay/api/service/pay_outs.rb +54 -0
- data/lib/mangopay/api/service/pre_authorizations.rb +69 -0
- data/lib/mangopay/api/service/refunds.rb +62 -0
- data/lib/mangopay/api/service/reports.rb +151 -0
- data/lib/mangopay/api/service/repudiations.rb +32 -0
- data/lib/mangopay/api/service/responses.rb +102 -0
- data/lib/mangopay/api/service/settlement_transfers.rb +55 -0
- data/lib/mangopay/api/service/transactions.rb +183 -0
- data/lib/mangopay/api/service/transfers.rb +54 -0
- data/lib/mangopay/api/service/ubo_declarations.rb +70 -0
- data/lib/mangopay/api/service/users.rb +163 -0
- data/lib/mangopay/api/service/wallets.rb +99 -0
- data/lib/mangopay/api/uri_provider.rb +35 -0
- data/lib/mangopay/common/json_tag_converter.rb +68 -0
- data/lib/mangopay/common/jsonifier.rb +249 -0
- data/lib/mangopay/common/log_provider.rb +34 -0
- data/lib/mangopay/common/rate_limit_interval.rb +17 -0
- data/lib/mangopay/common/read_only_fields.rb +27 -0
- data/lib/mangopay/common/response_error.rb +61 -0
- data/lib/mangopay/common/sort_direction.rb +15 -0
- data/lib/mangopay/common/sort_field.rb +13 -0
- data/lib/mangopay/common/template_url_options.rb +9 -0
- data/lib/mangopay/configuration.rb +39 -0
- data/lib/mangopay/environment.rb +66 -0
- data/lib/mangopay/model/address.rb +27 -0
- data/lib/mangopay/model/declared_ubo.rb +21 -0
- data/lib/mangopay/model/dispute_reason.rb +15 -0
- data/lib/mangopay/model/document_page_consult.rb +15 -0
- data/lib/mangopay/model/e_money.rb +18 -0
- data/lib/mangopay/model/entity/account/bank_account.rb +26 -0
- data/lib/mangopay/model/entity/account/ca_bank_account.rb +27 -0
- data/lib/mangopay/model/entity/account/gb_bank_account.rb +21 -0
- data/lib/mangopay/model/entity/account/iban_bank_account.rb +21 -0
- data/lib/mangopay/model/entity/account/other_bank_account.rb +24 -0
- data/lib/mangopay/model/entity/account/us_bank_account.rb +24 -0
- data/lib/mangopay/model/entity/card.rb +45 -0
- data/lib/mangopay/model/entity/card_registration.rb +43 -0
- data/lib/mangopay/model/entity/client.rb +63 -0
- data/lib/mangopay/model/entity/client_wallet.rb +23 -0
- data/lib/mangopay/model/entity/dispute.rb +50 -0
- data/lib/mangopay/model/entity/dispute_document.rb +29 -0
- data/lib/mangopay/model/entity/entity_base.rb +18 -0
- data/lib/mangopay/model/entity/hook.rb +26 -0
- data/lib/mangopay/model/entity/kyc_document.rb +28 -0
- data/lib/mangopay/model/entity/mandate.rb +51 -0
- data/lib/mangopay/model/entity/pay_in/bank_wire_direct_pay_in.rb +22 -0
- data/lib/mangopay/model/entity/pay_in/card_direct_pay_in.rb +33 -0
- data/lib/mangopay/model/entity/pay_in/card_pre_authorized_pay_in.rb +13 -0
- data/lib/mangopay/model/entity/pay_in/card_web_pay_in.rb +40 -0
- data/lib/mangopay/model/entity/pay_in/direct_debit_direct_pay_in.rb +23 -0
- data/lib/mangopay/model/entity/pay_in/direct_debit_web_pay_in.rb +38 -0
- data/lib/mangopay/model/entity/pay_in/pay_in.rb +16 -0
- data/lib/mangopay/model/entity/pay_out.rb +22 -0
- data/lib/mangopay/model/entity/pre_authorization.rb +68 -0
- data/lib/mangopay/model/entity/refund.rb +18 -0
- data/lib/mangopay/model/entity/report.rb +51 -0
- data/lib/mangopay/model/entity/repudiation.rb +18 -0
- data/lib/mangopay/model/entity/settlement_transfer.rb +17 -0
- data/lib/mangopay/model/entity/transaction.rb +52 -0
- data/lib/mangopay/model/entity/transfer.rb +13 -0
- data/lib/mangopay/model/entity/ubo_declaration.rb +32 -0
- data/lib/mangopay/model/entity/user/legal_user.rb +53 -0
- data/lib/mangopay/model/entity/user/natural_user.rb +50 -0
- data/lib/mangopay/model/entity/user/user.rb +18 -0
- data/lib/mangopay/model/entity/wallet.rb +28 -0
- data/lib/mangopay/model/enum/account_type.rb +24 -0
- data/lib/mangopay/model/enum/card_status.rb +15 -0
- data/lib/mangopay/model/enum/card_type.rb +33 -0
- data/lib/mangopay/model/enum/card_validity.rb +19 -0
- data/lib/mangopay/model/enum/country_iso.rb +759 -0
- data/lib/mangopay/model/enum/culture_code.rb +44 -0
- data/lib/mangopay/model/enum/currency_iso.rb +552 -0
- data/lib/mangopay/model/enum/declared_ubo_refused_reason_type.rb +16 -0
- data/lib/mangopay/model/enum/declared_ubo_status.rb +18 -0
- data/lib/mangopay/model/enum/deposit_type.rb +15 -0
- data/lib/mangopay/model/enum/direct_debit_type.rb +13 -0
- data/lib/mangopay/model/enum/dispute_doc_refused_reason_type.rb +25 -0
- data/lib/mangopay/model/enum/dispute_document_type.rb +23 -0
- data/lib/mangopay/model/enum/dispute_reason_type.rb +33 -0
- data/lib/mangopay/model/enum/dispute_status.rb +21 -0
- data/lib/mangopay/model/enum/dispute_type.rb +15 -0
- data/lib/mangopay/model/enum/document_status.rb +21 -0
- data/lib/mangopay/model/enum/download_format.rb +11 -0
- data/lib/mangopay/model/enum/event_type.rb +74 -0
- data/lib/mangopay/model/enum/funds_type.rb +15 -0
- data/lib/mangopay/model/enum/hook_status.rb +13 -0
- data/lib/mangopay/model/enum/hook_validity.rb +15 -0
- data/lib/mangopay/model/enum/income_range.rb +21 -0
- data/lib/mangopay/model/enum/kyc_doc_refused_reason_type.rb +37 -0
- data/lib/mangopay/model/enum/kyc_document_type.rb +19 -0
- data/lib/mangopay/model/enum/kyc_level.rb +13 -0
- data/lib/mangopay/model/enum/legal_person_type.rb +15 -0
- data/lib/mangopay/model/enum/mandate_culture_code.rb +23 -0
- data/lib/mangopay/model/enum/mandate_execution_type.rb +11 -0
- data/lib/mangopay/model/enum/mandate_scheme.rb +13 -0
- data/lib/mangopay/model/enum/mandate_status.rb +24 -0
- data/lib/mangopay/model/enum/mandate_type.rb +11 -0
- data/lib/mangopay/model/enum/natural_user_capacity.rb +15 -0
- data/lib/mangopay/model/enum/pay_in_execution_type.rb +18 -0
- data/lib/mangopay/model/enum/pay_in_payment_type.rb +21 -0
- data/lib/mangopay/model/enum/pay_out_payment_type.rb +11 -0
- data/lib/mangopay/model/enum/payment_status.rb +21 -0
- data/lib/mangopay/model/enum/person_type.rb +15 -0
- data/lib/mangopay/model/enum/platform_type.rb +23 -0
- data/lib/mangopay/model/enum/pre_authorization_execution_type.rb +11 -0
- data/lib/mangopay/model/enum/pre_authorization_status.rb +18 -0
- data/lib/mangopay/model/enum/refund_reason_type.rb +21 -0
- data/lib/mangopay/model/enum/report_status.rb +17 -0
- data/lib/mangopay/model/enum/report_type.rb +13 -0
- data/lib/mangopay/model/enum/secure_mode.rb +16 -0
- data/lib/mangopay/model/enum/transaction_nature.rb +17 -0
- data/lib/mangopay/model/enum/transaction_status.rb +15 -0
- data/lib/mangopay/model/enum/transaction_type.rb +15 -0
- data/lib/mangopay/model/enum/ubo_declaration_refused_reason_type.rb +19 -0
- data/lib/mangopay/model/enum/ubo_declaration_status.rb +21 -0
- data/lib/mangopay/model/event.rb +18 -0
- data/lib/mangopay/model/model.rb +194 -0
- data/lib/mangopay/model/money.rb +17 -0
- data/lib/mangopay/model/pay_in_web_extended_view.rb +31 -0
- data/lib/mangopay/model/refund_reason.rb +15 -0
- data/lib/mangopay/model/report_filter.rb +83 -0
- data/lib/mangopay/model/request/cancel_request.rb +16 -0
- data/lib/mangopay/model/request/complete_registration_request.rb +13 -0
- data/lib/mangopay/model/request/currency_request.rb +13 -0
- data/lib/mangopay/model/request/deactivation_request.rb +10 -0
- data/lib/mangopay/model/request/filter_request.rb +38 -0
- data/lib/mangopay/model/request/submit_document_request.rb +14 -0
- data/lib/mangopay/model/request/submit_ubo_declaration_request.rb +14 -0
- data/lib/mangopay/model/request/upload_file_request.rb +9 -0
- data/lib/mangopay/model/response_replica.rb +27 -0
- data/lib/mangopay/util/custom_formatter.rb +12 -0
- data/lib/mangopay/util/custom_logger.rb +34 -0
- data/lib/mangopay/util/enum.rb +52 -0
- data/lib/mangopay/util/file_encoder.rb +16 -0
- data/lib/mangopay/util/non_instantiable.rb +6 -0
- data/lib/mangopay/util/storage_strategy.rb +10 -0
- data/lib/mangopay/util/void_logger.rb +6 -0
- data/mangopay.gemspec +32 -0
- data/spec/context/address_context.rb +25 -0
- data/spec/context/bank_account_context.rb +138 -0
- data/spec/context/card_context.rb +46 -0
- data/spec/context/client_context.rb +45 -0
- data/spec/context/dispute_context.rb +37 -0
- data/spec/context/dispute_document_context.rb +20 -0
- data/spec/context/hook_context.rb +16 -0
- data/spec/context/kyc_document_context.rb +23 -0
- data/spec/context/mandate_context.rb +27 -0
- data/spec/context/pay_in_context.rb +225 -0
- data/spec/context/pay_out_context.rb +39 -0
- data/spec/context/pre_authorization_context.rb +41 -0
- data/spec/context/refund_context.rb +33 -0
- data/spec/context/report_context.rb +22 -0
- data/spec/context/repudiation_context.rb +19 -0
- data/spec/context/settlement_transfer_context.rb +28 -0
- data/spec/context/transfer_context.rb +51 -0
- data/spec/context/ubo_declaration_context.rb +25 -0
- data/spec/context/user_context.rb +83 -0
- data/spec/context/wallet_context.rb +53 -0
- data/spec/mangopay/bank_accounts_spec.rb +229 -0
- data/spec/mangopay/cards_spec.rb +135 -0
- data/spec/mangopay/client_wallets_spec.rb +148 -0
- data/spec/mangopay/clients_spec.rb +55 -0
- data/spec/mangopay/configuration_spec.rb +126 -0
- data/spec/mangopay/dispute_documents_spec.rb +174 -0
- data/spec/mangopay/disputes_spec.rb +265 -0
- data/spec/mangopay/e_money_spec.rb +38 -0
- data/spec/mangopay/events_spec.rb +50 -0
- data/spec/mangopay/hooks_spec.rb +71 -0
- data/spec/mangopay/kyc_documents_spec.rb +180 -0
- data/spec/mangopay/mandates_spec.rb +219 -0
- data/spec/mangopay/oauth_tokens_spec.rb +41 -0
- data/spec/mangopay/pay_ins_spec.rb +181 -0
- data/spec/mangopay/pay_outs_spec.rb +39 -0
- data/spec/mangopay/pre_authorizations_spec.rb +58 -0
- data/spec/mangopay/refunds_spec.rb +40 -0
- data/spec/mangopay/reports_spec.rb +121 -0
- data/spec/mangopay/responses_spec.rb +295 -0
- data/spec/mangopay/settlement_transfers_spec.rb +37 -0
- data/spec/mangopay/transactions_spec.rb +233 -0
- data/spec/mangopay/transfers_spec.rb +38 -0
- data/spec/mangopay/ubo_declarations_spec.rb +65 -0
- data/spec/mangopay/users_spec.rb +146 -0
- data/spec/mangopay/wallets_spec.rb +104 -0
- data/spec/resources/logo.png +0 -0
- data/spec/resources/test_pdf.pdf +0 -0
- data/spec/spec_helper.rb +72 -0
- metadata +349 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../../lib/mangopay/api/service/events'
|
2
|
+
require_relative '../../lib/mangopay/common/sort_field'
|
3
|
+
require_relative '../../lib/mangopay/common/sort_direction'
|
4
|
+
|
5
|
+
describe MangoApi::Events do
|
6
|
+
|
7
|
+
describe '.all' do
|
8
|
+
|
9
|
+
context 'from a correctly-configured environment' do
|
10
|
+
context 'not having specified filters' do
|
11
|
+
default_per_page = 10
|
12
|
+
|
13
|
+
it 'retrieves list with default parameters' do
|
14
|
+
results = MangoApi::Events.all
|
15
|
+
|
16
|
+
expect(results).to be_kind_of Array
|
17
|
+
expect(results.length).to eq default_per_page
|
18
|
+
results.each do |result|
|
19
|
+
expect(result).to be_kind_of MangoModel::Event
|
20
|
+
expect(result.resource_id).not_to be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'having specified filters' do
|
26
|
+
per_page = 13
|
27
|
+
|
28
|
+
it 'retrieves list with specified parameters' do
|
29
|
+
results = MangoApi::Events.all do |filter|
|
30
|
+
filter.page = 1
|
31
|
+
filter.per_page = per_page
|
32
|
+
filter.sort_field = MangoPay::SortField::DATE
|
33
|
+
filter.sort_direction = MangoPay::SortDirection::DESC
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(results).to be_kind_of Array
|
37
|
+
expect(results.length).to eq per_page
|
38
|
+
results.each.with_index do |result, index|
|
39
|
+
expect(result).to be_kind_of MangoModel::Event
|
40
|
+
expect(result.resource_id).not_to be_nil
|
41
|
+
next if index == results.length - 1
|
42
|
+
first_date = result.date
|
43
|
+
second_date = results[index + 1].date
|
44
|
+
expect(first_date >= second_date).to be_truthy
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative '../context/hook_context'
|
2
|
+
require_relative '../../lib/mangopay/api/service/hooks'
|
3
|
+
require_relative '../../lib/mangopay/model/enum/hook_status'
|
4
|
+
require_relative '../../lib/mangopay/common/sort_field'
|
5
|
+
require_relative '../../lib/mangopay/common/sort_direction'
|
6
|
+
|
7
|
+
describe MangoApi::Hooks do
|
8
|
+
include_context 'hook_context'
|
9
|
+
|
10
|
+
|
11
|
+
describe '.create' do
|
12
|
+
|
13
|
+
context 'given a valid object' do
|
14
|
+
hook = HOOK_DATA
|
15
|
+
|
16
|
+
it 'creates the hook entity' do
|
17
|
+
expect { MangoApi::Hooks.create hook }.to raise_error(MangoPay::ResponseError, /already.+registered/)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.update' do
|
23
|
+
|
24
|
+
context 'given a valid object' do
|
25
|
+
url = 'https://www.hello.com/hook'
|
26
|
+
status = MangoModel::HookStatus::DISABLED
|
27
|
+
created = HOOK_PERSISTED
|
28
|
+
created.url = url
|
29
|
+
created.status = status
|
30
|
+
|
31
|
+
it 'updates the corresponding entity' do
|
32
|
+
updated = MangoApi::Hooks.update created
|
33
|
+
|
34
|
+
expect(updated).to be_kind_of MangoModel::Hook
|
35
|
+
expect(updated.id).to eq created.id
|
36
|
+
expect(updated.url).to eq url
|
37
|
+
expect(updated.status).to be status
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.get' do
|
43
|
+
|
44
|
+
context "given an existing entity's ID" do
|
45
|
+
id = HOOK_PERSISTED.id
|
46
|
+
|
47
|
+
it 'retrieves the corresponding entity' do
|
48
|
+
retrieved = MangoApi::Hooks.get id
|
49
|
+
|
50
|
+
expect(retrieved).to be_kind_of MangoModel::Hook
|
51
|
+
expect(retrieved.id).to eq id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '.all' do
|
57
|
+
|
58
|
+
context 'not having specified filters' do
|
59
|
+
|
60
|
+
it 'retrieves list of all events' do
|
61
|
+
results = MangoApi::Hooks.all
|
62
|
+
|
63
|
+
expect(results).to be_kind_of Array
|
64
|
+
results.each do |result|
|
65
|
+
expect(result).to be_kind_of MangoModel::Hook
|
66
|
+
expect(result.id).not_to be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require_relative '../context/kyc_document_context'
|
2
|
+
require_relative '../../lib/mangopay/api/service/kyc_documents'
|
3
|
+
require_relative '../../lib/mangopay/model/document_page_consult'
|
4
|
+
require_relative '../../lib/mangopay/model/entity/kyc_document'
|
5
|
+
require_relative '../../lib/mangopay/common/sort_field'
|
6
|
+
require_relative '../../lib/mangopay/common/sort_direction'
|
7
|
+
|
8
|
+
describe MangoApi::KycDocuments do
|
9
|
+
include_context 'kyc_document_context'
|
10
|
+
|
11
|
+
describe '.create' do
|
12
|
+
|
13
|
+
context 'given a valid object' do
|
14
|
+
kyc_doc = MangoModel::KycDocument.new
|
15
|
+
kyc_doc.type = MangoModel::KycDocumentType::IDENTITY_PROOF
|
16
|
+
|
17
|
+
it 'creates the kyc document entity' do
|
18
|
+
created = MangoApi::KycDocuments.create kyc_doc, NATURAL_USER_PERSISTED.id
|
19
|
+
|
20
|
+
expect(created).to be_kind_of MangoModel::KycDocument
|
21
|
+
expect(created.id).not_to be_nil
|
22
|
+
expect(created.status).to be MangoModel::DocumentStatus::CREATED
|
23
|
+
expect(its_the_same_kyc_doc(kyc_doc, created)).to be_truthy
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.upload_page' do
|
29
|
+
|
30
|
+
context "given a valid file's path" do
|
31
|
+
path = File.join(File.dirname(__FILE__), '..', 'resources', 'test_pdf.pdf')
|
32
|
+
|
33
|
+
it "uploads the file as one of the KYC document's pages" do
|
34
|
+
response = MangoApi::KycDocuments.upload_page KYC_DOCUMENT_PERSISTED.id,
|
35
|
+
NATURAL_USER_PERSISTED.id,
|
36
|
+
path
|
37
|
+
expect(response).to be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.submit' do
|
43
|
+
|
44
|
+
context "given an existing entity's ID" do
|
45
|
+
created = KYC_DOCUMENT_PERSISTED
|
46
|
+
id = created.id
|
47
|
+
# upload a page to allow submission
|
48
|
+
path = File.join(File.dirname(__FILE__), '..', 'resources', 'test_pdf.pdf')
|
49
|
+
MangoApi::KycDocuments.upload_page KYC_DOCUMENT_PERSISTED.id,
|
50
|
+
NATURAL_USER_PERSISTED.id,
|
51
|
+
path
|
52
|
+
|
53
|
+
it 'submits the corresponding entity for approval' do
|
54
|
+
submitted = MangoApi::KycDocuments.submit id, NATURAL_USER_PERSISTED.id
|
55
|
+
|
56
|
+
expect(submitted).to be_kind_of MangoModel::KycDocument
|
57
|
+
expect(submitted.id).to eq id
|
58
|
+
expect(submitted.status).to be MangoModel::DocumentStatus::VALIDATION_ASKED
|
59
|
+
expect(its_the_same_kyc_doc(created, submitted)).to be_truthy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.of_user' do
|
65
|
+
|
66
|
+
context "given an existing user entity's ID" do
|
67
|
+
id = NATURAL_USER_PERSISTED.id
|
68
|
+
# prepare some test data
|
69
|
+
10.times do
|
70
|
+
persist_kyc_doc KYC_DOCUMENT_DATA
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'not having specified filters' do
|
74
|
+
default_per_page = 10
|
75
|
+
|
76
|
+
it 'retrieves list with default parameters' do
|
77
|
+
results = MangoApi::KycDocuments.of_user id
|
78
|
+
|
79
|
+
expect(results).to be_kind_of Array
|
80
|
+
expect(results.length).to eq default_per_page
|
81
|
+
results.each do |result|
|
82
|
+
expect(result).to be_kind_of MangoModel::KycDocument
|
83
|
+
expect(result.id).not_to be_nil
|
84
|
+
expect(result.user_id).to eq id
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'having specified filters' do
|
90
|
+
per_page = 11
|
91
|
+
|
92
|
+
it 'retrieves list with specified parameters' do
|
93
|
+
results = MangoApi::KycDocuments.of_user id do |filter|
|
94
|
+
filter.page = 1
|
95
|
+
filter.per_page = per_page
|
96
|
+
filter.sort_field = MangoPay::SortField::CREATION_DATE
|
97
|
+
filter.sort_direction = MangoPay::SortDirection::ASC
|
98
|
+
end
|
99
|
+
|
100
|
+
expect(results).to be_kind_of Array
|
101
|
+
expect(results.length).to eq per_page
|
102
|
+
results.each.with_index do |result, index|
|
103
|
+
expect(result).to be_kind_of MangoModel::KycDocument
|
104
|
+
expect(result.id).not_to be_nil
|
105
|
+
expect(result.user_id).to eq id
|
106
|
+
next if index == results.length - 1
|
107
|
+
first_date = result.creation_date
|
108
|
+
second_date = results[index + 1].creation_date
|
109
|
+
expect(first_date <= second_date).to be_truthy
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '.all' do
|
117
|
+
|
118
|
+
context 'from a correctly-configured environment' do
|
119
|
+
# prepare some test data
|
120
|
+
10.times do
|
121
|
+
persist_kyc_doc KYC_DOCUMENT_DATA
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'not having specified filters' do
|
125
|
+
default_per_page = 10
|
126
|
+
|
127
|
+
it 'retrieves list with default parameters' do
|
128
|
+
results = MangoApi::KycDocuments.all
|
129
|
+
|
130
|
+
expect(results).to be_kind_of Array
|
131
|
+
expect(results.length).to eq default_per_page
|
132
|
+
results.each do |result|
|
133
|
+
expect(result).to be_kind_of MangoModel::KycDocument
|
134
|
+
expect(result.id).not_to be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'having specified filters' do
|
140
|
+
per_page = 11
|
141
|
+
|
142
|
+
it 'retrieves list with specified parameters' do
|
143
|
+
results = MangoApi::KycDocuments.all do |filter|
|
144
|
+
filter.page = 1
|
145
|
+
filter.per_page = per_page
|
146
|
+
filter.sort_field = MangoPay::SortField::CREATION_DATE
|
147
|
+
filter.sort_direction = MangoPay::SortDirection::ASC
|
148
|
+
end
|
149
|
+
|
150
|
+
expect(results).to be_kind_of Array
|
151
|
+
expect(results.length).to eq per_page
|
152
|
+
results.each.with_index do |result, index|
|
153
|
+
expect(result).to be_kind_of MangoModel::KycDocument
|
154
|
+
expect(result.id).not_to be_nil
|
155
|
+
next if index == results.length - 1
|
156
|
+
first_date = result.creation_date
|
157
|
+
second_date = results[index + 1].creation_date
|
158
|
+
expect(first_date <= second_date).to be_truthy
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '.consult' do
|
166
|
+
|
167
|
+
context "given an existing entity's ID" do
|
168
|
+
id = KYC_DOCUMENT_PERSISTED.id
|
169
|
+
|
170
|
+
it 'creates the document page consult entities' do
|
171
|
+
results = MangoApi::KycDocuments.consult id
|
172
|
+
|
173
|
+
expect(results).to be_kind_of Array
|
174
|
+
results.each do |result|
|
175
|
+
expect(result).to be_kind_of MangoModel::DocumentPageConsult
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require_relative '../../lib/mangopay/api/service/mandates'
|
2
|
+
require_relative '../../spec/context/mandate_context'
|
3
|
+
require_relative '../../lib/mangopay/common/sort_field'
|
4
|
+
require_relative '../../lib/mangopay/common/sort_direction'
|
5
|
+
|
6
|
+
describe MangoApi::Mandates do
|
7
|
+
include_context 'mandate_context'
|
8
|
+
|
9
|
+
describe '.create' do
|
10
|
+
|
11
|
+
context 'given a valid object' do
|
12
|
+
mandate = MANDATE_DATA
|
13
|
+
|
14
|
+
it 'creates the mandate entity' do
|
15
|
+
created = MangoApi::Mandates.create mandate
|
16
|
+
|
17
|
+
expect(created).to be_kind_of MangoModel::Mandate
|
18
|
+
expect(created.id).not_to be_nil
|
19
|
+
expect(created.document_url).not_to be_nil
|
20
|
+
expect(created.execution_type).to be MangoModel::MandateExecutionType::WEB
|
21
|
+
expect(created.mandate_type).to be MangoModel::MandateType::DIRECT_DEBIT
|
22
|
+
expect(created.redirect_url).not_to be_nil
|
23
|
+
expect(created.return_url).not_to be_nil
|
24
|
+
expect(created.status).to be MangoModel::MandateStatus::CREATED
|
25
|
+
expect(created.user_id).not_to be_nil
|
26
|
+
expect(its_the_same_mandate(mandate, created)).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.get' do
|
32
|
+
|
33
|
+
context "given an existing entity's ID" do
|
34
|
+
mandate = MANDATE_PERSISTED
|
35
|
+
id = mandate.id
|
36
|
+
|
37
|
+
it 'retrieves the corresponding entity' do
|
38
|
+
retrieved = MangoApi::Mandates.get id
|
39
|
+
|
40
|
+
expect(retrieved).to be_kind_of MangoModel::Mandate
|
41
|
+
expect(retrieved.id).to eq id
|
42
|
+
expect(its_the_same_mandate(mandate, retrieved)).to be_truthy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# describe '.cancel' do
|
48
|
+
#
|
49
|
+
# context "given an existing entity's ID" do
|
50
|
+
# mandate = MangoModel::Mandate.new
|
51
|
+
# mandate.bank_account_id = GB_ACCOUNT_PERSISTED.id
|
52
|
+
# mandate.culture = MangoModel::MandateCultureCode::EN
|
53
|
+
# mandate.return_url = 'http://www.my-site.com/returnURL/'
|
54
|
+
# created = MangoApi::Mandates.create mandate
|
55
|
+
# id = created.id
|
56
|
+
#
|
57
|
+
# it 'cancels the corresponding entity' do
|
58
|
+
#
|
59
|
+
# # Attention
|
60
|
+
# #
|
61
|
+
# # To make this test pass, you must pause execution with a breakpoint on
|
62
|
+
# # the following line, and use your browser to open the page received
|
63
|
+
# # in the +created.redirect_url+ property and click the Confirm button
|
64
|
+
# # before continuing.
|
65
|
+
# canceled = MangoApi::Mandates.cancel id # Place breakpoint here
|
66
|
+
#
|
67
|
+
# expect(canceled).to be_kind_of MangoModel::Mandate
|
68
|
+
# expect(canceled.id).to eq id
|
69
|
+
# expect(canceled.status).to be MangoModel::MandateStatus::FAILED
|
70
|
+
# expect(canceled.result_code).to eq '001806' # cancelled
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
|
75
|
+
describe '.all' do
|
76
|
+
|
77
|
+
context 'not having specified filters' do
|
78
|
+
default_per_page = 10
|
79
|
+
|
80
|
+
it 'retrieves a list with default parameters' do
|
81
|
+
results = MangoApi::Mandates.all
|
82
|
+
|
83
|
+
expect(results).to be_kind_of Array
|
84
|
+
expect(results.length).to eq default_per_page
|
85
|
+
results.each do |result|
|
86
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
87
|
+
expect(result.id).not_to be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'having specified filters' do
|
93
|
+
per_page = 11
|
94
|
+
|
95
|
+
it 'retrieves a list with specified parameters' do
|
96
|
+
results = MangoApi::Mandates.all do |filter|
|
97
|
+
filter.page = 1
|
98
|
+
filter.per_page = per_page
|
99
|
+
filter.sort_field = MangoPay::SortField::CREATION_DATE
|
100
|
+
filter.sort_direction = MangoPay::SortDirection::ASC
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(results).to be_kind_of Array
|
104
|
+
expect(results.length).to be per_page
|
105
|
+
results.each.with_index do |result, index|
|
106
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
107
|
+
expect(result.id).not_to be_nil
|
108
|
+
next if index == results.length - 1
|
109
|
+
first_date = result.creation_date
|
110
|
+
second_date = results[index + 1].creation_date
|
111
|
+
expect(first_date < second_date).to be_truthy
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.of_user' do
|
118
|
+
# prepare test data
|
119
|
+
10.times do
|
120
|
+
persist_mandate build_mandate
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "given an existing user entity's ID" do
|
124
|
+
id = NATURAL_USER_PERSISTED.id
|
125
|
+
|
126
|
+
context 'not having specified filters' do
|
127
|
+
default_per_page = 10
|
128
|
+
|
129
|
+
it 'retrieves a list with default parameters' do
|
130
|
+
results = MangoApi::Mandates.of_user id
|
131
|
+
|
132
|
+
expect(results).to be_kind_of Array
|
133
|
+
expect(results.length).to eq default_per_page
|
134
|
+
results.each do |result|
|
135
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
136
|
+
expect(result.id).not_to be_nil
|
137
|
+
expect(result.user_id).to eq id
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'having specified filters' do
|
143
|
+
per_page = 8
|
144
|
+
|
145
|
+
it 'retrieves a list with specified parameters' do
|
146
|
+
results = MangoApi::Mandates.of_user id do |filter|
|
147
|
+
filter.page = 1
|
148
|
+
filter.per_page = per_page
|
149
|
+
filter.sort_field = MangoPay::SortField::CREATION_DATE
|
150
|
+
filter.sort_direction = MangoPay::SortDirection::ASC
|
151
|
+
end
|
152
|
+
|
153
|
+
expect(results).to be_kind_of Array
|
154
|
+
expect(results.length).to be per_page
|
155
|
+
results.each.with_index do |result, index|
|
156
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
157
|
+
expect(result.id).not_to be_nil
|
158
|
+
expect(result.user_id).to eq id
|
159
|
+
next if index == results.length - 1
|
160
|
+
first_date = result.creation_date
|
161
|
+
second_date = results[index + 1].creation_date
|
162
|
+
expect(first_date <= second_date).to be_truthy
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '.of_bank_account' do
|
170
|
+
|
171
|
+
context "given an existing bank account entity's ID" do
|
172
|
+
user_id = NATURAL_USER_PERSISTED.id
|
173
|
+
account_id = IBAN_ACCOUNT_PERSISTED.id
|
174
|
+
|
175
|
+
context 'not having specified filters' do
|
176
|
+
default_per_page = 10
|
177
|
+
|
178
|
+
it 'retrieves a list with default parameters' do
|
179
|
+
results = MangoApi::Mandates.of_bank_account(user_id, account_id)
|
180
|
+
|
181
|
+
expect(results).to be_kind_of Array
|
182
|
+
expect(results.length).to eq default_per_page
|
183
|
+
results.each.with_index do |result, index|
|
184
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
185
|
+
expect(result.id).not_to be_nil
|
186
|
+
next if index == results.length - 1
|
187
|
+
first_date = result.creation_date
|
188
|
+
second_date = results[index + 1].creation_date
|
189
|
+
expect(first_date <= second_date).to be_truthy
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'having specified filters' do
|
195
|
+
per_page = 3
|
196
|
+
|
197
|
+
it 'retrieves a list according to specified parameters' do
|
198
|
+
results = MangoApi::Mandates.of_bank_account(user_id, account_id) do |filter|
|
199
|
+
filter.page = 1
|
200
|
+
filter.per_page = per_page
|
201
|
+
filter.sort_field = MangoPay::SortField::CREATION_DATE
|
202
|
+
filter.sort_direction = MangoPay::SortDirection::ASC
|
203
|
+
end
|
204
|
+
|
205
|
+
expect(results).to be_kind_of Array
|
206
|
+
expect(results.length).to eq per_page
|
207
|
+
results.each.with_index do |result, index|
|
208
|
+
expect(result).to be_kind_of MangoModel::Mandate
|
209
|
+
expect(result.id).not_to be_nil
|
210
|
+
next if index == results.length - 1
|
211
|
+
first_date = result.creation_date
|
212
|
+
second_date = results[index + 1].creation_date
|
213
|
+
expect(first_date <= second_date).to be_truthy
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|