Skip to content

Commit e88a03f

Browse files
committed
Merge branch 'master' into epic/dmt-client-v2
2 parents 7fe3e5d + 62f116f commit e88a03f

5 files changed

Lines changed: 46 additions & 16 deletions

File tree

apps/hellgate/src/hg_invoice_handler.erl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
99114
handle_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+
236260
get_payment_session(PaymentID, St) ->
237261
case try_get_payment_session(PaymentID, St) of
238262
PaymentSession when PaymentSession /= undefined ->

apps/hellgate/src/hg_invoice_template.erl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ handle_function_('Delete' = Fun, {TplID} = Args, _Opts) ->
8181
_ = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party),
8282
_ = set_meta(TplID),
8383
call(TplID, Fun, Args);
84-
handle_function_('ComputeTerms', {TplID, _Timestamp, _PartyRevision0}, _Opts) ->
84+
handle_function_('ComputeTerms', {TplID}, _Opts) ->
8585
_ = set_meta(TplID),
8686
Tpl = get_invoice_template(TplID),
8787
Cost =
@@ -91,19 +91,28 @@ handle_function_('ComputeTerms', {TplID, _Timestamp, _PartyRevision0}, _Opts) ->
9191
_ ->
9292
undefined
9393
end,
94-
VS0 = #{
95-
cost => Cost
96-
},
97-
VS = hg_varset:prepare_varset(VS0),
9894
Revision = hg_party:get_party_revision(),
9995
Party = hg_party:checkout(Tpl#domain_InvoiceTemplate.owner_id, Revision),
10096
Shop = hg_party:get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party, Revision),
97+
_ = assert_party_shop_operable(Shop, Party),
98+
VS = #{
99+
cost => Cost,
100+
shop_id => Shop#domain_ShopConfig.id,
101+
party_id => Party#domain_PartyConfig.id,
102+
category => Shop#domain_ShopConfig.category,
103+
currency => hg_invoice_utils:get_shop_currency(Shop)
104+
},
101105
hg_invoice_utils:compute_shop_terms(
102106
Revision,
103107
Shop,
104108
VS
105109
).
106110

111+
assert_party_shop_operable(Shop, Party) ->
112+
_ = hg_invoice_utils:assert_party_operable(Party),
113+
_ = hg_invoice_utils:assert_shop_operable(Shop),
114+
ok.
115+
107116
get_party(PartyID) ->
108117
Party = hg_party:get_party(PartyID),
109118
_ = hg_invoice_utils:assert_party_operable(Party),

apps/hellgate/test/hg_invoice_template_tests_SUITE.erl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,7 @@ terms_retrieval(C) ->
484484
Client = cfg(client, C),
485485
?invoice_tpl(TplID1) = create_invoice_tpl(C),
486486

487-
Timestamp = hg_datetime:format_now(),
488-
TermSet1 = hg_client_invoice_templating:compute_terms(TplID1, Timestamp, {timestamp, Timestamp}, Client),
487+
TermSet1 = hg_client_invoice_templating:compute_terms(TplID1, Client),
489488
#domain_TermSet{
490489
payments = #domain_PaymentsServiceTerms{
491490
payment_methods = undefined
@@ -494,7 +493,7 @@ terms_retrieval(C) ->
494493

495494
_ = hg_domain:update(construct_term_set_for_cost(5000, 11000)),
496495

497-
TermSet2 = hg_client_invoice_templating:compute_terms(TplID1, Timestamp, {timestamp, Timestamp}, Client),
496+
TermSet2 = hg_client_invoice_templating:compute_terms(TplID1, Client),
498497
#domain_TermSet{
499498
payments = #domain_PaymentsServiceTerms{
500499
payment_methods =
@@ -509,7 +508,7 @@ terms_retrieval(C) ->
509508
Lifetime = make_lifetime(0, 0, 2),
510509
Cost = make_cost(unlim, sale, "1%"),
511510
?invoice_tpl(TplID2) = create_invoice_tpl(C, <<"rubberduck">>, Lifetime, Cost),
512-
TermSet3 = hg_client_invoice_templating:compute_terms(TplID2, Timestamp, {timestamp, Timestamp}, Client),
511+
TermSet3 = hg_client_invoice_templating:compute_terms(TplID2, Client),
513512
#domain_TermSet{
514513
payments = #domain_PaymentsServiceTerms{
515514
payment_methods = {decisions, _}

apps/hg_client/src/hg_client_invoice_templating.erl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
-export([update/3]).
1212
-export([delete/2]).
1313

14-
-export([compute_terms/4]).
14+
-export([compute_terms/2]).
1515

1616
%% GenServer
1717

@@ -30,9 +30,7 @@
3030
-type create_params() :: dmsl_payproc_thrift:'InvoiceTemplateCreateParams'().
3131
-type update_params() :: dmsl_payproc_thrift:'InvoiceTemplateUpdateParams'().
3232
-type invoice_tpl() :: dmsl_domain_thrift:'InvoiceTemplate'().
33-
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
3433
-type term_set() :: dmsl_domain_thrift:'TermSet'().
35-
-type party_revision_param() :: dmsl_payproc_thrift:'PartyRevisionParam'().
3634

3735
-spec start(hg_client_api:t()) -> pid().
3836
start(ApiClient) ->
@@ -69,9 +67,9 @@ update(ID, Params, Client) ->
6967
delete(ID, Client) ->
7068
map_result_error(gen_server:call(Client, {call, 'Delete', [ID]})).
7169

72-
-spec compute_terms(id(), timestamp(), party_revision_param(), pid()) -> term_set().
73-
compute_terms(ID, Timestamp, PartyRevision, Client) ->
74-
map_result_error(gen_server:call(Client, {call, 'ComputeTerms', [ID, Timestamp, PartyRevision]})).
70+
-spec compute_terms(id(), pid()) -> term_set().
71+
compute_terms(ID, Client) ->
72+
map_result_error(gen_server:call(Client, {call, 'ComputeTerms', [ID]})).
7573

7674
map_result_error({ok, Result}) ->
7775
Result;

rebar.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
2828
{<<"damsel">>,
2929
{git,"https://github.com/valitydev/damsel.git",
30-
{ref,"ab44b9db25a76a2c50545fd884e4cdf3d3e3b628"}},
30+
{ref,"5ca4f4a2af6bd68ba4d255889c0e2c0c1c5479a4"}},
3131
0},
3232
{<<"dmt_client">>,
3333
{git,"https://github.com/valitydev/dmt-client.git",

0 commit comments

Comments
 (0)