IMP-250: Remove payout (#48)

This commit is contained in:
Артем 2024-07-02 19:08:09 +03:00 committed by GitHub
parent 2477bfbe20
commit 89759bfd18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 7 additions and 845 deletions

View File

@ -28,7 +28,6 @@
bouncer_client,
token_keeper_client,
party_client,
payout_manager_proto,
magista_proto,
opentelemetry_api,
opentelemetry_exporter,

View File

@ -6,7 +6,6 @@
-include_lib("damsel/include/dmsl_payproc_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_webhooker_thrift.hrl").
-include_lib("payout_manager_proto/include/payouts_payout_manager_thrift.hrl").
-type fragment() :: bouncer_client:context_fragment().
-type acc() :: bouncer_context_helpers:context_fragment().
@ -20,7 +19,6 @@
-type prototypes() :: [
{operation, prototype_operation()}
| {payproc, prototype_payproc()}
| {payouts, prototype_payouts()}
| {webhooks, prototype_webhooks()}
].
@ -36,8 +34,7 @@
customer => entity_id(),
binding => entity_id(),
file => entity_id(),
webhook => entity_id(),
payout => entity_id()
webhook => entity_id()
}.
-type prototype_payproc() :: #{
@ -46,11 +43,6 @@
customer => customer_id() | customer() | undefined
}.
-type prototype_payouts() :: #{
payout => payout_id() | payout() | undefined,
contract => entity_id()
}.
-type prototype_webhooks() :: #{
webhook => webhook_id() | webhook() | undefined
}.
@ -67,15 +59,11 @@
-type webhook_id() :: dmsl_webhooker_thrift:'WebhookID'().
-type webhook() :: dmsl_webhooker_thrift:'Webhook'().
-type payout_id() :: payouts_payout_manager_thrift:'PayoutID'().
-type payout() :: payouts_payout_manager_thrift:'Payout'().
-type entity_id() :: binary().
-export_type([prototypes/0]).
-export_type([prototype_operation/0]).
-export_type([prototype_payproc/0]).
-export_type([prototype_payouts/0]).
-export_type([prototype_webhooks/0]).
-export([new/0]).
@ -113,8 +101,7 @@ build(operation, Params = #{id := OperationID}, Acc, _WoodyCtx) ->
customer = maybe_entity(customer, Params),
binding = maybe_entity(binding, Params),
file = maybe_entity(file, Params),
webhook = maybe_entity(webhook, Params),
payout = maybe_entity(payout, Params)
webhook = maybe_entity(webhook, Params)
}
}
};
@ -147,20 +134,6 @@ build(webhooks, Params = #{}, Acc, WoodyCtx) ->
fun(V) -> build_webhook_ctx(V, WoodyCtx) end
)
}
};
build(payouts, Params = #{}, Acc, WoodyCtx) ->
Payout0 = maybe_with(payout, Params, fun(V) ->
build_payout_ctx(V, WoodyCtx)
end),
Payout = maybe(Payout0, fun(_Payout0) ->
Payout0#ctx_v1_Payout{
contract = maybe_entity(contract, Params)
}
end),
Acc#ctx_v1_ContextFragment{
payouts = #ctx_v1_ContextPayouts{
payout = Payout
}
}.
%%
@ -235,24 +208,6 @@ build_binding_ctx(#payproc_CustomerBinding{id = ID}) ->
%%
build_payout_ctx(ID, WoodyCtx) when is_binary(ID) ->
maybe_with_woody_result(payouts, 'GetPayout', {ID}, WoodyCtx, fun build_payout_ctx/1);
build_payout_ctx(Payout, _WoodyCtx) ->
build_payout_ctx(Payout).
build_payout_ctx(#payouts_Payout{
payout_id = ID,
party_id = PartyID,
shop_id = ShopID
}) ->
#ctx_v1_Payout{
id = ID,
party = build_entity(PartyID),
shop = build_entity(ShopID)
}.
%%
build_webhook_ctx(ID, WoodyCtx) when is_integer(ID) ->
maybe_with_woody_result(webhook_manager, 'Get', {ID}, WoodyCtx, fun build_webhook_ctx/1);
build_webhook_ctx(Webhook, _WoodyCtx) ->

View File

@ -111,7 +111,6 @@ get_handlers() ->
capi_handler_parties,
capi_handler_payment_institutions,
capi_handler_payments,
capi_handler_payouts,
capi_handler_search,
capi_handler_shops,
capi_handler_trade_blocs,

View File

@ -13,7 +13,6 @@
-export([decode_reporting_preferences/1]).
-export([decode_residence/1]).
-export([decode_payment_institution_ref/1]).
-export([decode_payout_tool_details/1]).
%%
@ -176,21 +175,6 @@ decode_residence(Residence) when is_atom(Residence) ->
decode_payment_institution_ref(#domain_PaymentInstitutionRef{id = Ref}) ->
Ref.
-spec decode_payout_tool_details({atom(), _}) -> capi_handler_decoder_utils:decode_data().
decode_payout_tool_details({russian_bank_account, V}) ->
decode_russian_bank_account(V, #{<<"detailsType">> => <<"PayoutToolDetailsBankAccount">>});
decode_payout_tool_details({international_bank_account, V}) ->
decode_international_bank_account(V, #{<<"detailsType">> => <<"PayoutToolDetailsInternationalBankAccount">>});
decode_payout_tool_details({wallet_info, V}) ->
#{
<<"detailsType">> => <<"PayoutToolDetailsWalletInfo">>,
<<"walletID">> => V#domain_WalletInfo.wallet_id
};
decode_payout_tool_details({payment_institution_account, _V}) ->
#{
<<"detailsType">> => <<"PayoutToolDetailsPaymentInstitutionAccount">>
}.
decode_russian_bank_account(BankAccount, V) ->
V#{
<<"account">> => BankAccount#domain_RussianBankAccount.account,
@ -198,29 +182,3 @@ decode_russian_bank_account(BankAccount, V) ->
<<"bankPostAccount">> => BankAccount#domain_RussianBankAccount.bank_post_account,
<<"bankBik">> => BankAccount#domain_RussianBankAccount.bank_bik
}.
decode_international_bank_account(undefined, _) ->
undefined;
decode_international_bank_account(BankAccount, V) ->
genlib_map:compact(V#{
<<"number">> => BankAccount#domain_InternationalBankAccount.number,
<<"iban">> => BankAccount#domain_InternationalBankAccount.iban,
<<"bankDetails">> => decode_international_bank_details(
BankAccount#domain_InternationalBankAccount.bank
),
<<"correspondentBankAccount">> => decode_international_bank_account(
BankAccount#domain_InternationalBankAccount.correspondent_account,
#{}
)
}).
decode_international_bank_details(undefined) ->
undefined;
decode_international_bank_details(Bank) ->
genlib_map:compact(#{
<<"bic">> => Bank#domain_InternationalBankDetails.bic,
<<"abartn">> => Bank#domain_InternationalBankDetails.aba_rtn,
<<"name">> => Bank#domain_InternationalBankDetails.name,
<<"countryCode">> => decode_residence(Bank#domain_InternationalBankDetails.country),
<<"address">> => Bank#domain_InternationalBankDetails.address
}).

View File

@ -56,40 +56,6 @@ prepare(OperationID = 'GetPaymentInstitutionPaymentTerms', Req, Context) ->
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID, Req, Context) when
OperationID =:= 'GetPaymentInstitutionPayoutMethods';
OperationID =:= 'GetPaymentInstitutionPayoutMethodsForParty'
->
Authorize = mk_authorize_operation(OperationID, Context),
Process = fun() ->
PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)),
case compute_payment_institution_terms(PaymentInstitutionID, prepare_request_varset(Req, Context), Context) of
{ok, #domain_TermSet{payouts = #domain_PayoutsServiceTerms{payout_methods = PayoutMethods}}} ->
{ok, {200, #{}, decode_payout_methods_selector(PayoutMethods)}};
{ok, #domain_TermSet{payouts = undefined}} ->
{ok, general_error(404, <<"Automatic payouts not allowed">>)};
{error, #payproc_PaymentInstitutionNotFound{}} ->
{ok, general_error(404, <<"Payment institution not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID, Req, Context) when
OperationID =:= 'GetPaymentInstitutionPayoutSchedules';
OperationID =:= 'GetPaymentInstitutionPayoutSchedulesForParty'
->
Authorize = mk_authorize_operation(OperationID, Context),
Process = fun() ->
PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)),
case compute_payment_institution_terms(PaymentInstitutionID, prepare_request_varset(Req, Context), Context) of
{ok, #domain_TermSet{payouts = #domain_PayoutsServiceTerms{payout_schedules = Schedules}}} ->
{ok, {200, #{}, decode_business_schedules_selector(Schedules)}};
{ok, #domain_TermSet{payouts = undefined}} ->
{ok, general_error(404, <<"Automatic payouts not allowed">>)};
{error, #payproc_PaymentInstitutionNotFound{}} ->
{ok, general_error(404, <<"Payment institution not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetServiceProviderByID', Req, Context) ->
Authorize = mk_authorize_operation(OperationID, Context),
Process = fun() ->
@ -151,33 +117,6 @@ compute_payment_institution_terms(PaymentInstitutionID, VS, Context) ->
Ref = ?PAYMENT_INSTITUTION_REF(PaymentInstitutionID),
capi_party:compute_payment_institution_terms(Ref, VS, Context).
prepare_request_varset(#{'partyID' := PartyID} = Req, _Context) ->
#payproc_Varset{
currency = encode_optional_currency(genlib_map:get('currency', Req)),
payout_method = encode_optional_payout_method(genlib_map:get('payoutMethod', Req)),
party_id = PartyID
};
prepare_request_varset(Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Req1 = maps:put('partyID', PartyID, Req),
prepare_request_varset(Req1, Context).
%
encode_optional_payout_method('BankAccount') ->
#domain_PayoutMethodRef{id = russian_bank_account};
encode_optional_payout_method('InternationalBankAccount') ->
#domain_PayoutMethodRef{id = international_bank_account};
encode_optional_payout_method('Wallet') ->
#domain_PayoutMethodRef{id = wallet_info};
encode_optional_payout_method('PaymentInstitutionAccount') ->
#domain_PayoutMethodRef{id = payment_institution_account};
encode_optional_payout_method(undefined) ->
undefined.
encode_optional_currency(undefined) -> undefined;
encode_optional_currency(SymbolicCode) -> capi_handler_encoder:encode_currency(SymbolicCode).
%
decode_payment_institution(#domain_PaymentInstitutionObject{ref = Ref, data = Data}) ->
@ -205,25 +144,6 @@ decode_payment_terms(Fun, {value, Val}) when is_list(Val) ->
decode_payment_terms(_, _) ->
undefined.
decode_payout_method(#domain_PayoutMethodRef{id = russian_bank_account}) ->
<<"BankAccount">>;
decode_payout_method(#domain_PayoutMethodRef{id = international_bank_account}) ->
<<"InternationalBankAccount">>;
decode_payout_method(#domain_PayoutMethodRef{id = wallet_info}) ->
<<"Wallet">>;
decode_payout_method(#domain_PayoutMethodRef{id = payment_institution_account}) ->
<<"PaymentInstitutionAccount">>.
decode_payout_methods_selector({value, Val}) when is_list(Val) ->
lists:map(fun decode_payout_method/1, Val);
decode_payout_methods_selector(_) ->
[].
decode_business_schedules_selector({value, Val}) when is_list(Val) ->
lists:map(fun capi_handler_decoder_utils:decode_business_schedule_ref/1, Val);
decode_business_schedules_selector(_) ->
[].
%%
decode_payment_service(ID, PaymentService = #domain_PaymentService{}) ->

View File

@ -1,272 +0,0 @@
-module(capi_handler_payouts).
-include_lib("damsel/include/dmsl_payproc_thrift.hrl").
-include_lib("payout_manager_proto/include/payouts_payout_manager_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-behaviour(capi_handler).
-export([prepare/3]).
-import(capi_handler_utils, [general_error/2, logic_error/2]).
-spec prepare(
OperationID :: capi_handler:operation_id(),
Req :: capi_handler:request_data(),
Context :: capi_handler:processing_context()
) -> {ok, capi_handler:request_state()} | {error, noimpl}.
prepare(OperationID = 'GetPayout', Req, Context) ->
PayoutID = maps:get('payoutID', Req),
OperationContext = #{
id => OperationID,
payout => PayoutID
},
Payout =
case capi_handler_utils:service_call({payouts, 'GetPayout', {PayoutID}}, Context) of
{ok, Result} ->
Result;
{exception, #payouts_NotFound{}} ->
undefined
end,
ContractID = capi_utils:maybe(Payout, fun(_Payout) ->
get_payout_contract_id(Payout, Context)
end),
Prototypes = [
{operation, OperationContext},
{payouts, #{payout => Payout, contract => ContractID}}
],
Authorize = fun() ->
{ok, capi_auth:authorize_operation(Prototypes, Context)}
end,
Process = fun() ->
capi_handler:respond_if_undefined(Payout, general_error(404, <<"Payout not found">>)),
{ok, PayoutTool} = get_payout_tool(Payout, Context),
{ok, {200, #{}, decode_payout(Payout, PayoutTool)}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'CreatePayout', Req, Context) ->
PayoutParams = maps:get('PayoutParams', Req),
PartyID = maps:get(<<"partyID">>, PayoutParams, capi_handler_utils:get_party_id(Context)),
OperationContext = #{
id => OperationID,
party => PartyID,
shop => maps:get(<<"shopID">>, PayoutParams)
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
CreateRequest = encode_payout_params(PartyID, PayoutParams),
case capi_handler_utils:service_call({payouts, 'CreatePayout', {CreateRequest}}, Context) of
{ok, Payout} ->
{ok, PayoutTool} = get_payout_tool(Payout, Context),
{ok, {201, #{}, decode_payout(Payout, PayoutTool)}};
{exception, #payouts_InsufficientFunds{}} ->
{ok, logic_error('invalidCash', <<"Invalid amount or currency">>)};
{exception, #payouts_InvalidRequest{errors = Errors}} ->
FormattedErrors = capi_handler_utils:format_request_errors(Errors),
{ok, logic_error('invalidRequest', FormattedErrors)};
{exception, #payouts_PayoutAlreadyExists{}} ->
{ok, logic_error('invalidRequest', <<"Payout already exists">>)};
{exception, #payouts_NotFound{message = Message}} ->
{ok, logic_error('invalidRequest', Message)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPayoutTools', Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
OperationContext = #{
id => OperationID,
party => PartyID
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
case capi_party:get_contract(PartyID, maps:get('contractID', Req), Context) of
{ok, #domain_Contract{payout_tools = PayoutTools}} ->
{ok, {200, #{}, [decode_payout_tool(P) || P <- PayoutTools]}};
{error, #payproc_ContractNotFound{}} ->
{ok, general_error(404, <<"Contract not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPayoutToolByID', Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
OperationContext = #{
id => OperationID,
party => PartyID
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
PayoutToolID = maps:get('payoutToolID', Req),
ContractID = maps:get('contractID', Req),
case get_payout_tool_by_id(PartyID, ContractID, PayoutToolID, Context) of
{ok, PayoutTool} ->
{ok, {200, #{}, decode_payout_tool(PayoutTool)}};
{error, not_found} ->
{ok, general_error(404, <<"PayoutTool not found">>)};
{error, #payproc_ContractNotFound{}} ->
{ok, general_error(404, <<"Contract not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPayoutToolsForParty', Req, Context) ->
PartyID = maps:get('partyID', Req),
OperationContext = #{
id => OperationID,
party => PartyID
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
ContractID = maps:get('contractID', Req),
case capi_party:get_contract(PartyID, ContractID, Context) of
{ok, #domain_Contract{payout_tools = PayoutTools}} ->
{ok, {200, #{}, [decode_payout_tool(P) || P <- PayoutTools]}};
{error, #payproc_ContractNotFound{}} ->
{ok, general_error(404, <<"Contract not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPayoutToolByIDForParty', Req, Context) ->
PartyID = maps:get('partyID', Req),
OperationContext = #{
id => OperationID,
party => PartyID
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
PayoutToolID = maps:get('payoutToolID', Req),
ContractID = maps:get('contractID', Req),
case get_payout_tool_by_id(PartyID, ContractID, PayoutToolID, Context) of
{ok, PayoutTool} ->
{ok, {200, #{}, decode_payout_tool(PayoutTool)}};
{error, not_found} ->
{ok, general_error(404, <<"PayoutTool not found">>)};
{error, #payproc_ContractNotFound{}} ->
{ok, general_error(404, <<"Contract not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetScheduleByRef', Req, Context) ->
OperationContext = #{
id => OperationID
},
Authorize = fun() ->
{ok, capi_auth:authorize_operation([{operation, OperationContext}], Context)}
end,
Process = fun() ->
case get_schedule_by_id(genlib:to_int(maps:get('scheduleID', Req)), Context) of
{ok, Schedule} ->
{ok, {200, #{}, decode_business_schedule(Schedule)}};
{error, not_found} ->
{ok, general_error(404, <<"Schedule not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(_OperationID, _Req, _Context) ->
{error, noimpl}.
%%
get_schedule_by_id(ScheduleID, Context) ->
Ref = {business_schedule, #domain_BusinessScheduleRef{id = ScheduleID}},
capi_domain:get(Ref, Context).
get_payout_tool(Payout, Context) ->
PayoutToolID = Payout#payouts_Payout.payout_tool_id,
PartyID = Payout#payouts_Payout.party_id,
ContractID = get_payout_contract_id(Payout, Context),
get_payout_tool_by_id(PartyID, ContractID, PayoutToolID, Context).
get_payout_contract_id(Payout, Context) ->
PartyID = Payout#payouts_Payout.party_id,
ShopID = Payout#payouts_Payout.shop_id,
{ok, Shop} = capi_party:get_shop(PartyID, ShopID, Context),
Shop#domain_Shop.contract_id.
get_payout_tool_by_id(PartyID, ContractID, PayoutToolID, Context) ->
case capi_party:get_contract(PartyID, ContractID, Context) of
{ok, #domain_Contract{payout_tools = PayoutTools}} ->
case lists:keyfind(PayoutToolID, #domain_PayoutTool.id, PayoutTools) of
#domain_PayoutTool{} = PayoutTool ->
{ok, PayoutTool};
false ->
{error, not_found}
end;
Error ->
Error
end.
%%
encode_payout_params(PartyID, PayoutParams) ->
#payouts_PayoutParams{
shop_params = #payouts_ShopParams{
party_id = PartyID,
shop_id = maps:get(<<"shopID">>, PayoutParams)
},
cash = encode_payout_cash(PayoutParams),
payout_id = maps:get(<<"id">>, PayoutParams, undefined),
payout_tool_id = maps:get(<<"payoutToolID">>, PayoutParams)
}.
encode_payout_cash(#{<<"amount">> := Amount, <<"currency">> := Currency}) ->
#payouts_Cash{
amount = Amount,
currency = encode_payout_currency(Currency)
}.
encode_payout_currency(SymbolicCode) ->
#payouts_CurrencyRef{symbolic_code = SymbolicCode}.
%%
decode_payout_tool(#domain_PayoutTool{id = ID, currency = Currency, payout_tool_info = Info}) ->
#{
<<"id">> => ID,
<<"currency">> => capi_handler_decoder_utils:decode_currency(Currency),
<<"details">> => capi_handler_decoder_party:decode_payout_tool_details(Info)
}.
decode_payout(Payout, #domain_PayoutTool{payout_tool_info = Info}) ->
Currency = decode_payout_currency(Payout#payouts_Payout.currency),
PayoutToolDetails = capi_handler_decoder_party:decode_payout_tool_details(Info),
capi_handler_utils:merge_and_compact(
#{
<<"id">> => Payout#payouts_Payout.payout_id,
<<"createdAt">> => Payout#payouts_Payout.created_at,
<<"shopID">> => Payout#payouts_Payout.shop_id,
<<"payoutToolDetails">> => PayoutToolDetails,
<<"amount">> => Payout#payouts_Payout.amount,
<<"fee">> => Payout#payouts_Payout.fee,
<<"currency">> => Currency
},
decode_payout_status(Payout#payouts_Payout.status)
).
decode_payout_status({cancelled, #payouts_PayoutCancelled{details = Details}}) ->
#{
<<"status">> => <<"cancelled">>,
<<"cancellationDetails">> => genlib:to_binary(Details)
};
decode_payout_status({Status, _}) ->
#{
<<"status">> => genlib:to_binary(Status)
}.
decode_payout_currency(#payouts_CurrencyRef{symbolic_code = SymbolicCode}) ->
capi_handler_decoder_utils:decode_currency(#domain_CurrencyRef{symbolic_code = SymbolicCode}).
decode_business_schedule(#domain_BusinessScheduleObject{ref = Ref, data = Data}) ->
genlib_map:compact(#{
<<"scheduleID">> => Ref#domain_BusinessScheduleRef.id,
<<"name">> => Data#domain_BusinessSchedule.name,
<<"description">> => Data#domain_BusinessSchedule.description
}).

View File

@ -459,7 +459,6 @@ build_prototypes(OperationID, Context, Req) ->
invoice => InvoiceID,
payment => genlib_map:get('paymentID', Req),
customer => CustomerID,
payout => genlib_map:get('payoutID', Req),
refund => genlib_map:get('refundID', Req)
}},
{payproc, #{

View File

@ -189,7 +189,5 @@ decode_shop(Shop) ->
<<"categoryID">> => capi_handler_decoder_utils:decode_category_ref(Shop#domain_Shop.category),
<<"details">> => capi_handler_decoder_party:decode_shop_details(Shop#domain_Shop.details),
<<"location">> => capi_handler_decoder_party:decode_shop_location(Shop#domain_Shop.location),
<<"contractID">> => Shop#domain_Shop.contract_id,
<<"payoutToolID">> => Shop#domain_Shop.payout_tool_id,
<<"scheduleID">> => capi_handler_decoder_utils:decode_business_schedule_ref(Shop#domain_Shop.payout_schedule)
<<"contractID">> => Shop#domain_Shop.contract_id
}).

View File

@ -8,7 +8,6 @@
-include_lib("damsel/include/dmsl_webhooker_thrift.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("payout_manager_proto/include/payouts_payout_manager_thrift.hrl").
-include_lib("capi_dummy_data.hrl").
-include_lib("capi_bouncer_data.hrl").
@ -91,13 +90,6 @@
get_contract_adjustments_for_party_ok_test/1,
get_contract_adjustment_by_id_ok_test/1,
get_contract_adjustment_by_id_for_party_ok_test/1,
get_payout_tools_ok_test/1,
get_payout_tools_for_party_ok_test/1,
get_payout_tool_by_id/1,
get_payout_tool_by_id_for_party/1,
create_payout/1,
get_payout/1,
create_payout_autorization_error/1,
create_webhook_ok_test/1,
create_webhook_limit_exceeded_test/1,
get_webhooks/1,
@ -106,14 +98,9 @@
delete_webhook_by_id/1,
get_categories_ok_test/1,
get_category_by_ref_ok_test/1,
get_schedule_by_ref_ok_test/1,
get_payment_institutions/1,
get_payment_institution_by_ref/1,
get_payment_institution_payment_terms/1,
get_payment_institution_payout_terms/1,
get_payment_institution_payout_terms_for_party/1,
get_payment_institution_payout_schedules/1,
get_payment_institution_payout_schedules_for_party/1,
get_service_provider_by_id/1,
check_no_payment_by_external_id_test/1,
check_no_internal_id_for_external_id_test/1,
@ -241,14 +228,9 @@ groups() ->
get_payment_institutions,
get_payment_institution_by_ref,
get_payment_institution_payment_terms,
get_payment_institution_payout_terms,
get_payment_institution_payout_terms_for_party,
get_payment_institution_payout_schedules,
get_payment_institution_payout_schedules_for_party,
get_service_provider_by_id,
get_category_by_ref_ok_test,
get_schedule_by_ref_ok_test,
get_country_by_id_test,
get_country_by_id_not_found_test,
get_countries_test,
@ -263,14 +245,6 @@ groups() ->
get_webhook_by_id,
delete_webhook_by_id,
get_payout_tools_ok_test,
get_payout_tools_for_party_ok_test,
get_payout_tool_by_id,
get_payout_tool_by_id_for_party,
create_payout,
create_payout_autorization_error,
get_payout,
different_ip_header
]}
].
@ -1641,106 +1615,6 @@ get_contract_adjustment_by_id_for_party_ok_test(Config) ->
?STRING
).
-spec get_payout_tools_ok_test(config()) -> _.
get_payout_tools_ok_test(Config) ->
_ = capi_ct_helper:mock_services([{party_management, fun('GetContract', _) -> {ok, ?CONTRACT} end}], Config),
_ = capi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetPayoutTools">>, ?STRING, Config),
{ok, _} = capi_client_payouts:get_payout_tools(?config(context, Config), ?STRING).
-spec get_payout_tools_for_party_ok_test(config()) -> _.
get_payout_tools_for_party_ok_test(Config) ->
_ = capi_ct_helper:mock_services([{party_management, fun('GetContract', _) -> {ok, ?CONTRACT} end}], Config),
_ = capi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetPayoutToolsForParty">>, ?STRING, Config),
{ok, _} = capi_client_payouts:get_payout_tools_for_party(?config(context, Config), ?STRING, ?STRING).
-spec get_payout_tool_by_id(config()) -> _.
get_payout_tool_by_id(Config) ->
_ = capi_ct_helper:mock_services([{party_management, fun('GetContract', _) -> {ok, ?CONTRACT} end}], Config),
_ = capi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetPayoutToolByID">>, ?STRING, Config),
{ok, _} = capi_client_payouts:get_payout_tool_by_id(?config(context, Config), ?STRING, ?BANKID_RU),
{ok, _} = capi_client_payouts:get_payout_tool_by_id(?config(context, Config), ?STRING, ?BANKID_US),
{ok, _} = capi_client_payouts:get_payout_tool_by_id(?config(context, Config), ?STRING, ?WALLET_TOOL),
{ok, _} = capi_client_payouts:get_payout_tool_by_id(?config(context, Config), ?STRING, ?PI_ACCOUNT_TOOL).
-spec get_payout_tool_by_id_for_party(config()) -> _.
get_payout_tool_by_id_for_party(Config) ->
_ = capi_ct_helper:mock_services([{party_management, fun('GetContract', _) -> {ok, ?CONTRACT} end}], Config),
_ = capi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetPayoutToolByIDForParty">>, ?STRING, Config),
{ok, _} = capi_client_payouts:get_payout_tool_by_id_for_party(
?config(context, Config),
?STRING,
?STRING,
?WALLET_TOOL
),
{ok, _} = capi_client_payouts:get_payout_tool_by_id_for_party(
?config(context, Config),
?STRING,
?STRING,
?PI_ACCOUNT_TOOL
).
-spec create_payout(config()) -> _.
create_payout(Config) ->
Payout = ?PAYOUT(?WALLET_TOOL),
_ = capi_ct_helper:mock_services(
[
{payouts, fun('CreatePayout', _) -> {ok, Payout} end},
{party_management, fun
('GetShop', _) -> {ok, ?SHOP};
('GetContract', _) -> {ok, ?CONTRACT}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_shop_op_ctx(<<"CreatePayout">>, ?STRING, ?STRING, Config),
{ok, _} = capi_client_payouts:create_payout(?config(context, Config), ?PAYOUT_PARAMS, ?STRING).
-spec create_payout_autorization_error(config()) -> _.
create_payout_autorization_error(Config) ->
Payout = ?PAYOUT(?WALLET_TOOL),
_ = capi_ct_helper:mock_services(
[
{payouts, fun('CreatePayout', _) -> {ok, Payout} end},
{party_management, fun
('GetShop', _) -> {ok, ?SHOP};
('GetContract', _) -> {ok, ?CONTRACT}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_arbiter(capi_ct_helper_bouncer:judge_always_forbidden(), Config),
?assertMatch(
{error, {401, _}},
capi_client_payouts:create_payout(
?config(context, Config),
?PAYOUT_PARAMS#{<<"partyID">> => <<"WrongPartyID">>},
?STRING
)
).
-spec get_payout(config()) -> _.
get_payout(Config) ->
Payout = ?PAYOUT(?WALLET_TOOL),
_ = capi_ct_helper:mock_services(
[
{payouts, fun('GetPayout', _) -> {ok, Payout} end},
{party_management, fun
('GetShop', _) -> {ok, ?SHOP};
('GetContract', _) -> {ok, ?CONTRACT}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_payout_op_ctx(
<<"GetPayout">>,
?STRING,
?STRING,
?STRING,
?STRING,
Config
),
{ok, _} = capi_client_payouts:get_payout(?config(context, Config), ?STRING).
-spec create_webhook_ok_test(config()) -> _.
create_webhook_ok_test(Config) ->
_ = capi_ct_helper:mock_services(
@ -1865,11 +1739,6 @@ get_category_by_ref_ok_test(Config) ->
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetCategoryByRef">>, Config),
{ok, _} = capi_client_categories:get_category_by_ref(?config(context, Config), ?INTEGER).
-spec get_schedule_by_ref_ok_test(config()) -> _.
get_schedule_by_ref_ok_test(Config) ->
_ = capi_ct_helper_bouncer:mock_arbiter(capi_ct_helper_bouncer:judge_always_allowed(), Config),
{ok, _} = capi_client_payouts:get_schedule_by_ref(?config(context, Config), ?INTEGER).
-spec check_no_payment_by_external_id_test(config()) -> _.
check_no_payment_by_external_id_test(Config) ->
ExternalID = capi_utils:get_unique_id(),
@ -2074,74 +1943,6 @@ get_payment_institution_payment_terms(Config) ->
{ok, _} =
capi_client_payment_institutions:get_payment_institution_payment_terms(?config(context, Config), ?INTEGER).
-spec get_payment_institution_payout_terms(config()) -> _.
get_payment_institution_payout_terms(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutMethods">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_methods(
?config(context, Config),
?INTEGER,
<<"RUB">>
).
-spec get_payment_institution_payout_terms_for_party(config()) -> _.
get_payment_institution_payout_terms_for_party(Config) ->
PartyID = capi_utils:get_unique_id(),
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutMethodsForParty">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_methods_for_party(
?config(context, Config),
PartyID,
?INTEGER,
<<"RUB">>
).
-spec get_payment_institution_payout_schedules(config()) -> _.
get_payment_institution_payout_schedules(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutSchedules">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_schedules(
?config(context, Config),
?INTEGER,
<<"USD">>,
<<"BankAccount">>
).
-spec get_payment_institution_payout_schedules_for_party(config()) -> _.
get_payment_institution_payout_schedules_for_party(Config) ->
PartyID = capi_utils:get_unique_id(),
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutSchedulesForParty">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_schedules_for_party(
?config(context, Config),
PartyID,
?INTEGER,
<<"USD">>,
<<"BankAccount">>
).
-spec get_service_provider_by_id(config()) -> _.
get_service_provider_by_id(Config) ->
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetServiceProviderByID">>, Config),

View File

@ -93,11 +93,6 @@
webhook = ?CTX_ENTITY(WebhookID)
}).
-define(CTX_PAYOUT_OP(ID, PayoutID), #ctx_v1_CommonAPIOperation{
id = ID,
payout = ?CTX_ENTITY(PayoutID)
}).
-define(CTX_SEARCH_OP(ID, PartyID, ShopID, InvoiceID, PaymentID),
?CTX_SEARCH_OP(
ID,

View File

@ -14,7 +14,6 @@
-export([mock_assert_invoice_tpl_op_ctx/5]).
-export([mock_assert_customer_op_ctx/5]).
-export([mock_assert_webhook_op_ctx/4]).
-export([mock_assert_payout_op_ctx/6]).
-export([mock_assert_search_op_ctx/2]).
-export([mock_assert_search_op_ctx/3]).
-export([mock_assert_requester_ctx/2]).
@ -169,20 +168,6 @@ mock_assert_webhook_op_ctx(Op, WebhookID, PartyID, Config) ->
Config
).
-spec mock_assert_payout_op_ctx(_, _, _, _, _, _) -> _.
mock_assert_payout_op_ctx(Op, PayoutID, PartyID, ContractID, ShopID, Config) ->
mock_arbiter(
?assertContextMatches(
#ctx_v1_ContextFragment{
capi = ?CTX_CAPI(?CTX_PAYOUT_OP(Op, PayoutID)),
payouts = #ctx_v1_ContextPayouts{
payout = ?CTX_PAYOUT(PayoutID, PartyID, ContractID, ShopID)
}
}
),
Config
).
-spec mock_assert_search_op_ctx(_, _) -> _.
mock_assert_search_op_ctx(SearchCtx, Config) ->
mock_arbiter(

View File

@ -4,12 +4,6 @@
-export([get_payment_institutions/3]).
-export([get_payment_institution_by_ref/2]).
-export([get_payment_institution_payment_terms/2]).
-export([get_payment_institution_payout_methods/2]).
-export([get_payment_institution_payout_methods/3]).
-export([get_payment_institution_payout_methods_for_party/4]).
-export([get_payment_institution_payout_schedules/2]).
-export([get_payment_institution_payout_schedules/4]).
-export([get_payment_institution_payout_schedules_for_party/5]).
-export([get_service_provider_by_id/2]).
-type context() :: capi_client_lib:context().
@ -54,80 +48,6 @@ get_payment_institution_payment_terms(Context, PaymentInstitutionID) ->
Response = swag_client_payment_institutions_api:get_payment_institution_payment_terms(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_methods(context(), term()) -> {ok, term()} | {error, term()}.
get_payment_institution_payout_methods(Context, PaymentInstitutionID) ->
get_payment_institution_payout_methods(Context, PaymentInstitutionID, undefined).
-spec get_payment_institution_payout_methods(context(), term(), term()) -> {ok, term()} | {error, term()}.
get_payment_institution_payout_methods(Context, PaymentInstitutionID, Currency) ->
Params = #{
binding => #{
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
currency => Currency
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_methods(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_methods_for_party(context(), binary(), term(), term()) ->
{ok, term()} | {error, term()}.
get_payment_institution_payout_methods_for_party(Context, PartyID, PaymentInstitutionID, Currency) ->
Params = #{
binding => #{
<<"partyID">> => PartyID,
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
currency => Currency
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_methods_for_party(
Url, PreparedParams, Opts
),
capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_schedules(context(), term()) -> {ok, term()} | {error, term()}.
get_payment_institution_payout_schedules(Context, PaymentInstitutionID) ->
get_payment_institution_payout_schedules(Context, PaymentInstitutionID, undefined, undefined).
-spec get_payment_institution_payout_schedules(context(), term(), term(), term()) -> {ok, term()} | {error, term()}.
get_payment_institution_payout_schedules(Context, PaymentInstitutionID, Currency, Method) ->
Params = #{
binding => #{
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
'currency' => Currency,
'payoutMethod' => Method
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_schedules(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_schedules_for_party(context(), binary(), term(), term(), term()) ->
{ok, term()} | {error, term()}.
get_payment_institution_payout_schedules_for_party(Context, PartyID, PaymentInstitutionID, Currency, Method) ->
Params = #{
binding => #{
<<"partyID">> => PartyID,
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
'currency' => Currency,
'payoutMethod' => Method
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_schedules_for_party(
Url, PreparedParams, Opts
),
capi_client_lib:handle_response(Response).
-spec get_service_provider_by_id(context(), binary()) -> {ok, term()} | {error, term()}.
get_service_provider_by_id(Context, ServiceProviderID) ->
Params = #{

View File

@ -1,93 +0,0 @@
-module(capi_client_payouts).
-export([get_payout_tools/2]).
-export([get_payout_tools_for_party/3]).
-export([get_payout_tool_by_id/3]).
-export([get_payout_tool_by_id_for_party/4]).
-export([get_schedule_by_ref/2]).
-export([create_payout/3]).
-export([get_payout/2]).
-type context() :: capi_client_lib:context().
-spec get_payout_tools(context(), binary()) -> {ok, term()} | {error, term()}.
get_payout_tools(Context, ContractID) ->
Params = #{
binding => genlib_map:compact(#{
<<"contractID">> => ContractID
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_payout_tools(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payout_tools_for_party(context(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_payout_tools_for_party(Context, PartyID, ContractID) ->
Params = #{
binding => genlib_map:compact(#{
<<"partyID">> => PartyID,
<<"contractID">> => ContractID
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_payout_tools_for_party(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payout_tool_by_id(context(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_payout_tool_by_id(Context, ContractID, PayoutToolID) ->
Params = #{
binding => genlib_map:compact(#{
<<"contractID">> => ContractID,
<<"payoutToolID">> => PayoutToolID
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_payout_tool_by_id(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payout_tool_by_id_for_party(context(), binary(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_payout_tool_by_id_for_party(Context, PartyID, ContractID, PayoutToolID) ->
Params = #{
binding => genlib_map:compact(#{
<<"partyID">> => PartyID,
<<"contractID">> => ContractID,
<<"payoutToolID">> => PayoutToolID
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_payout_tool_by_id_for_party(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_schedule_by_ref(context(), term()) -> {ok, term()} | {error, term()}.
get_schedule_by_ref(Context, ScheduleRef) ->
Params = #{
binding => #{
<<"scheduleID">> => genlib:to_list(ScheduleRef)
}
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_schedule_by_ref(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec create_payout(context(), map(), binary()) -> {ok, term()} | {error, term()}.
create_payout(Context, Request, PayoutID) ->
Params = #{
binding => #{
<<"payoutID">> => PayoutID
},
body => Request
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:create_payout(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec get_payout(context(), binary()) -> {ok, term()} | {error, term()}.
get_payout(Context, PayoutID) ->
Params = #{
binding => #{
<<"payoutID">> => PayoutID
}
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payouts_api:get_payout(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).

View File

@ -79,8 +79,6 @@ get_service_modname(invoice_templating) ->
{dmsl_payproc_thrift, 'InvoiceTemplating'};
get_service_modname(magista) ->
{magista_magista_thrift, 'MerchantStatisticsService'};
get_service_modname(payouts) ->
{payouts_payout_manager_thrift, 'PayoutManagement'};
get_service_modname(webhook_manager) ->
{dmsl_webhooker_thrift, 'WebhookManager'};
get_service_modname(customer_management) ->

View File

@ -14,7 +14,7 @@
0},
{<<"bouncer_proto">>,
{git,"https://github.com/valitydev/bouncer-proto.git",
{ref,"b23c905db51915737fdab80c2a3af4c546b32799"}},
{ref,"07dcc7b9b4599923b20bcf5f84642c3a1d6570e2"}},
0},
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.6.1">>},2},
@ -40,7 +40,7 @@
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"c170117e5fde4ebdc6878e75dcd37ca2779dfb82"}},
{ref,"e5d3c83a240ba716348c6fbd816ea8e4d864472f"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",
@ -134,11 +134,11 @@
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.7">>},2},
{<<"swag_client">>,
{git,"https://github.com/valitydev/swag-payments",
{ref,"17fb90d8eb2ea21a4bfc6c38d290745529d94144"}},
{ref,"400015842b1a53a93dd1ea298914510a13a66f5d"}},
0},
{<<"swag_server">>,
{git,"https://github.com/valitydev/swag-payments",
{ref,"bffc256b326fccb1233d84a89e3527d016afe3c2"}},
{ref,"79a46abf70bbf72394baa5dc14bafcc51d71fbd9"}},
0},
{<<"thrift">>,
{git,"https://github.com/valitydev/thrift_erlang.git",