mirror of
https://github.com/valitydev/capi-v2.git
synced 2024-11-06 10:05:21 +00:00
parent
de2cfef0d3
commit
d62050f351
@ -219,16 +219,22 @@ get_operation_access('GetPaymentRateStats', _) ->
|
||||
[{[party], read}];
|
||||
get_operation_access('GetPaymentMethodStats', _) ->
|
||||
[{[party], read}];
|
||||
get_operation_access('GetMyParty', _) ->
|
||||
[{[party], read}];
|
||||
get_operation_access('ActivateShop', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('SuspendShop', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('GetMyParty', _) ->
|
||||
[{[party], read}];
|
||||
get_operation_access('SuspendMyParty', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('ActivateMyParty', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('GetPartyByID', _) ->
|
||||
[{[party], read}];
|
||||
get_operation_access('SuspendPartyByID', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('ActivatePartyByID', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('CreateClaim', _) ->
|
||||
[{[party], write}];
|
||||
get_operation_access('GetClaims', _) ->
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
-export([prepare/3]).
|
||||
|
||||
-import(capi_handler_utils, [logic_error/2]).
|
||||
-import(capi_handler_utils, [general_error/2, logic_error/2]).
|
||||
|
||||
-type processing_context() :: capi_handler:processing_context().
|
||||
|
||||
@ -22,7 +22,7 @@ prepare('GetMyParty' = OperationID, Req, Context) ->
|
||||
{ok, capi_auth:authorize_operation(OperationID, Prototypes, Context, Req)}
|
||||
end,
|
||||
Process = fun() ->
|
||||
case get_party(PartyID, Context) of
|
||||
case get_or_create_party(PartyID, Context) of
|
||||
{ok, Party} ->
|
||||
DecodedParty = capi_handler_decoder_party:decode_party(Party),
|
||||
{ok, {200, #{}, DecodedParty}};
|
||||
@ -73,13 +73,71 @@ prepare('SuspendMyParty' = OperationID, Req, Context) ->
|
||||
end
|
||||
end,
|
||||
{ok, #{authorize => Authorize, process => Process}};
|
||||
prepare('GetPartyByID' = OperationID, Req, Context) ->
|
||||
PartyID = maps:get(partyID, Req),
|
||||
Authorize = fun() ->
|
||||
Prototypes = [{operation, #{id => OperationID, party => PartyID}}],
|
||||
{ok, capi_auth:authorize_operation(OperationID, Prototypes, Context, Req)}
|
||||
end,
|
||||
Process = fun() ->
|
||||
case capi_handler_utils:get_party(PartyID, Context) of
|
||||
{ok, Party} ->
|
||||
DecodedParty = capi_handler_decoder_party:decode_party(Party),
|
||||
{ok, {200, #{}, DecodedParty}};
|
||||
{exception, #payproc_InvalidUser{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)};
|
||||
{exception, #payproc_PartyNotFound{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)}
|
||||
end
|
||||
end,
|
||||
{ok, #{authorize => Authorize, process => Process}};
|
||||
prepare('ActivatePartyByID' = OperationID, Req, Context) ->
|
||||
PartyID = maps:get(partyID, Req),
|
||||
Authorize = fun() ->
|
||||
Prototypes = [{operation, #{id => OperationID, party => PartyID}}],
|
||||
{ok, capi_auth:authorize_operation(OperationID, Prototypes, Context, Req)}
|
||||
end,
|
||||
Process = fun() ->
|
||||
Call = {party_management, 'Activate', {PartyID}},
|
||||
case capi_handler_utils:service_call_with([user_info], Call, Context) of
|
||||
{ok, _R} ->
|
||||
{ok, {204, #{}, undefined}};
|
||||
{exception, #payproc_InvalidUser{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)};
|
||||
{exception, #payproc_PartyNotFound{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)};
|
||||
{exception, #payproc_InvalidPartyStatus{status = {suspension, {active, _}}}} ->
|
||||
{ok, logic_error(<<"invalidRequest">>, <<"Invalid party status">>)}
|
||||
end
|
||||
end,
|
||||
{ok, #{authorize => Authorize, process => Process}};
|
||||
prepare('SuspendPartyByID' = OperationID, Req, Context) ->
|
||||
PartyID = maps:get(partyID, Req),
|
||||
Authorize = fun() ->
|
||||
Prototypes = [{operation, #{id => OperationID, party => PartyID}}],
|
||||
{ok, capi_auth:authorize_operation(OperationID, Prototypes, Context, Req)}
|
||||
end,
|
||||
Process = fun() ->
|
||||
Call = {party_management, 'Suspend', {PartyID}},
|
||||
case capi_handler_utils:service_call_with([user_info], Call, Context) of
|
||||
{ok, _R} ->
|
||||
{ok, {204, #{}, undefined}};
|
||||
{exception, #payproc_InvalidUser{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)};
|
||||
{exception, #payproc_PartyNotFound{}} ->
|
||||
{ok, general_error(404, <<"Party not found">>)};
|
||||
{exception, #payproc_InvalidPartyStatus{status = {suspension, {suspended, _}}}} ->
|
||||
{ok, logic_error(<<"invalidRequest">>, <<"Invalid party status">>)}
|
||||
end
|
||||
end,
|
||||
{ok, #{authorize => Authorize, process => Process}};
|
||||
prepare(_OperationID, _Req, _Context) ->
|
||||
{error, noimpl}.
|
||||
|
||||
%%
|
||||
|
||||
-spec get_party(binary(), processing_context()) -> woody:result().
|
||||
get_party(PartyID, Context) ->
|
||||
-spec get_or_create_party(binary(), processing_context()) -> woody:result().
|
||||
get_or_create_party(PartyID, Context) ->
|
||||
case capi_handler_utils:get_party(PartyID, Context) of
|
||||
{exception, #payproc_PartyNotFound{}} ->
|
||||
_ = logger:info("Attempting to create a missing party"),
|
||||
|
@ -56,6 +56,9 @@
|
||||
get_my_party_ok_test/1,
|
||||
suspend_my_party_ok_test/1,
|
||||
activate_my_party_ok_test/1,
|
||||
get_party_by_id_ok_test/1,
|
||||
suspend_party_by_id_ok_test/1,
|
||||
activate_party_by_id_ok_test/1,
|
||||
get_shop_by_id_ok_test/1,
|
||||
get_shops_ok_test/1,
|
||||
activate_shop_ok_test/1,
|
||||
@ -226,6 +229,10 @@ groups() ->
|
||||
suspend_my_party_ok_test,
|
||||
activate_my_party_ok_test,
|
||||
|
||||
get_party_by_id_ok_test,
|
||||
suspend_party_by_id_ok_test,
|
||||
activate_party_by_id_ok_test,
|
||||
|
||||
get_locations_names_ok_test,
|
||||
|
||||
get_account_by_id_ok_test,
|
||||
@ -826,6 +833,24 @@ activate_my_party_ok_test(Config) ->
|
||||
_ = capi_ct_helper_bouncer:mock_bouncer_assert_party_op_ctx(<<"ActivateMyParty">>, ?STRING, Config),
|
||||
ok = capi_client_parties:activate_my_party(?config(context, Config)).
|
||||
|
||||
-spec get_party_by_id_ok_test(config()) -> _.
|
||||
get_party_by_id_ok_test(Config) ->
|
||||
_ = capi_ct_helper:mock_services([{party_management, fun('Get', _) -> {ok, ?PARTY} end}], Config),
|
||||
_ = capi_ct_helper_bouncer:mock_bouncer_assert_party_op_ctx(<<"GetPartyByID">>, ?STRING, Config),
|
||||
{ok, _} = capi_client_parties:get_party_by_id(?config(context, Config), ?STRING).
|
||||
|
||||
-spec suspend_party_by_id_ok_test(config()) -> _.
|
||||
suspend_party_by_id_ok_test(Config) ->
|
||||
_ = capi_ct_helper:mock_services([{party_management, fun('Suspend', _) -> {ok, ok} end}], Config),
|
||||
_ = capi_ct_helper_bouncer:mock_bouncer_assert_party_op_ctx(<<"SuspendPartyByID">>, ?STRING, Config),
|
||||
ok = capi_client_parties:suspend_party_by_id(?config(context, Config), ?STRING).
|
||||
|
||||
-spec activate_party_by_id_ok_test(config()) -> _.
|
||||
activate_party_by_id_ok_test(Config) ->
|
||||
_ = capi_ct_helper:mock_services([{party_management, fun('Activate', _) -> {ok, ok} end}], Config),
|
||||
_ = capi_ct_helper_bouncer:mock_bouncer_assert_party_op_ctx(<<"ActivatePartyByID">>, ?STRING, Config),
|
||||
ok = capi_client_parties:activate_party_by_id(?config(context, Config), ?STRING).
|
||||
|
||||
-spec get_shop_by_id_ok_test(config()) -> _.
|
||||
get_shop_by_id_ok_test(Config) ->
|
||||
_ = capi_ct_helper:mock_services([{party_management, fun('GetShop', _) -> {ok, ?SHOP} end}], Config),
|
||||
|
@ -3,6 +3,9 @@
|
||||
-export([get_my_party/1]).
|
||||
-export([suspend_my_party/1]).
|
||||
-export([activate_my_party/1]).
|
||||
-export([get_party_by_id/2]).
|
||||
-export([suspend_party_by_id/2]).
|
||||
-export([activate_party_by_id/2]).
|
||||
|
||||
-type context() :: capi_client_lib:context().
|
||||
|
||||
@ -29,3 +32,42 @@ activate_my_party(Context) ->
|
||||
{ok, undefined} -> ok;
|
||||
{error, Error} -> {error, Error}
|
||||
end.
|
||||
|
||||
-spec get_party_by_id(context(), binary()) -> {ok, term()} | {error, term()}.
|
||||
get_party_by_id(Context, PartyID) ->
|
||||
Params = #{
|
||||
binding => #{
|
||||
<<"partyID">> => PartyID
|
||||
}
|
||||
},
|
||||
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
|
||||
Response = swag_client_parties_api:get_party_by_id(Url, PreparedParams, Opts),
|
||||
capi_client_lib:handle_response(Response).
|
||||
|
||||
-spec suspend_party_by_id(context(), binary()) -> ok | {error, term()}.
|
||||
suspend_party_by_id(Context, PartyID) ->
|
||||
Params = #{
|
||||
binding => #{
|
||||
<<"partyID">> => PartyID
|
||||
}
|
||||
},
|
||||
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
|
||||
Response = swag_client_parties_api:suspend_party_by_id(Url, PreparedParams, Opts),
|
||||
case capi_client_lib:handle_response(Response) of
|
||||
{ok, undefined} -> ok;
|
||||
{error, Error} -> {error, Error}
|
||||
end.
|
||||
|
||||
-spec activate_party_by_id(context(), binary()) -> ok | {error, term()}.
|
||||
activate_party_by_id(Context, PartyID) ->
|
||||
Params = #{
|
||||
binding => #{
|
||||
<<"partyID">> => PartyID
|
||||
}
|
||||
},
|
||||
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
|
||||
Response = swag_client_parties_api:activate_party_by_id(Url, PreparedParams, Opts),
|
||||
case capi_client_lib:handle_response(Response) of
|
||||
{ok, undefined} -> ok;
|
||||
{error, Error} -> {error, Error}
|
||||
end.
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6666a375574ce1399c5b865344281247194cb5ab
|
||||
Subproject commit c3a0f346f3c7a46d824562f1037f5dfbde96f12a
|
Loading…
Reference in New Issue
Block a user