* Drop account-related handlers as per valitydev/swag-payments@777d37a
* Bump to valitydev/bouncer-client-erlang@b6c7be0
* Drop unnecessary exception handling
* Drop unused utility functions
This commit is contained in:
Andrew Mayorov 2022-03-26 17:40:19 +03:00 committed by GitHub
parent 67d1ef1f2c
commit 7d6a034f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 124 deletions

View File

@ -97,7 +97,6 @@ map_error(validation_error, Error) ->
get_handlers() ->
[
capi_handler_accounts,
capi_handler_analytics,
capi_handler_categories,
capi_handler_claims,

View File

@ -1,43 +0,0 @@
-module(capi_handler_accounts).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-behaviour(capi_handler).
-export([prepare/3]).
-import(capi_handler_utils, [general_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, Req, Context) when OperationID =:= 'GetAccountByID' ->
PartyID = capi_handler_utils:get_party_id(Context),
Authorize = fun() ->
Prototypes = [{operation, #{id => OperationID, party => PartyID}}],
{ok, capi_auth:authorize_operation(Prototypes, Context)}
end,
Process = fun() ->
AccountID = genlib:to_int(maps:get('accountID', Req)),
case capi_party:get_account_state(PartyID, AccountID, Context) of
{ok, S} ->
{ok, {200, #{}, decode_account_state(S)}};
{error, #payproc_AccountNotFound{}} ->
{ok, general_error(404, <<"Account not found">>)}
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(_OperationID, _Req, _Context) ->
{error, noimpl}.
%%
decode_account_state(AccountState) ->
#{
<<"id">> => AccountState#payproc_AccountState.account_id,
<<"ownAmount">> => AccountState#payproc_AccountState.own_amount,
<<"availableAmount">> => AccountState#payproc_AccountState.available_amount,
<<"currency">> => capi_handler_decoder_utils:decode_currency(AccountState#payproc_AccountState.currency)
}.

View File

@ -176,15 +176,5 @@ decode_shop(Shop) ->
<<"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),
<<"account">> => decode_shop_account(Shop#domain_Shop.account)
<<"scheduleID">> => capi_handler_decoder_utils:decode_business_schedule_ref(Shop#domain_Shop.payout_schedule)
}).
decode_shop_account(undefined) ->
undefined;
decode_shop_account(#domain_ShopAccount{currency = Currency, settlement = SettlementID, guarantee = GuaranteeID}) ->
#{
<<"guaranteeID">> => GuaranteeID,
<<"settlementID">> => SettlementID,
<<"currency">> => capi_handler_decoder_utils:decode_currency(Currency)
}.

View File

@ -15,7 +15,6 @@
-export([revoke_claim/5]).
-export([get_claim/3]).
-export([get_claims/2]).
-export([get_account_state/3]).
-type result() :: ok | {ok, woody:result()} | {error, woody_error:business_error()}.
-type processing_context() :: capi_handler:processing_context().
@ -31,7 +30,6 @@
-type claim_revision() :: party_client_thrift:claim_revision().
-type changeset() :: party_client_thrift:changeset().
-type revoke_reason() :: party_client_thrift:revoke_reason().
-type account_id() :: party_client_thrift:account_id().
-spec create_party(party_id(), party_params(), processing_context()) -> result().
create_party(PartyID, PartyParams, Context) ->
@ -130,10 +128,5 @@ get_claims(PartyID, Context) ->
{Client, ClientContext} = client_context(Context),
party_client_thrift:get_claims(PartyID, Client, ClientContext).
-spec get_account_state(party_id(), account_id(), processing_context()) -> result().
get_account_state(PartyID, AccountID, Context) ->
{Client, ClientContext} = client_context(Context),
party_client_thrift:get_account_state(PartyID, AccountID, Client, ClientContext).
client_context(#{party_client := Client, party_client_context := ClientContext}) ->
{Client, ClientContext}.

View File

@ -19,7 +19,6 @@
-export([redact/2]).
-export([unwrap/1]).
-export([define/2]).
-export([deduplicate_payment_methods/1]).
@ -52,24 +51,12 @@ deadline_is_reached(Deadline) ->
-spec base64url_to_map(binary()) -> map() | no_return().
base64url_to_map(Base64) when is_binary(Base64) ->
try
{ok, Json} = jose_base64url:decode(Base64),
jsx:decode(Json, [return_maps])
catch
Class:Reason ->
_ = logger:debug("decoding base64 ~p to map failed with ~p:~p", [Base64, Class, Reason]),
erlang:error(badarg)
end.
Json = jose_base64url:'decode!'(Base64),
jsx:decode(Json, [return_maps]).
-spec map_to_base64url(map()) -> binary() | no_return().
map_to_base64url(Map) when is_map(Map) ->
try
jose_base64url:encode(jsx:encode(Map))
catch
Class:Reason ->
_ = logger:debug("encoding map ~p to base64 failed with ~p:~p", [Map, Class, Reason]),
erlang:error(badarg)
end.
jose_base64url:encode(jsx:encode(Map)).
-spec redact(Subject :: binary(), Pattern :: binary()) -> Redacted :: binary().
redact(Subject, Pattern) ->
@ -99,17 +86,7 @@ unwrap({ok, Value}) ->
unwrap({error, Error}) ->
erlang:error({unwrap_error, Error}).
-spec define(undefined | T, T) -> T.
define(undefined, V) ->
V;
define(V, _Default) ->
V.
-spec parse_deadline
(binary()) -> {ok, woody:deadline()} | {error, bad_deadline};
(undefined) -> {ok, undefined}.
parse_deadline(undefined) ->
{ok, undefined};
-spec parse_deadline(binary()) -> {ok, woody:deadline()} | {error, bad_deadline}.
parse_deadline(DeadlineStr) ->
Parsers = [
fun try_parse_woody_default/1,

View File

@ -50,7 +50,6 @@
get_refund_by_external_id/1,
update_invoice_template_ok_test/1,
delete_invoice_template_ok_test/1,
get_account_by_id_ok_test/1,
get_my_party_ok_test/1,
get_my_party_lazy_creation_ok_test/1,
get_my_party_lazy_creation_fail_test/1,
@ -198,7 +197,6 @@ groups() ->
activate_shop_ok_test,
suspend_shop_ok_test,
get_account_by_id_ok_test,
get_categories_ok_test,
get_claim_by_id_ok_test,
@ -1056,15 +1054,6 @@ delete_invoice_template_ok_test(Config) ->
),
ok = capi_client_invoice_templates:delete(?config(context, Config), ?STRING).
-spec get_account_by_id_ok_test(config()) -> _.
get_account_by_id_ok_test(Config) ->
_ = capi_ct_helper:mock_services(
[{party_management, fun('GetAccountState', _) -> {ok, ?ACCOUNT_STATE} end}],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_party_op_ctx(<<"GetAccountByID">>, ?STRING, Config),
{ok, _} = capi_client_accounts:get_account_by_id(?config(context, Config), ?INTEGER).
-spec get_my_party_ok_test(config()) -> _.
get_my_party_ok_test(Config) ->
_ = capi_ct_helper:mock_services(

View File

@ -1,16 +0,0 @@
-module(capi_client_accounts).
-export([get_account_by_id/2]).
-type context() :: capi_client_lib:context().
-spec get_account_by_id(context(), integer()) -> {ok, term()} | {error, term()}.
get_account_by_id(Context, AccountID) ->
Params = #{
binding => #{
<<"accountID">> => AccountID
}
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_accounts_api:get_account_by_id(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).

View File

@ -46,7 +46,7 @@
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, master}}},
{lechiffre, {git, "https://github.com/valitydev/lechiffre.git", {branch, master}}},
{bouncer_proto, {git, "https://github.com/valitydev/bouncer-proto.git", {branch, master}}},
{bouncer_client, {git, "https://github.com/valitydev/bouncer_client_erlang.git", {branch, master}}},
{bouncer_client, {git, "https://github.com/valitydev/bouncer-client-erlang.git", {branch, master}}},
{token_keeper_client, {git, "https://github.com/valitydev/token-keeper-client.git", {branch, master}}},
{party_client, {git, "https://github.com/valitydev/party_client_erlang.git", {branch, master}}},
{payout_manager_proto, {git, "https://github.com/valitydev/payout-manager-proto.git", {branch, master}}},

View File

@ -8,8 +8,8 @@
{ref,"e08deadaab22019ff50a5d96ca6befff0034dab3"}},
0},
{<<"bouncer_client">>,
{git,"https://github.com/valitydev/bouncer_client_erlang.git",
{ref,"535449a459b70643836c440a863b42656f2a1409"}},
{git,"https://github.com/valitydev/bouncer-client-erlang.git",
{ref,"b6c7be05e24f46121f42ae5a48232b94f78c9c5c"}},
0},
{<<"bouncer_proto">>,
{git,"https://github.com/valitydev/bouncer-proto.git",
@ -69,7 +69,7 @@
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
{<<"jesse">>,
{git,"https://github.com/valitydev/jesse.git",
{ref,"9b980b7f9ce09b6a136fe5a23d404d1b903f3061"}},
{ref,"f4ff58e79ebe65650f9c445e730ad4c8d7f463a0"}},
1},
{<<"jose">>,
{git,"https://github.com/potatosalad/erlang-jose.git",
@ -87,8 +87,8 @@
{ref,"ec15d5e854ea60c58467373077d90c2faf6273d8"}},
1},
{<<"org_management_proto">>,
{git,"https://github.com/valitydev/org-management-proto.git",
{ref,"06c5c8430e445cb7874e54358e457cbb5697fc32"}},
{git,"https://github.com/valitydev/org-management-proto",
{ref,"f433223706284000694e54e839fafb10db84e2b3"}},
1},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.4.1">>},1},
{<<"party_client">>,
@ -119,11 +119,11 @@
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},2},
{<<"swag_client">>,
{git,"https://github.com/valitydev/swag-payments",
{ref,"d42fe53131e605b86a6fafd731c8d17275a2d1c3"}},
{ref,"03520bda80db540cfe2f431bc035e9c9c165fb99"}},
0},
{<<"swag_server">>,
{git,"https://github.com/valitydev/swag-payments",
{ref,"d66adf6f04071cf587ae1d11c6d3502fbe5fe0af"}},
{ref,"347f081b2823c17c390fcedefb58bad9de35034f"}},
0},
{<<"thrift">>,
{git,"https://github.com/valitydev/thrift_erlang.git",