mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 10:45:21 +00:00
FF-129/130: Get destination/withdrawal by external id (#147)
This commit is contained in:
parent
6345c916f8
commit
9c13b85f55
@ -75,8 +75,6 @@ init([]) ->
|
||||
% TODO
|
||||
% - Make it palatable
|
||||
{Backends, Handlers} = lists:unzip([
|
||||
contruct_backend_childspec('ff/external_id' , ff_external_id , PartyClient),
|
||||
contruct_backend_childspec('ff/sequence' , ff_sequence , PartyClient),
|
||||
contruct_backend_childspec('ff/identity' , ff_identity_machine , PartyClient),
|
||||
contruct_backend_childspec('ff/wallet_v2' , ff_wallet_machine , PartyClient),
|
||||
contruct_backend_childspec('ff/source_v1' , ff_instrument_machine , PartyClient),
|
||||
|
@ -32,9 +32,11 @@
|
||||
|
||||
-export([get_destinations/2]).
|
||||
-export([get_destination/2]).
|
||||
-export([get_destination_by_external_id/2]).
|
||||
-export([create_destination/2]).
|
||||
-export([create_withdrawal/2]).
|
||||
-export([get_withdrawal/2]).
|
||||
-export([get_withdrawal_by_external_id/2]).
|
||||
-export([get_withdrawal_events/2]).
|
||||
-export([get_withdrawal_event/3]).
|
||||
-export([list_withdrawals/2]).
|
||||
@ -316,6 +318,21 @@ get_destinations(_Params, _Context) ->
|
||||
get_destination(DestinationID, Context) ->
|
||||
do(fun() -> to_swag(destination, get_state(destination, DestinationID, Context)) end).
|
||||
|
||||
-spec get_destination_by_external_id(id(), ctx()) -> result(map(),
|
||||
{destination, unauthorized} |
|
||||
{destination, notfound} |
|
||||
{external_id, {unknown_external_id, id()}}
|
||||
).
|
||||
get_destination_by_external_id(ExternalID, Context = #{woody_context := WoodyCtx}) ->
|
||||
PartyID = wapi_handler_utils:get_owner(Context),
|
||||
IdempotentKey = bender_client:get_idempotent_key(?BENDER_DOMAIN, destination, PartyID, ExternalID),
|
||||
case bender_client:get_internal_id(IdempotentKey, WoodyCtx) of
|
||||
{ok, DestinationID, _CtxData} ->
|
||||
get_destination(DestinationID, Context);
|
||||
{error, internal_id_not_found} ->
|
||||
{error, {external_id, {unknown_external_id, ExternalID}}}
|
||||
end.
|
||||
|
||||
-spec create_destination(params(), ctx()) -> result(map(),
|
||||
invalid |
|
||||
{identity, unauthorized} |
|
||||
@ -369,6 +386,21 @@ create_withdrawal(Params, Context) ->
|
||||
get_withdrawal(WithdrawalId, Context) ->
|
||||
do(fun() -> to_swag(withdrawal, get_state(withdrawal, WithdrawalId, Context)) end).
|
||||
|
||||
-spec get_withdrawal_by_external_id(id(), ctx()) -> result(map(),
|
||||
{withdrawal, unauthorized} |
|
||||
{withdrawal, {unknown_withdrawal, ff_withdrawal:id()}} |
|
||||
{external_id, {unknown_external_id, id()}}
|
||||
).
|
||||
get_withdrawal_by_external_id(ExternalID, Context = #{woody_context := WoodyCtx}) ->
|
||||
PartyID = wapi_handler_utils:get_owner(Context),
|
||||
IdempotentKey = bender_client:get_idempotent_key(?BENDER_DOMAIN, withdrawal, PartyID, ExternalID),
|
||||
case bender_client:get_internal_id(IdempotentKey, WoodyCtx) of
|
||||
{ok, WithdrawalId, _CtxData} ->
|
||||
get_withdrawal(WithdrawalId, Context);
|
||||
{error, internal_id_not_found} ->
|
||||
{error, {external_id, {unknown_external_id, ExternalID}}}
|
||||
end.
|
||||
|
||||
-spec get_withdrawal_events(params(), ctx()) -> result([map()],
|
||||
{withdrawal, unauthorized} |
|
||||
{withdrawal, {unknown_withdrawal, ff_withdrawal:id()}}
|
||||
|
@ -245,6 +245,17 @@ process_request('GetDestination', #{'destinationID' := DestinationId}, Context,
|
||||
{error, {destination, notfound}} -> wapi_handler_utils:reply_ok(404);
|
||||
{error, {destination, unauthorized}} -> wapi_handler_utils:reply_ok(404)
|
||||
end;
|
||||
process_request('getDestinationByExternalID', #{'externalID' := ExternalID}, Context, _Opts) ->
|
||||
case wapi_wallet_ff_backend:get_destination_by_external_id(ExternalID, Context) of
|
||||
{ok, Destination} ->
|
||||
wapi_handler_utils:reply_ok(200, Destination);
|
||||
{error, {external_id, {unknown_external_id, ExternalID}}} ->
|
||||
wapi_handler_utils:reply_ok(404);
|
||||
{error, {destination, notfound}} ->
|
||||
wapi_handler_utils:reply_ok(404);
|
||||
{error, {destination, unauthorized}} ->
|
||||
wapi_handler_utils:reply_ok(404)
|
||||
end;
|
||||
process_request('CreateDestination', #{'Destination' := Params}, Context, Opts) ->
|
||||
case wapi_wallet_ff_backend:create_destination(Params, Context) of
|
||||
{ok, Destination = #{<<"id">> := DestinationId}} ->
|
||||
@ -344,6 +355,17 @@ process_request('GetWithdrawal', #{'withdrawalID' := WithdrawalId}, Context, _Op
|
||||
{error, {withdrawal, unauthorized}} ->
|
||||
wapi_handler_utils:reply_ok(404)
|
||||
end;
|
||||
process_request('getWithdrawalByExternalID', #{'externalID' := ExternalID}, Context, _Opts) ->
|
||||
case wapi_wallet_ff_backend:get_withdrawal_by_external_id(ExternalID, Context) of
|
||||
{ok, Withdrawal} ->
|
||||
wapi_handler_utils:reply_ok(200, Withdrawal);
|
||||
{error, {external_id, {unknown_external_id, ExternalID}}} ->
|
||||
wapi_handler_utils:reply_ok(404);
|
||||
{error, {withdrawal, {unknown_withdrawal, _WithdrawalId}}} ->
|
||||
wapi_handler_utils:reply_ok(404);
|
||||
{error, {withdrawal, unauthorized}} ->
|
||||
wapi_handler_utils:reply_ok(404)
|
||||
end;
|
||||
process_request('PollWithdrawalEvents', Params, Context, _Opts) ->
|
||||
case wapi_wallet_ff_backend:get_withdrawal_events(Params, Context) of
|
||||
{ok, Events} ->
|
||||
|
@ -168,6 +168,7 @@ idempotency_destination_ok(C) ->
|
||||
ct_cardstore:bank_card(<<"4150399999000900">>, {12, 2025}, C),
|
||||
Party = create_party(C),
|
||||
ExternalID = genlib:unique(),
|
||||
Context = create_context(Party, C),
|
||||
{ok, #{<<"id">> := IdentityID}} = create_identity(Party, C),
|
||||
Params = #{
|
||||
<<"identity">> => IdentityID,
|
||||
@ -182,9 +183,11 @@ idempotency_destination_ok(C) ->
|
||||
<<"externalID">> => ExternalID
|
||||
},
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:create_destination(Params, create_context(Party, C)),
|
||||
wapi_wallet_ff_backend:create_destination(Params, Context),
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:create_destination(Params, create_context(Party, C)).
|
||||
wapi_wallet_ff_backend:create_destination(Params, Context),
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:get_destination_by_external_id(ExternalID, Context).
|
||||
|
||||
-spec idempotency_destination_conflict(config()) ->
|
||||
test_return().
|
||||
@ -222,7 +225,7 @@ idempotency_withdrawal_ok(C) ->
|
||||
{ok, #{<<"id">> := IdentityID}} = create_identity(Party, C),
|
||||
{ok, #{<<"id">> := WalletID}} = create_wallet(IdentityID, Party, C),
|
||||
{ok, #{<<"id">> := DestID}} = create_destination(IdentityID, Party, C),
|
||||
|
||||
Context = create_context(Party, C),
|
||||
wait_for_destination_authorized(DestID),
|
||||
|
||||
Params = #{
|
||||
@ -235,10 +238,11 @@ idempotency_withdrawal_ok(C) ->
|
||||
<<"externalID">> => ExternalID
|
||||
},
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:create_withdrawal(Params, create_context(Party, C)),
|
||||
wapi_wallet_ff_backend:create_withdrawal(Params, Context),
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:create_withdrawal(Params, create_context(Party, C)),
|
||||
_ = binary_to_integer(ID).
|
||||
wapi_wallet_ff_backend:create_withdrawal(Params, Context),
|
||||
{ok, #{<<"id">> := ID}} =
|
||||
wapi_wallet_ff_backend:get_withdrawal_by_external_id(ExternalID, Context).
|
||||
|
||||
-spec idempotency_withdrawal_conflict(config()) ->
|
||||
test_return().
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 620133d70a8bcddf34dc862b4dfb3fedcf1cf055
|
||||
Subproject commit bf107cdb20ba499ef972f7b1806aaf8701f884e8
|
Loading…
Reference in New Issue
Block a user