Revert "Revert "HG-555: update ComputeShopTerms clients (#497)" (#503)" (#504)

This reverts commit 72f6fd5c3d.
This commit is contained in:
Toporkov Igor 2020-11-09 13:50:16 +03:00 committed by GitHub
parent 72f6fd5c3d
commit 233b3a0913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 21 deletions

View File

@ -216,13 +216,26 @@ handle_function_('ComputeTerms', {UserInfo, InvoiceID, PartyRevision0}, _Opts) -
PartyID = get_party_id(St),
Timestamp = get_created_at(St),
PartyRevision1 = hg_maybe:get_defined(PartyRevision0, {timestamp, Timestamp}),
Party = hg_party:get_party(PartyID),
Shop = hg_party:get_shop(ShopID, Party),
Contract = hg_party:get_contract(Shop#domain_Shop.contract_id, Party),
Cash = get_cost(St),
VS = hg_varset:prepare_varset(#{
party_id => PartyID,
shop_id => ShopID,
category => Shop#domain_Shop.category,
currency => (Shop#domain_Shop.account)#domain_ShopAccount.currency,
identification_level => hg_invoice_utils:get_identification_level(Contract, Party),
cost => Cash
}),
ShopTerms = hg_invoice_utils:compute_shop_terms(
UserInfo,
PartyID,
ShopID,
Timestamp,
PartyRevision1
PartyRevision1,
VS
),
% TODO: remove once PM is updated
Revision = hg_domain:head(),
Cash = get_cost(St),
pm_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);

View File

@ -95,13 +95,33 @@ handle_function_('ComputeTerms', {UserInfo, TplID, Timestamp, PartyRevision0}, _
ShopID = Tpl#domain_InvoiceTemplate.shop_id,
PartyID = Tpl#domain_InvoiceTemplate.owner_id,
PartyRevision1 = hg_maybe:get_defined(PartyRevision0, {timestamp, Timestamp}),
ShopTerms = hg_invoice_utils:compute_shop_terms(UserInfo, PartyID, ShopID, Timestamp, PartyRevision1),
case Tpl#domain_InvoiceTemplate.details of
{product, #domain_InvoiceTemplateProduct{price = {fixed, Cash}}} ->
Revision = hg_domain:head(),
pm_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);
Party = hg_party:get_party(PartyID),
Shop = hg_party:get_shop(ShopID, Party),
Contract = hg_party:get_contract(Shop#domain_Shop.contract_id, Party),
Cost =
case Tpl#domain_InvoiceTemplate.details of
{product, #domain_InvoiceTemplateProduct{price = {fixed, Cash}}} ->
Cash;
_ ->
undefined
end,
VS0 = #{
party_id => PartyID,
shop_id => ShopID,
category => Shop#domain_Shop.category,
currency => (Shop#domain_Shop.account)#domain_ShopAccount.currency,
identification_level => hg_invoice_utils:get_identification_level(Contract, Party),
cost => Cost
},
VS = hg_varset:prepare_varset(genlib_map:compact(VS0)),
ShopTerms = hg_invoice_utils:compute_shop_terms(PartyID, ShopID, Timestamp, PartyRevision1, VS),
% TODO: remove once PM is updated
case Cost of
undefined ->
ShopTerms;
_ ->
ShopTerms
Revision = hg_domain:head(),
pm_party:reduce_terms(ShopTerms, #{cost => Cost}, Revision)
end.
assume_user_identity(UserInfo) ->

View File

@ -18,6 +18,7 @@
-export([compute_shop_terms/5]).
-export([get_cart_amount/1]).
-export([check_deadline/1]).
-export([get_identification_level/2]).
-type amount() :: dmsl_domain_thrift:'Amount'().
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
@ -33,8 +34,9 @@
-type payment_service_terms() :: dmsl_domain_thrift:'PaymentsServiceTerms'().
-type domain_revision() :: dmsl_domain_thrift:'DataRevision'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type party_revision_param() :: dmsl_payment_processing_thrift:'PartyRevisionParam'().
-type identification_level() :: dmsl_domain_thrift:'ContractorIdentificationLevel'().
-type varset() :: dmsl_payment_processing_thrift:'Varset'().
-spec validate_cost(cash(), shop()) -> ok.
validate_cost(#domain_Cash{currency = Currency, amount = Amount}, Shop) ->
@ -145,10 +147,11 @@ collect_validation_varset(Cost, Party, Shop) ->
currency => Currency
}.
-spec compute_shop_terms(user_info(), party_id(), shop_id(), timestamp(), party_revision_param()) -> term_set().
compute_shop_terms(UserInfo, PartyID, ShopID, Timestamp, PartyRevision) ->
Args = {UserInfo, PartyID, ShopID, Timestamp, PartyRevision},
{ok, TermSet} = hg_woody_wrapper:call(party_management, 'ComputeShopTerms', Args),
-spec compute_shop_terms(party_id(), shop_id(), timestamp(), party_revision_param(), varset()) -> term_set().
compute_shop_terms(PartyID, ShopID, Timestamp, PartyRevision, Varset) ->
{Client, Context} = get_party_client(),
{ok, TermSet} =
party_client_thrift:compute_shop_terms(PartyID, ShopID, Timestamp, PartyRevision, Varset, Client, Context),
TermSet.
validate_currency_(Currency, Currency) ->
@ -197,3 +200,22 @@ check_deadline(Deadline) ->
_ ->
{error, deadline_reached}
end.
get_party_client() ->
HgContext = hg_context:load(),
Client = hg_context:get_party_client(HgContext),
Context = hg_context:get_party_client_context(HgContext),
{Client, Context}.
-spec get_identification_level(contract(), party()) -> identification_level().
get_identification_level(#domain_Contract{contractor_id = undefined, contractor = Contractor}, _) ->
%% TODO legacy, remove after migration
case Contractor of
{legal_entity, _} ->
full;
_ ->
none
end;
get_identification_level(#domain_Contract{contractor_id = ContractorID}, #domain_Party{contractors = Contractors}) ->
Contractor = maps:get(ContractorID, Contractors, undefined),
Contractor#domain_PartyContractor.status.

View File

@ -1079,14 +1079,21 @@ shop_terms_retrieval(C) ->
PartyID = cfg(party_id, C),
ShopID = ?REAL_SHOP_ID,
Timestamp = pm_datetime:format_now(),
TermSet1 = pm_client_party:compute_shop_terms(ShopID, Timestamp, {timestamp, Timestamp}, Client),
VS = #payproc_Varset{
shop_id = ShopID,
party_id = PartyID,
category = ?cat(2),
currency = ?cur(<<"RUB">>),
identification_level = full
},
TermSet1 = pm_client_party:compute_shop_terms(ShopID, Timestamp, {timestamp, Timestamp}, VS, Client),
#domain_TermSet{
payments = #domain_PaymentsServiceTerms{
payment_methods = {value, [?pmt(bank_card_deprecated, visa)]}
}
} = TermSet1,
ok = pm_domain:update(construct_term_set_for_party(PartyID, {shop_is, ShopID})),
TermSet2 = pm_client_party:compute_shop_terms(ShopID, pm_datetime:format_now(), {timestamp, Timestamp}, Client),
TermSet2 = pm_client_party:compute_shop_terms(ShopID, pm_datetime:format_now(), {timestamp, Timestamp}, VS, Client),
#domain_TermSet{
payments = #domain_PaymentsServiceTerms{
payment_methods = {value, ?REAL_PARTY_PAYMENT_METHODS}

View File

@ -25,7 +25,7 @@
-export([get_contract/2]).
-export([compute_contract_terms/6]).
-export([get_shop/2]).
-export([compute_shop_terms/4]).
-export([compute_shop_terms/5]).
-export([compute_payment_institution_terms/3]).
-export([compute_payout_cash_flow/2]).
@ -205,10 +205,10 @@ suspend_shop(ID, Client) ->
activate_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'ActivateShop', [ID]})).
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), pid()) ->
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), varset(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_shop_terms(ID, Timestamp, PartyRevision, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision]})).
compute_shop_terms(ID, Timestamp, PartyRevision, VS, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision, VS]})).
-spec get_claim(claim_id(), pid()) -> claim() | woody_error:business_error().
get_claim(ID, Client) ->

View File

@ -11,7 +11,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.8.0">>},2},
{<<"damsel">>,
{git,"git@github.com:rbkmoney/damsel.git",
{ref,"1c2fe199e22bb4919dda674643f35501c5b9ce66"}},
{ref,"0d7c67e62ae3a7a70e39fdc47fb75f4a67792369"}},
0},
{<<"dmt_client">>,
{git,"git@github.com:rbkmoney/dmt_client.git",
@ -58,7 +58,7 @@
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.0">>},3},
{<<"party_client">>,
{git,"git@github.com:rbkmoney/party_client_erlang.git",
{ref,"6b5765cb4f936dae38938ccb97ad13664eabd736"}},
{ref,"d05c5f7b7797f914070b4e8b15870d915764eab0"}},
0},
{<<"payproc_errors">>,
{git,"git@github.com:rbkmoney/payproc-errors-erlang.git",