33-include_lib (" damsel/include/dmsl_base_thrift.hrl" ).
44-include_lib (" damsel/include/dmsl_domain_thrift.hrl" ).
55-include_lib (" damsel/include/dmsl_wthd_domain_thrift.hrl" ).
6+ -include_lib (" limiter_proto/include/limproto_base_thrift.hrl" ).
67-include_lib (" limiter_proto/include/limproto_limiter_thrift.hrl" ).
78-include_lib (" limiter_proto/include/limproto_context_withdrawal_thrift.hrl" ).
89
2122-type clock () :: limproto_limiter_thrift :'Clock' ().
2223
2324-export ([get_turnover_limits /1 ]).
24- -export ([check_limits /2 ]).
25+ -export ([check_limits /3 ]).
2526-export ([marshal_withdrawal /1 ]).
2627
2728-export ([hold_withdrawal_limits /3 ]).
@@ -36,11 +37,11 @@ get_turnover_limits({value, Limits}) ->
3637get_turnover_limits (Ambiguous ) ->
3738 error ({misconfiguration , {'Could not reduce selector to a value' , Ambiguous }}).
3839
39- -spec check_limits ([turnover_limit ()], withdrawal ()) ->
40+ -spec check_limits ([turnover_limit ()], route (), withdrawal ()) ->
4041 {ok , [limit ()]}
4142 | {error , {overflow , [{limit_id (), limit_amount (), turnover_limit_upper_boundary ()}]}}.
42- check_limits (TurnoverLimits , Withdrawal ) ->
43- Context = gen_limit_context (Withdrawal ),
43+ check_limits (TurnoverLimits , Route , Withdrawal ) ->
44+ Context = gen_limit_context (Route , Withdrawal ),
4445 case lists :foldl (fun (Limit , Acc ) -> check_limits_ (Limit , Acc , Context ) end , {[], []}, TurnoverLimits ) of
4546 {Limits , ErrorList } when length (ErrorList ) =:= 0 ->
4647 {ok , Limits };
@@ -67,21 +68,21 @@ check_limits_(T, {Limits, Errors}, Context) ->
6768hold_withdrawal_limits (TurnoverLimits , Route , Withdrawal ) ->
6869 IDs = [T # domain_TurnoverLimit .id || T <- TurnoverLimits ],
6970 LimitChanges = gen_limit_changes (IDs , Route , Withdrawal ),
70- Context = gen_limit_context (Withdrawal ),
71+ Context = gen_limit_context (Route , Withdrawal ),
7172 hold (LimitChanges , get_latest_clock (), Context ).
7273
7374-spec commit_withdrawal_limits ([turnover_limit ()], route (), withdrawal ()) -> ok .
7475commit_withdrawal_limits (TurnoverLimits , Route , Withdrawal ) ->
7576 IDs = [T # domain_TurnoverLimit .id || T <- TurnoverLimits ],
7677 LimitChanges = gen_limit_changes (IDs , Route , Withdrawal ),
77- Context = gen_limit_context (Withdrawal ),
78+ Context = gen_limit_context (Route , Withdrawal ),
7879 commit (LimitChanges , get_latest_clock (), Context ).
7980
8081-spec rollback_withdrawal_limits ([turnover_limit ()], route (), withdrawal ()) -> ok .
8182rollback_withdrawal_limits (TurnoverLimits , Route , Withdrawal ) ->
8283 IDs = [T # domain_TurnoverLimit .id || T <- TurnoverLimits ],
8384 LimitChanges = gen_limit_changes (IDs , Route , Withdrawal ),
84- Context = gen_limit_context (Withdrawal ),
85+ Context = gen_limit_context (Route , Withdrawal ),
8586 rollback (LimitChanges , get_latest_clock (), Context ).
8687
8788-spec hold ([limit_change ()], clock (), context ()) -> ok .
@@ -111,12 +112,20 @@ rollback(LimitChanges, Clock, Context) ->
111112 LimitChanges
112113 ).
113114
114- gen_limit_context (Withdrawal ) ->
115+ gen_limit_context (#{provider_id := ProviderID , terminal_id := TerminalID }, Withdrawal ) ->
116+ #{wallet_id := WalletID } = ff_withdrawal :params (Withdrawal ),
115117 MarshaledWithdrawal = marshal_withdrawal (Withdrawal ),
116118 # limiter_LimitContext {
117119 withdrawal_processing = # context_withdrawal_Context {
118120 op = {withdrawal , # context_withdrawal_OperationWithdrawal {}},
119- withdrawal = # context_withdrawal_Withdrawal {withdrawal = MarshaledWithdrawal }
121+ withdrawal = # context_withdrawal_Withdrawal {
122+ withdrawal = MarshaledWithdrawal ,
123+ route = # base_Route {
124+ provider = # domain_ProviderRef {id = ProviderID },
125+ terminal = # domain_TerminalRef {id = TerminalID }
126+ },
127+ wallet_id = WalletID
128+ }
120129 }
121130 }.
122131
0 commit comments