mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
TD-407: Add route and wallet scopes (#43)
This commit is contained in:
parent
e28ecaa408
commit
ad8e2d0996
@ -3,6 +3,7 @@
|
||||
-include_lib("damsel/include/dmsl_base_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_wthd_domain_thrift.hrl").
|
||||
-include_lib("limiter_proto/include/limproto_base_thrift.hrl").
|
||||
-include_lib("limiter_proto/include/limproto_limiter_thrift.hrl").
|
||||
-include_lib("limiter_proto/include/limproto_context_withdrawal_thrift.hrl").
|
||||
|
||||
@ -21,7 +22,7 @@
|
||||
-type clock() :: limproto_limiter_thrift:'Clock'().
|
||||
|
||||
-export([get_turnover_limits/1]).
|
||||
-export([check_limits/2]).
|
||||
-export([check_limits/3]).
|
||||
-export([marshal_withdrawal/1]).
|
||||
|
||||
-export([hold_withdrawal_limits/3]).
|
||||
@ -36,11 +37,11 @@ get_turnover_limits({value, Limits}) ->
|
||||
get_turnover_limits(Ambiguous) ->
|
||||
error({misconfiguration, {'Could not reduce selector to a value', Ambiguous}}).
|
||||
|
||||
-spec check_limits([turnover_limit()], withdrawal()) ->
|
||||
-spec check_limits([turnover_limit()], route(), withdrawal()) ->
|
||||
{ok, [limit()]}
|
||||
| {error, {overflow, [{limit_id(), limit_amount(), turnover_limit_upper_boundary()}]}}.
|
||||
check_limits(TurnoverLimits, Withdrawal) ->
|
||||
Context = gen_limit_context(Withdrawal),
|
||||
check_limits(TurnoverLimits, Route, Withdrawal) ->
|
||||
Context = gen_limit_context(Route, Withdrawal),
|
||||
case lists:foldl(fun(Limit, Acc) -> check_limits_(Limit, Acc, Context) end, {[], []}, TurnoverLimits) of
|
||||
{Limits, ErrorList} when length(ErrorList) =:= 0 ->
|
||||
{ok, Limits};
|
||||
@ -67,21 +68,21 @@ check_limits_(T, {Limits, Errors}, Context) ->
|
||||
hold_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
|
||||
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
|
||||
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
|
||||
Context = gen_limit_context(Withdrawal),
|
||||
Context = gen_limit_context(Route, Withdrawal),
|
||||
hold(LimitChanges, get_latest_clock(), Context).
|
||||
|
||||
-spec commit_withdrawal_limits([turnover_limit()], route(), withdrawal()) -> ok.
|
||||
commit_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
|
||||
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
|
||||
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
|
||||
Context = gen_limit_context(Withdrawal),
|
||||
Context = gen_limit_context(Route, Withdrawal),
|
||||
commit(LimitChanges, get_latest_clock(), Context).
|
||||
|
||||
-spec rollback_withdrawal_limits([turnover_limit()], route(), withdrawal()) -> ok.
|
||||
rollback_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
|
||||
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
|
||||
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
|
||||
Context = gen_limit_context(Withdrawal),
|
||||
Context = gen_limit_context(Route, Withdrawal),
|
||||
rollback(LimitChanges, get_latest_clock(), Context).
|
||||
|
||||
-spec hold([limit_change()], clock(), context()) -> ok.
|
||||
@ -111,12 +112,20 @@ rollback(LimitChanges, Clock, Context) ->
|
||||
LimitChanges
|
||||
).
|
||||
|
||||
gen_limit_context(Withdrawal) ->
|
||||
gen_limit_context(#{provider_id := ProviderID, terminal_id := TerminalID}, Withdrawal) ->
|
||||
#{wallet_id := WalletID} = ff_withdrawal:params(Withdrawal),
|
||||
MarshaledWithdrawal = marshal_withdrawal(Withdrawal),
|
||||
#limiter_LimitContext{
|
||||
withdrawal_processing = #context_withdrawal_Context{
|
||||
op = {withdrawal, #context_withdrawal_OperationWithdrawal{}},
|
||||
withdrawal = #context_withdrawal_Withdrawal{withdrawal = MarshaledWithdrawal}
|
||||
withdrawal = #context_withdrawal_Withdrawal{
|
||||
withdrawal = MarshaledWithdrawal,
|
||||
route = #base_Route{
|
||||
provider = #domain_ProviderRef{id = ProviderID},
|
||||
terminal = #domain_TerminalRef{id = TerminalID}
|
||||
},
|
||||
wallet_id = WalletID
|
||||
}
|
||||
}
|
||||
}.
|
||||
|
||||
|
@ -356,7 +356,7 @@ validate_turnover_limits(undefined, _VS, _Route, _RoutingContext) ->
|
||||
{ok, valid};
|
||||
validate_turnover_limits({value, TurnoverLimits}, _VS, Route, #{withdrawal := Withdrawal}) ->
|
||||
ok = ff_limiter:hold_withdrawal_limits(TurnoverLimits, Route, Withdrawal),
|
||||
case ff_limiter:check_limits(TurnoverLimits, Withdrawal) of
|
||||
case ff_limiter:check_limits(TurnoverLimits, Route, Withdrawal) of
|
||||
{ok, _} ->
|
||||
{ok, valid};
|
||||
{error, Error} ->
|
||||
|
@ -50,7 +50,7 @@
|
||||
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
|
||||
{<<"limiter_proto">>,
|
||||
{git,"https://github.com/valitydev/limiter-proto.git",
|
||||
{ref,"61581846b4d41de3a9e561c79f558e74450ab950"}},
|
||||
{ref,"31de59b17ad20e426b158ace6097e35330926bea"}},
|
||||
0},
|
||||
{<<"machinery">>,
|
||||
{git,"https://github.com/valitydev/machinery-erlang.git",
|
||||
|
Loading…
Reference in New Issue
Block a user