Skip to content

Commit

Permalink
IMP-250: Remove payout (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
WWWcool authored Jul 2, 2024
1 parent 2477bfb commit 89759bf
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 845 deletions.
1 change: 0 additions & 1 deletion apps/capi/src/capi.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
bouncer_client,
token_keeper_client,
party_client,
payout_manager_proto,
magista_proto,
opentelemetry_api,
opentelemetry_exporter,
Expand Down
49 changes: 2 additions & 47 deletions apps/capi/src/capi_bouncer_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -20,7 +19,6 @@
-type prototypes() :: [
{operation, prototype_operation()}
| {payproc, prototype_payproc()}
| {payouts, prototype_payouts()}
| {webhooks, prototype_webhooks()}
].

Expand All @@ -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() :: #{
Expand All @@ -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
}.
Expand All @@ -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]).
Expand Down Expand Up @@ -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)
}
}
};
Expand Down Expand Up @@ -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
}
}.

%%
Expand Down Expand Up @@ -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) ->
Expand Down
1 change: 0 additions & 1 deletion apps/capi/src/capi_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 0 additions & 42 deletions apps/capi/src/capi_handler_decoder_party.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).

%%

Expand Down Expand Up @@ -176,51 +175,10 @@ 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,
<<"bankName">> => BankAccount#domain_RussianBankAccount.bank_name,
<<"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
}).
80 changes: 0 additions & 80 deletions apps/capi/src/capi_handler_payment_institutions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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() ->
Expand Down Expand Up @@ -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}) ->
Expand Down Expand Up @@ -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{}) ->
Expand Down
Loading

0 comments on commit 89759bf

Please sign in to comment.