diff --git a/apps/hellgate/src/hg_customer.erl b/apps/hellgate/src/hg_customer.erl index b54ad5fc4..4748ef85e 100644 --- a/apps/hellgate/src/hg_customer.erl +++ b/apps/hellgate/src/hg_customer.erl @@ -66,8 +66,7 @@ handle_function(Func, Args, Opts) -> handle_function_('Create', {CustomerParams}, _Opts) -> DomainRevision = hg_domain:head(), - %% FIXME(ED-95): temporary fallback generation till CustomerID is made required in damsel - CustomerID = hg_utils:uid(CustomerParams#payproc_CustomerParams.customer_id), + CustomerID = CustomerParams#payproc_CustomerParams.customer_id, ok = set_meta(CustomerID), PartyID = CustomerParams#payproc_CustomerParams.party_id, ShopID = CustomerParams#payproc_CustomerParams.shop_id, @@ -322,13 +321,10 @@ handle_result_action(#{}, Acc) -> start_binding(BindingParams, St) -> #payproc_CustomerBindingParams{ - customer_binding_id = MaybeBindingID, + customer_binding_id = BindingID, payment_resource = PaymentResource, - rec_payment_tool_id = MaybePaytoolID + rec_payment_tool_id = PaytoolID } = BindingParams, - %% FIXME(ED-95): temporary fallback generation till TemplateID is made required in damsel - BindingID = hg_utils:uid(MaybeBindingID), - PaytoolID = hg_utils:uid(MaybePaytoolID), DomainRevision = hg_domain:head(), PartyID = get_party_id(St), PartyRevision = hg_party:get_party_revision(PartyID), diff --git a/apps/hellgate/src/hg_invoice.erl b/apps/hellgate/src/hg_invoice.erl index 028ff3059..3539973a4 100644 --- a/apps/hellgate/src/hg_invoice.erl +++ b/apps/hellgate/src/hg_invoice.erl @@ -158,7 +158,7 @@ handle_function(Func, Args, Opts) -> -spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return(). handle_function_('Create', {UserInfo, InvoiceParams}, _Opts) -> DomainRevision = hg_domain:head(), - InvoiceID = hg_utils:uid(InvoiceParams#payproc_InvoiceParams.id), + InvoiceID = InvoiceParams#payproc_InvoiceParams.id, ok = assume_user_identity(UserInfo), _ = set_invoicing_meta(InvoiceID), PartyID = InvoiceParams#payproc_InvoiceParams.party_id, @@ -173,7 +173,7 @@ handle_function_('Create', {UserInfo, InvoiceParams}, _Opts) -> get_invoice_state(get_state(InvoiceID)); handle_function_('CreateWithTemplate', {UserInfo, Params}, _Opts) -> DomainRevision = hg_domain:head(), - InvoiceID = hg_utils:uid(Params#payproc_InvoiceWithTemplateParams.id), + InvoiceID = Params#payproc_InvoiceWithTemplateParams.id, ok = assume_user_identity(UserInfo), _ = set_invoicing_meta(InvoiceID), TplID = Params#payproc_InvoiceWithTemplateParams.template_id, @@ -1251,6 +1251,7 @@ assume_user_identity(UserInfo) -> make_invoice_params(Params) -> #payproc_InvoiceWithTemplateParams{ + id = InvoiceID, template_id = TplID, cost = Cost, context = Context, @@ -1279,6 +1280,7 @@ make_invoice_params(Params) -> InvoiceDue = make_invoice_due_date(Lifetime), InvoiceContext = make_invoice_context(Context, TplContext), InvoiceParams = #payproc_InvoiceParams{ + id = InvoiceID, party_id = PartyID, shop_id = ShopID, details = InvoiceDetails, diff --git a/apps/hellgate/src/hg_invoice_template.erl b/apps/hellgate/src/hg_invoice_template.erl index 7d129b745..82c67972a 100644 --- a/apps/hellgate/src/hg_invoice_template.erl +++ b/apps/hellgate/src/hg_invoice_template.erl @@ -60,8 +60,7 @@ handle_function(Func, Args, Opts) -> -spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return(). handle_function_('Create', {UserInfo, Params}, _Opts) -> - %% FIXME(ED-95): temporary fallback generation till TemplateID is made required in damsel - TplID = hg_utils:uid(Params#payproc_InvoiceTemplateCreateParams.template_id), + TplID = Params#payproc_InvoiceTemplateCreateParams.template_id, ok = assume_user_identity(UserInfo), _ = set_meta(TplID), Party = get_party(Params#payproc_InvoiceTemplateCreateParams.party_id), diff --git a/apps/hellgate/src/hg_utils.erl b/apps/hellgate/src/hg_utils.erl index 435c055e2..d37a6baa4 100644 --- a/apps/hellgate/src/hg_utils.erl +++ b/apps/hellgate/src/hg_utils.erl @@ -1,7 +1,6 @@ -module(hg_utils). -export([unique_id/0]). --export([uid/1]). -export([logtag_process/2]). -export([unwrap_result/1]). -export([construct_complex_id/1]). @@ -20,14 +19,6 @@ unique_id() -> <> = snowflake:new(), genlib_format:format_int_base(ID, 62). --spec uid(undefined | dmsl_base_thrift:'ID'()) -> dmsl_base_thrift:'ID'(). -uid(undefined) -> - unique_id(); -uid(ID) when is_binary(ID) -> - ID. - -%% - -spec logtag_process(atom(), any()) -> ok. logtag_process(Key, Value) when is_atom(Key) -> logger:update_process_metadata(#{Key => Value}). diff --git a/apps/hellgate/test/hg_ct_helper.erl b/apps/hellgate/test/hg_ct_helper.erl index 2bf96b21c..c56a256af 100644 --- a/apps/hellgate/test/hg_ct_helper.erl +++ b/apps/hellgate/test/hg_ct_helper.erl @@ -26,13 +26,16 @@ -export([make_invoice_params/4]). -export([make_invoice_params/5]). +-export([make_invoice_params/6]). -export([make_invoice_params_tpl/1]). -export([make_invoice_params_tpl/2]). -export([make_invoice_params_tpl/3]). +-export([make_invoice_params_tpl/4]). -export([make_invoice_tpl_create_params/5]). -export([make_invoice_tpl_create_params/6]). +-export([make_invoice_tpl_create_params/7]). -export([make_invoice_tpl_details/2]). -export([make_invoice_tpl_update_params/1]). @@ -52,6 +55,7 @@ -export([make_disposable_payment_resource/1]). -export([make_customer_params/3]). +-export([make_customer_params/4]). -export([make_customer_binding_params/1]). -export([make_customer_binding_params/2]). -export([make_customer_binding_params/3]). @@ -333,6 +337,9 @@ make_user_identity(UserID) -> -include_lib("damsel/include/dmsl_payment_processing_thrift.hrl"). -include_lib("hellgate/include/party_events.hrl"). +-type customer_id() :: dmsl_domain_thrift:'CustomerID'(). +-type invoice_id() :: dmsl_domain_thrift:'InvoiceID'(). +-type invoice_template_id() :: dmsl_domain_thrift:'InvoiceTemplateID'(). -type party_id() :: dmsl_domain_thrift:'PartyID'(). -type user_info() :: dmsl_payment_processing_thrift:'UserInfo'(). -type account_id() :: dmsl_domain_thrift:'AccountID'(). @@ -551,7 +558,13 @@ make_invoice_params(PartyID, ShopID, Product, Cost) -> -spec make_invoice_params(party_id(), shop_id(), binary(), timestamp(), cash()) -> invoice_params(). make_invoice_params(PartyID, ShopID, Product, Due, Cost) -> + InvoiceID = hg_utils:unique_id(), + make_invoice_params(InvoiceID, PartyID, ShopID, Product, Due, Cost). + +-spec make_invoice_params(invoice_id(), party_id(), shop_id(), binary(), timestamp(), cash()) -> invoice_params(). +make_invoice_params(InvoiceID, PartyID, ShopID, Product, Due, Cost) -> #payproc_InvoiceParams{ + id = InvoiceID, party_id = PartyID, shop_id = ShopID, details = make_invoice_details(Product), @@ -570,7 +583,14 @@ make_invoice_params_tpl(TplID, Cost) -> -spec make_invoice_params_tpl(invoice_tpl_id(), undefined | cash(), undefined | context()) -> invoice_params_tpl(). make_invoice_params_tpl(TplID, Cost, Context) -> + InvoiceID = hg_utils:unique_id(), + make_invoice_params_tpl(InvoiceID, TplID, Cost, Context). + +-spec make_invoice_params_tpl(invoice_id(), invoice_tpl_id(), undefined | cash(), undefined | context()) -> + invoice_params_tpl(). +make_invoice_params_tpl(InvoiceID, TplID, Cost, Context) -> #payproc_InvoiceWithTemplateParams{ + id = InvoiceID, template_id = TplID, cost = Cost, context = Context @@ -590,7 +610,21 @@ make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details) -> context() ) -> invoice_tpl_create_params(). make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details, Context) -> + InvoiceTemplateID = hg_utils:unique_id(), + make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context). + +-spec make_invoice_tpl_create_params( + invoice_template_id(), + party_id(), + shop_id(), + lifetime_interval(), + binary(), + invoice_tpl_details(), + context() +) -> invoice_tpl_create_params(). +make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context) -> #payproc_InvoiceTemplateCreateParams{ + template_id = InvoiceTemplateID, party_id = PartyID, shop_id = ShopID, invoice_lifetime = Lifetime, @@ -720,7 +754,14 @@ get_hellgate_url() -> -spec make_customer_params(party_id(), shop_id(), binary()) -> dmsl_payment_processing_thrift:'CustomerParams'(). make_customer_params(PartyID, ShopID, EMail) -> + CustomerID = hg_utils:unique_id(), + make_customer_params(CustomerID, PartyID, ShopID, EMail). + +-spec make_customer_params(customer_id(), party_id(), shop_id(), binary()) -> + dmsl_payment_processing_thrift:'CustomerParams'(). +make_customer_params(CustomerID, PartyID, ShopID, EMail) -> #payproc_CustomerParams{ + customer_id = CustomerID, party_id = PartyID, shop_id = ShopID, contact_info = ?contact_info(EMail), @@ -730,19 +771,16 @@ make_customer_params(PartyID, ShopID, EMail) -> -spec make_customer_binding_params({dmsl_domain_thrift:'PaymentTool'(), dmsl_domain_thrift:'PaymentSessionID'()}) -> dmsl_payment_processing_thrift:'CustomerBindingParams'(). make_customer_binding_params(PaymentToolSession) -> - #payproc_CustomerBindingParams{ - payment_resource = make_disposable_payment_resource(PaymentToolSession) - }. + RecPaymentToolID = hg_utils:unique_id(), + make_customer_binding_params(RecPaymentToolID, PaymentToolSession). -spec make_customer_binding_params( dmsl_domain_thrift:'RecurrentPaymentToolID'(), {dmsl_domain_thrift:'PaymentTool'(), dmsl_domain_thrift:'PaymentSessionID'()} ) -> dmsl_payment_processing_thrift:'CustomerBindingParams'(). make_customer_binding_params(RecPayToolId, PaymentToolSession) -> - #payproc_CustomerBindingParams{ - rec_payment_tool_id = RecPayToolId, - payment_resource = make_disposable_payment_resource(PaymentToolSession) - }. + CustomerBindingID = hg_utils:unique_id(), + make_customer_binding_params(CustomerBindingID, RecPayToolId, PaymentToolSession). -spec make_customer_binding_params( dmsl_domain_thrift:'CustomerBindingID'(), diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index c1f522467..2f394902f 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -341,18 +341,18 @@ groups() -> {refunds, [], [ invalid_refund_party_status, invalid_refund_shop_status, - {refunds_, [parallel], [ + {parallel, [parallel], [ retry_temporary_unavailability_refund, payment_refund_idempotency, payment_refund_success, payment_refund_failure, - deadline_doesnt_affect_payment_refund, payment_partial_refunds_success, invalid_amount_payment_partial_refund, invalid_amount_partial_capture_and_refund, invalid_currency_payment_partial_refund, cant_start_simultaneous_partial_refunds ]}, + deadline_doesnt_affect_payment_refund, ineligible_payment_partial_refund, payment_manual_refund, payment_refund_id_types @@ -696,7 +696,7 @@ invalid_party_status(C) -> PartyID = cfg(party_id, C), InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), - InvoiceParamsWithTpl = make_invoice_params_tpl(TplID), + InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), ok = hg_client_party:suspend(PartyClient), {exception, #payproc_InvalidPartyStatus{ @@ -724,7 +724,7 @@ invalid_shop_status(C) -> PartyID = cfg(party_id, C), InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), - InvoiceParamsWithTpl = make_invoice_params_tpl(TplID), + InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), ok = hg_client_party:suspend_shop(ShopID, PartyClient), {exception, #payproc_InvalidShopStatus{ @@ -751,40 +751,40 @@ invalid_invoice_template_cost(C) -> Cost1 = make_tpl_cost(unlim, sale, "30%"), TplID = create_invoice_tpl(C, Cost1, Context), - Params1 = make_invoice_params_tpl(TplID), + Params1 = hg_ct_helper:make_invoice_params_tpl(TplID), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_NO_COST] }} = hg_client_invoicing:create_with_tpl(Params1, Client), Cost2 = make_tpl_cost(fixed, 100, <<"RUB">>), _ = update_invoice_tpl(TplID, Cost2, C), - Params2 = make_invoice_params_tpl(TplID, make_cash(50, <<"RUB">>)), + Params2 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(50, <<"RUB">>)), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_BAD_COST] }} = hg_client_invoicing:create_with_tpl(Params2, Client), - Params3 = make_invoice_params_tpl(TplID, make_cash(100, <<"KEK">>)), + Params3 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(100, <<"KEK">>)), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_BAD_COST] }} = hg_client_invoicing:create_with_tpl(Params3, Client), Cost3 = make_tpl_cost(range, {inclusive, 100, <<"RUB">>}, {inclusive, 10000, <<"RUB">>}), _ = update_invoice_tpl(TplID, Cost3, C), - Params4 = make_invoice_params_tpl(TplID, make_cash(50, <<"RUB">>)), + Params4 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(50, <<"RUB">>)), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_BAD_AMOUNT] }} = hg_client_invoicing:create_with_tpl(Params4, Client), - Params5 = make_invoice_params_tpl(TplID, make_cash(50000, <<"RUB">>)), + Params5 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(50000, <<"RUB">>)), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_BAD_AMOUNT] }} = hg_client_invoicing:create_with_tpl(Params5, Client), - Params6 = make_invoice_params_tpl(TplID, make_cash(500, <<"KEK">>)), + Params6 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(500, <<"KEK">>)), {exception, #'InvalidRequest'{ errors = [?INVOICE_TPL_BAD_CURRENCY] }} = hg_client_invoicing:create_with_tpl(Params6, Client), Cost4 = make_tpl_cost(fixed, 42000000000, <<"RUB">>), _ = update_invoice_tpl(TplID, Cost4, C), - Params7 = make_invoice_params_tpl(TplID, make_cash(42000000000, <<"RUB">>)), + Params7 = hg_ct_helper:make_invoice_params_tpl(TplID, make_cash(42000000000, <<"RUB">>)), {exception, #payproc_InvoiceTermsViolated{reason = {invoice_unpayable, _}}} = hg_client_invoicing:create_with_tpl(Params7, Client). @@ -793,12 +793,12 @@ invalid_invoice_template_id(C) -> Client = cfg(client, C), TplID1 = <<"Watsthat">>, - Params1 = make_invoice_params_tpl(TplID1), + Params1 = hg_ct_helper:make_invoice_params_tpl(TplID1), {exception, #payproc_InvoiceTemplateNotFound{}} = hg_client_invoicing:create_with_tpl(Params1, Client), TplID2 = create_invoice_tpl(C), _ = delete_invoice_tpl(TplID2, C), - Params2 = make_invoice_params_tpl(TplID2), + Params2 = hg_ct_helper:make_invoice_params_tpl(TplID2), {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoicing:create_with_tpl(Params2, Client). -spec invoive_w_template_idempotency(config()) -> _ | no_return(). @@ -817,9 +817,8 @@ invoive_w_template_idempotency(C) -> InvoiceID = hg_utils:unique_id(), ExternalID = hg_utils:unique_id(), - Params = make_invoice_params_tpl(TplID, InvoiceCost1, InvoiceContext1), + Params = hg_ct_helper:make_invoice_params_tpl(InvoiceID, TplID, InvoiceCost1, InvoiceContext1), Params1 = Params#payproc_InvoiceWithTemplateParams{ - id = InvoiceID, external_id = ExternalID }, ?invoice_state(#domain_Invoice{ @@ -832,9 +831,8 @@ invoive_w_template_idempotency(C) -> external_id = ExternalID }) = hg_client_invoicing:create_with_tpl(Params1, Client), - OtherParams = make_invoice_params_tpl(TplID), + OtherParams = hg_ct_helper:make_invoice_params_tpl(InvoiceID, TplID, undefined, undefined), Params2 = OtherParams#payproc_InvoiceWithTemplateParams{ - id = InvoiceID, external_id = hg_utils:unique_id() }, ?invoice_state(#domain_Invoice{ @@ -861,7 +859,7 @@ invoice_w_template(C) -> InvoiceCost1 = FixedCost, InvoiceContext1 = make_invoice_context(<<"invoice specific context">>), - Params1 = make_invoice_params_tpl(TplID, InvoiceCost1, InvoiceContext1), + Params1 = hg_ct_helper:make_invoice_params_tpl(TplID, InvoiceCost1, InvoiceContext1), ?invoice_state(#domain_Invoice{ owner_id = TplPartyID, shop_id = TplShopID, @@ -870,7 +868,7 @@ invoice_w_template(C) -> context = InvoiceContext1 }) = hg_client_invoicing:create_with_tpl(Params1, Client), - Params2 = make_invoice_params_tpl(TplID), + Params2 = hg_ct_helper:make_invoice_params_tpl(TplID), ?invoice_state(#domain_Invoice{ owner_id = TplPartyID, shop_id = TplShopID, @@ -1055,11 +1053,18 @@ refund_limit_success(C) -> ShopID = hg_ct_helper:create_party_and_shop(?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient), InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), - InvoiceID = create_invoice(InvoiceParams, Client), + InvoiceParams1 = InvoiceParams#payproc_InvoiceParams{ + id = hg_utils:unique_id() + }, + InvoiceID = create_invoice(InvoiceParams1, Client), [?invoice_created(?invoice_w_status(?invoice_unpaid()))] = next_event(InvoiceID, Client), PaymentID = execute_payment(InvoiceID, make_payment_params(), Client), - InvoiceID2 = create_invoice(InvoiceParams, Client), + InvoiceParams2 = InvoiceParams#payproc_InvoiceParams{ + id = hg_utils:unique_id() + }, + + InvoiceID2 = create_invoice(InvoiceParams2, Client), [?invoice_created(?invoice_w_status(?invoice_unpaid()))] = next_event(InvoiceID2, Client), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(), Client), @@ -4701,15 +4706,6 @@ make_invoice_params(PartyID, ShopID, Product, Cost) -> make_invoice_params(PartyID, ShopID, Product, Due, Cost) -> hg_ct_helper:make_invoice_params(PartyID, ShopID, Product, Due, Cost). -make_invoice_params_tpl(TplID) -> - hg_ct_helper:make_invoice_params_tpl(TplID). - -make_invoice_params_tpl(TplID, Cost) -> - hg_ct_helper:make_invoice_params_tpl(TplID, Cost). - -make_invoice_params_tpl(TplID, Cost, Context) -> - hg_ct_helper:make_invoice_params_tpl(TplID, Cost, Context). - make_invoice_context() -> hg_ct_helper:make_invoice_context(). diff --git a/rebar.lock b/rebar.lock index 4b3a0ce73..b556e8858 100644 --- a/rebar.lock +++ b/rebar.lock @@ -11,7 +11,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.9.1">>},2}, {<<"damsel">>, {git,"https://github.com/rbkmoney/damsel.git", - {ref,"908d8b4c701c38ee783e8e6012901526beb34c89"}}, + {ref,"eab641d9e1ca46673e37b9fbad9106d94f63042e"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/rbkmoney/dmt_client.git",