1010-type turnover_limit () :: dmsl_domain_thrift :'TurnoverLimit' ().
1111-type invoice () :: dmsl_domain_thrift :'Invoice' ().
1212-type payment () :: dmsl_domain_thrift :'InvoicePayment' ().
13+ -type session () :: hg_session :t ().
1314-type route () :: hg_route :payment_route ().
1415-type refund () :: hg_invoice_payment :domain_refund ().
1516-type cash () :: dmsl_domain_thrift :'Cash' ().
2122-export_type ([turnover_limit_value / 0 ]).
2223
2324-export ([get_turnover_limits /2 ]).
24- -export ([check_limits /5 ]).
25+ -export ([check_limits /6 ]).
2526-export ([check_shop_limits /5 ]).
26- -export ([hold_payment_limits /5 ]).
27+ -export ([hold_payment_limits /6 ]).
2728-export ([hold_shop_limits /5 ]).
2829-export ([hold_refund_limits /5 ]).
29- -export ([commit_payment_limits /6 ]).
30+ -export ([commit_payment_limits /7 ]).
3031-export ([commit_shop_limits /5 ]).
3132-export ([commit_refund_limits /5 ]).
32- -export ([rollback_payment_limits /6 ]).
33+ -export ([rollback_payment_limits /7 ]).
3334-export ([rollback_shop_limits /6 ]).
3435-export ([rollback_refund_limits /5 ]).
35- -export ([get_limit_values /5 ]).
36+ -export ([get_limit_values /6 ]).
3637
3738-define (route (ProviderRef , TerminalRef ), # domain_PaymentRoute {
3839 provider = ProviderRef ,
@@ -77,9 +78,10 @@ filter_existing_turnover_limits(Limits, Mode) ->
7778 Limits
7879 ).
7980
80- -spec get_limit_values ([turnover_limit ()], invoice (), payment (), route (), pos_integer ()) -> [turnover_limit_value ()].
81- get_limit_values (TurnoverLimits , Invoice , Payment , Route , Iter ) ->
82- Context = gen_limit_context (Invoice , Payment , Route ),
81+ -spec get_limit_values ([turnover_limit ()], invoice (), payment (), session () | undefined , route (), pos_integer ()) ->
82+ [turnover_limit_value ()].
83+ get_limit_values (TurnoverLimits , Invoice , Payment , Session , Route , Iter ) ->
84+ Context = gen_limit_context (Invoice , Payment , Session , Route ),
8385 get_limit_values (Context , TurnoverLimits , make_route_operation_segments (Invoice , Payment , Route , Iter )).
8486
8587make_route_operation_segments (Invoice , Payment , ? route (ProviderRef , TerminalRef ), Iter ) ->
@@ -105,11 +107,11 @@ get_batch_limit_values(Context, TurnoverLimits, OperationIdSegments) ->
105107 hg_limiter_client :get_batch (LimitRequest , Context )
106108 ).
107109
108- -spec check_limits ([turnover_limit ()], invoice (), payment (), route (), pos_integer ()) ->
110+ -spec check_limits ([turnover_limit ()], invoice (), payment (), session () | undefined , route (), pos_integer ()) ->
109111 {ok , [turnover_limit_value ()]}
110112 | {error , {limit_overflow , [binary ()], [turnover_limit_value ()]}}.
111- check_limits (TurnoverLimits , Invoice , Payment , Route , Iter ) ->
112- Context = gen_limit_context (Invoice , Payment , Route ),
113+ check_limits (TurnoverLimits , Invoice , Payment , Session , Route , Iter ) ->
114+ Context = gen_limit_context (Invoice , Payment , Session , Route ),
113115 Limits = get_limit_values (Context , TurnoverLimits , make_route_operation_segments (Invoice , Payment , Route , Iter )),
114116 try
115117 ok = check_limits_ (Limits , Context ),
@@ -166,9 +168,10 @@ check_limits_([TurnoverLimitValue | TLVs], Context) ->
166168 throw (limit_overflow )
167169 end .
168170
169- -spec hold_payment_limits ([turnover_limit ()], invoice (), payment (), route (), pos_integer ()) -> ok .
170- hold_payment_limits (TurnoverLimits , Invoice , Payment , Route , Iter ) ->
171- Context = gen_limit_context (Invoice , Payment , Route ),
171+ -spec hold_payment_limits ([turnover_limit ()], invoice (), payment (), session () | undefined , route (), pos_integer ()) ->
172+ ok .
173+ hold_payment_limits (TurnoverLimits , Invoice , Payment , Session , Route , Iter ) ->
174+ Context = gen_limit_context (Invoice , Payment , Session , Route ),
172175 ok = batch_hold_limits (Context , TurnoverLimits , make_route_operation_segments (Invoice , Payment , Route , Iter )).
173176
174177batch_hold_limits (_Context , [], _OperationIdSegments ) ->
@@ -197,9 +200,17 @@ make_refund_operation_segments(Invoice, Payment, Refund) ->
197200 {refund_session , get_refund_id (Refund )}
198201 ].
199202
200- -spec commit_payment_limits ([turnover_limit ()], invoice (), payment (), route (), pos_integer (), cash () | undefined ) -> ok .
201- commit_payment_limits (TurnoverLimits , Invoice , Payment , Route , Iter , CapturedCash ) ->
202- Context = gen_limit_context (Invoice , Payment , Route , CapturedCash ),
203+ -spec commit_payment_limits (
204+ [turnover_limit ()],
205+ invoice (),
206+ payment (),
207+ session () | undefined ,
208+ route (),
209+ pos_integer (),
210+ cash () | undefined
211+ ) -> ok .
212+ commit_payment_limits (TurnoverLimits , Invoice , Payment , Session , Route , Iter , CapturedCash ) ->
213+ Context = gen_limit_context (Invoice , Payment , Session , Route , CapturedCash ),
203214 OperationIdSegments = make_route_operation_segments (Invoice , Payment , Route , Iter ),
204215 ok = batch_commit_limits (Context , TurnoverLimits , OperationIdSegments ).
205216
@@ -243,10 +254,18 @@ batch_commit_limits(Context, TurnoverLimits, OperationIdSegments) ->
243254% %
244255% % - `ignore_not_found` -- does not raise error if limiter won't be able to
245256% % find according posting plan in accountant service
246- -spec rollback_payment_limits ([turnover_limit ()], invoice (), payment (), route (), pos_integer (), [handling_flag ()]) ->
257+ -spec rollback_payment_limits (
258+ [turnover_limit ()],
259+ invoice (),
260+ payment (),
261+ session () | undefined ,
262+ route (),
263+ pos_integer (),
264+ [handling_flag ()]
265+ ) ->
247266 ok .
248- rollback_payment_limits (TurnoverLimits , Invoice , Payment , Route , Iter , Flags ) ->
249- Context = gen_limit_context (Invoice , Payment , Route ),
267+ rollback_payment_limits (TurnoverLimits , Invoice , Payment , Session , Route , Iter , Flags ) ->
268+ Context = gen_limit_context (Invoice , Payment , Session , Route ),
250269 OperationIdSegments = make_route_operation_segments (Invoice , Payment , Route , Iter ),
251270 ok = batch_rollback_limits (Context , TurnoverLimits , OperationIdSegments , Flags ).
252271
@@ -281,10 +300,10 @@ rollback_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) ->
281300 OperationIdSegments = make_refund_operation_segments (Invoice , Payment , Refund ),
282301 ok = batch_rollback_limits (Context , TurnoverLimits , OperationIdSegments , []).
283302
284- gen_limit_context (Invoice , Payment , Route ) ->
285- gen_limit_context (Invoice , Payment , Route , undefined ).
303+ gen_limit_context (Invoice , Payment , Session , Route ) ->
304+ gen_limit_context (Invoice , Payment , Session , Route , undefined ).
286305
287- gen_limit_context (Invoice , Payment , Route , CapturedCash ) ->
306+ gen_limit_context (Invoice , Payment , Session , Route , CapturedCash ) ->
288307 PaymentCtx = # context_payproc_InvoicePayment {
289308 payment = Payment # domain_InvoicePayment {
290309 status = {captured , # domain_InvoicePaymentCaptured {cost = CapturedCash }}
@@ -296,11 +315,17 @@ gen_limit_context(Invoice, Payment, Route, CapturedCash) ->
296315 op = {invoice_payment , # context_payproc_OperationInvoicePayment {}},
297316 invoice = # context_payproc_Invoice {
298317 invoice = Invoice ,
299- payment = PaymentCtx
318+ payment = PaymentCtx ,
319+ session = gen_limit_session_context (Session , Route )
300320 }
301321 }
302322 }.
303323
324+ gen_limit_session_context (#{status := finished , route := Route }, Route ) ->
325+ # context_payproc_InvoicePaymentSession {};
326+ gen_limit_session_context (_ , _ ) ->
327+ undefined .
328+
304329gen_limit_shop_context (Invoice , Payment ) ->
305330 # limiter_LimitContext {
306331 payment_processing = # context_payproc_Context {
0 commit comments