diff --git a/apps/ff_cth/src/ct_domain.erl b/apps/ff_cth/src/ct_domain.erl index 4dba5fb..57261e8 100644 --- a/apps/ff_cth/src/ct_domain.erl +++ b/apps/ff_cth/src/ct_domain.erl @@ -144,7 +144,8 @@ proxy(Ref, Name, Opts) -> object(). system_account_set(Ref, Name, ?cur(SymCode), C) -> - AccountID = account(SymCode, C), + AccountID1 = account(SymCode, C), + AccountID2 = account(SymCode, C), {system_account_set, #domain_SystemAccountSetObject{ ref = Ref, data = #domain_SystemAccountSet{ @@ -152,7 +153,8 @@ system_account_set(Ref, Name, ?cur(SymCode), C) -> description = <<>>, accounts = #{ ?cur(SymCode) => #domain_SystemAccount{ - settlement = AccountID + settlement = AccountID1, + subagent = AccountID2 } } } diff --git a/apps/ff_cth/src/ct_payment_system.erl b/apps/ff_cth/src/ct_payment_system.erl index 3abc9fd..de23a1f 100644 --- a/apps/ff_cth/src/ct_payment_system.erl +++ b/apps/ff_cth/src/ct_payment_system.erl @@ -130,7 +130,11 @@ setup_dominant(Options, C) -> configure_processing_apps(_Options) -> ok = set_app_env( - [ff_transfer, withdrawal, system, accounts, <<"RUB">>], + [ff_transfer, withdrawal, system, accounts, settlement, <<"RUB">>], + create_company_account() + ), + ok = set_app_env( + [ff_transfer, withdrawal, system, accounts, subagent, <<"RUB">>], create_company_account() ), ok = set_app_env( @@ -454,6 +458,11 @@ default_termset(Options) -> {wallet, receiver_destination}, {system, settlement}, ?share(10, 100, operation_amount) + ), + ?cfpost( + {wallet, receiver_destination}, + {system, subagent}, + ?share(10, 100, operation_amount) ) ]} } diff --git a/apps/ff_transfer/src/ff_withdrawal.erl b/apps/ff_transfer/src/ff_withdrawal.erl index 040a9f7..39368d0 100644 --- a/apps/ff_transfer/src/ff_withdrawal.erl +++ b/apps/ff_transfer/src/ff_withdrawal.erl @@ -253,10 +253,19 @@ create_p_transfer(Withdrawal) -> ProviderAccount = maps:get(CurrencyID, ProviderAccounts, undefined), ProviderFee = ff_withdrawal_provider:fee(Provider, CurrencyID), SystemAccounts = unwrap(system, get_system_accounts()), - SystemAccount = maps:get(CurrencyID, SystemAccounts, undefined), + SettlementAccountMap = maps:get(settlement, SystemAccounts, #{}), + SettlementAccount = maps:get(CurrencyID, SettlementAccountMap, undefined), + SubagentAccountMap = maps:get(subagent, SystemAccounts, #{}), + SubagentAccount = maps:get(CurrencyID, SubagentAccountMap, undefined), CashFlowPlan = unwrap(provider_fee, ff_cash_flow:add_fee(WalletCashFlowPlan, ProviderFee)), FinalCashFlow = unwrap(cash_flow, finalize_cash_flow( - CashFlowPlan, WalletAccount, DestinationAccount, SystemAccount, ProviderAccount, body(Withdrawal) + CashFlowPlan, + WalletAccount, + DestinationAccount, + SettlementAccount, + SubagentAccount, + ProviderAccount, + body(Withdrawal) )), PTransferID = construct_p_transfer_id(id(Withdrawal)), PostingsTransferEvents = unwrap(p_transfer, ff_postings_transfer:create(PTransferID, FinalCashFlow)), @@ -331,16 +340,18 @@ get_system_accounts() -> SystemAccounts = maps:get(accounts, SystemConfig, undefined), {ok, SystemAccounts}. --spec finalize_cash_flow(cash_flow_plan(), account(), account(), account(), account(), body()) -> +-spec finalize_cash_flow(cash_flow_plan(), account(), account(), account(), account(), account(), body()) -> {ok, final_cash_flow()} | {error, _Error}. -finalize_cash_flow(CashFlowPlan, WalletAccount, DestinationAccount, SystemAccount, ProviderAccount, Body) -> +finalize_cash_flow(CashFlowPlan, WalletAccount, DestinationAccount, + SettlementAccount, SubagentAccount, ProviderAccount, Body) -> Constants = #{ operation_amount => Body }, Accounts = genlib_map:compact(#{ {wallet, sender_settlement} => WalletAccount, {wallet, receiver_destination} => DestinationAccount, - {system, settlement} => SystemAccount, + {system, settlement} => SettlementAccount, + {system, subagent} => SubagentAccount, {provider, settlement} => ProviderAccount }), ff_cash_flow:finalize(CashFlowPlan, Accounts, Constants). diff --git a/apps/ff_transfer/test/ff_transfer_SUITE.erl b/apps/ff_transfer/test/ff_transfer_SUITE.erl index a8e1433..195753b 100644 --- a/apps/ff_transfer/test/ff_transfer_SUITE.erl +++ b/apps/ff_transfer/test/ff_transfer_SUITE.erl @@ -456,5 +456,5 @@ process_withdrawal(WalID, DestID) -> genlib_retry:linear(15, 1000) ), ok = await_wallet_balance({10000 - 4240, <<"RUB">>}, WalID), - ok = await_destination_balance({4240 - 424, <<"RUB">>}, DestID), + ok = await_destination_balance({4240 - 848, <<"RUB">>}, DestID), WdrID. diff --git a/apps/fistful/src/ff_cash_flow.erl b/apps/fistful/src/ff_cash_flow.erl index 3f24838..ec82b5c 100644 --- a/apps/fistful/src/ff_cash_flow.erl +++ b/apps/fistful/src/ff_cash_flow.erl @@ -59,6 +59,7 @@ {wallet, receiver_settlement} | {wallet, receiver_destination} | {system, settlement} | + {system, subagent} | {provider, settlement}. -type final_account() :: #{ account := account(), diff --git a/config/sys.config b/config/sys.config index e0e01c7..706c0f3 100644 --- a/config/sys.config +++ b/config/sys.config @@ -91,11 +91,21 @@ }, system => #{ accounts => #{ - <<"RUB">> => #{ - id => <<"system_some_id">>, - identity => <<"system_some_other_id">>, - currency => <<"RUB">>, - accounter_account_id => <<"system_some_third_id">> + settlement => #{ + <<"RUB">> => #{ + id => <<"system_some_id">>, + identity => <<"system_some_other_id">>, + currency => <<"RUB">>, + accounter_account_id => <<"system_some_third_id">> + } + }, + subagent => #{ + <<"RUB">> => #{ + id => <<"system_some_id">>, + identity => <<"system_some_other_id">>, + currency => <<"RUB">>, + accounter_account_id => <<"system_some_third_id">> + } } } } diff --git a/docker-compose.sh b/docker-compose.sh index 1deadce..8d81d33 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -46,7 +46,7 @@ services: retries: 10 hellgate: - image: dr.rbkmoney.com/rbkmoney/hellgate:998985ade2bb8d8b7882e8d09a036414e91e25b4 + image: dr.rbkmoney.com/rbkmoney/hellgate:8d7f618f6f2e1d8410384797b8f9a76150580f46 command: /opt/hellgate/bin/hellgate foreground depends_on: machinegun: @@ -86,7 +86,7 @@ services: retries: 20 dominant: - image: dr.rbkmoney.com/rbkmoney/dominant:7eda4ecade678a7a2dd25795c214ab8be93e8cd4 + image: dr.rbkmoney.com/rbkmoney/dominant:3cf6c46d482f0057d117209170c831f5a238d95a command: /opt/dominant/bin/dominant foreground depends_on: machinegun: @@ -117,7 +117,7 @@ services: test: "curl http://localhost:8022/" interval: 5s timeout: 1s - retries: 10 + retries: 30 identification: image: dr.rbkmoney.com/rbkmoney/identification:ff4ef447327d81882c0ee618b622e5e04e771881 diff --git a/rebar.lock b/rebar.lock index cf34951..5adff77 100644 --- a/rebar.lock +++ b/rebar.lock @@ -18,7 +18,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},1}, {<<"dmsl">>, {git,"git@github.com:rbkmoney/damsel.git", - {ref,"8cfdc074bf39ae966c286796d25f94c1e95d5b47"}}, + {ref,"37f417a48c19675478058733fa753dbe70babf58"}}, 0}, {<<"dmt_client">>, {git,"git@github.com:rbkmoney/dmt_client.git", @@ -42,7 +42,7 @@ 0}, {<<"fistful_proto">>, {git,"git@github.com:rbkmoney/fistful-proto.git", - {ref,"56a39762845bf8eb299ae0ba4d0bf21ae0fa4620"}}, + {ref,"6977cd82d85282277a2d371edca647ce9cdfcf70"}}, 0}, {<<"fistful_reporter_proto">>, {git,"git@github.com:rbkmoney/fistful-reporter-proto.git",