@@ -96,6 +96,21 @@ handle_function_('GetPaymentAdjustment', {InvoiceID, PaymentID, ID}, _Opts) ->
9696 _ = set_invoicing_meta (InvoiceID , PaymentID ),
9797 St = get_state (InvoiceID ),
9898 hg_invoice_payment :get_adjustment (ID , get_payment_session (PaymentID , St ));
99+ handle_function_ ('ComputeTerms' , {InvoiceID }, _Opts ) ->
100+ _ = set_invoicing_meta (InvoiceID ),
101+ St = get_state (InvoiceID ),
102+ DomainRevision = hg_domain :head (),
103+ Party = hg_party :get_party (get_party_id (St )),
104+ Shop = assert_shop_exists (hg_party :get_shop (get_shop_id (St ), Party , DomainRevision )),
105+ _ = assert_party_shop_operable (Shop , Party ),
106+ VS = #{
107+ cost => get_cost (St ),
108+ shop_id => Shop # domain_ShopConfig .id ,
109+ party_id => Party # domain_PartyConfig .id ,
110+ category => Shop # domain_ShopConfig .category ,
111+ currency => hg_invoice_utils :get_shop_currency (Shop )
112+ },
113+ hg_invoice_utils :compute_shop_terms (DomainRevision , Shop , VS );
99114handle_function_ (Fun , Args , _Opts ) when
100115 Fun =:= 'StartPayment' orelse
101116 Fun =:= 'RegisterPayment' orelse
@@ -233,6 +248,15 @@ map_history_error({error, notfound}) ->
233248
234249% %
235250
251+ get_party_id (# st {invoice = # domain_Invoice {owner_id = PartyID }}) ->
252+ PartyID .
253+
254+ get_shop_id (# st {invoice = # domain_Invoice {shop_id = ShopID }}) ->
255+ ShopID .
256+
257+ get_cost (# st {invoice = # domain_Invoice {cost = Cash }}) ->
258+ Cash .
259+
236260get_payment_session (PaymentID , St ) ->
237261 case try_get_payment_session (PaymentID , St ) of
238262 PaymentSession when PaymentSession /= undefined ->
0 commit comments