diff --git a/apps/hellgate/include/allocation.hrl b/apps/hellgate/include/allocation.hrl index 8f41e03b..e65eb0aa 100644 --- a/apps/hellgate/include/allocation.hrl +++ b/apps/hellgate/include/allocation.hrl @@ -73,10 +73,10 @@ body = Body }). --define(allocation_trx_target_shop(OwnerID, ShopID), +-define(allocation_trx_target_shop(PartyConfigRef, ShopConfigRef), {shop, #domain_AllocationTransactionTargetShop{ - owner_id = OwnerID, - shop_id = ShopID + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef }} ). diff --git a/apps/hellgate/include/hg_invoice.hrl b/apps/hellgate/include/hg_invoice.hrl index dfdbaf36..0e0f7920 100644 --- a/apps/hellgate/include/hg_invoice.hrl +++ b/apps/hellgate/include/hg_invoice.hrl @@ -6,7 +6,7 @@ invoice :: undefined | hg_invoice:invoice(), payments = [] :: [{hg_invoice:payment_id(), hg_invoice:payment_st()}], party :: undefined | hg_invoice:party(), - party_id :: undefined | hg_invoice:party_id() + party_config_ref :: undefined | hg_invoice:party_config_ref() }). -endif. diff --git a/apps/hellgate/src/hg_accounting.erl b/apps/hellgate/src/hg_accounting.erl index b4d1b8af..189db6ad 100644 --- a/apps/hellgate/src/hg_accounting.erl +++ b/apps/hellgate/src/hg_accounting.erl @@ -37,9 +37,9 @@ -type thrift_account() :: dmsl_accounter_thrift:'Account'(). -type payment() :: dmsl_domain_thrift:'InvoicePayment'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type route() :: hg_route:payment_route(). -type payment_institution() :: dmsl_domain_thrift:'PaymentInstitution'(). -type provider() :: dmsl_domain_thrift:'Provider'(). @@ -48,8 +48,8 @@ -type collect_account_context() :: #{ payment := payment(), - party_id := party_id(), - shop := {shop_id(), shop()}, + party_config_ref := party_config_ref(), + shop := {shop_config_ref(), shop()}, route := route(), payment_institution := payment_institution(), provider := provider(), @@ -101,7 +101,7 @@ create_account(CurrencyCode, Description) -> -spec collect_account_map(collect_account_context()) -> map(). collect_account_map(#{ payment := Payment, - party_id := PartyID, + party_config_ref := PartyConfigRef, shop := ShopObj, route := Route, payment_institution := PaymentInstitution, @@ -109,15 +109,15 @@ collect_account_map(#{ varset := VS, revision := Revision }) -> - Map0 = collect_merchant_account_map(PartyID, ShopObj, #{}), + Map0 = collect_merchant_account_map(PartyConfigRef, ShopObj, #{}), Map1 = collect_provider_account_map(Payment, Provider, Route, Map0), Map2 = collect_system_account_map(Payment, PaymentInstitution, Revision, Map1), collect_external_account_map(Payment, VS, Revision, Map2). --spec collect_merchant_account_map(party_id(), {shop_id(), shop()}, map()) -> map(). -collect_merchant_account_map(PartyID, {ShopID, #domain_ShopConfig{account = Account}}, Acc) -> +-spec collect_merchant_account_map(party_config_ref(), {shop_config_ref(), shop()}, map()) -> map(). +collect_merchant_account_map(PartyConfigRef, {ShopConfigRef, #domain_ShopConfig{account = Account}}, Acc) -> Acc#{ - merchant => {PartyID, ShopID}, + merchant => {PartyConfigRef, ShopConfigRef}, {merchant, settlement} => Account#domain_ShopAccount.settlement, {merchant, guarantee} => Account#domain_ShopAccount.guarantee }. diff --git a/apps/hellgate/src/hg_allocation.erl b/apps/hellgate/src/hg_allocation.erl index da9932b3..d505c144 100644 --- a/apps/hellgate/src/hg_allocation.erl +++ b/apps/hellgate/src/hg_allocation.erl @@ -22,11 +22,11 @@ -type party() :: dmsl_domain_thrift:'PartyConfig'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type party_id() :: dmsl_payproc_thrift:'PartyID'(). --type shop_id() :: dmsl_payproc_thrift:'ShopID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type target_map() :: #{ - party_id => party_id(), - shop_id => shop_id() + party_config_ref => party_config_ref(), + shop_config_ref => shop_config_ref() }. -type sub_errors() :: @@ -85,14 +85,14 @@ assert_allocatable(_Allocation, _PaymentAllocationServiceTerms, _Party, _Shop, _ {error, allocation_not_allowed}. -spec construct_target(target_map()) -> target(). -construct_target(#{party_id := PartyID, shop_id := ShopID}) -> - ?allocation_trx_target_shop(PartyID, ShopID). +construct_target(#{party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef}) -> + ?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef). --spec calculate(allocation_prototype(), party_id(), shop_id(), cash()) -> allocation(). -calculate(AllocationPrototype, PartyID, ShopID, Cost) -> +-spec calculate(allocation_prototype(), party_config_ref(), shop_config_ref(), cash()) -> allocation(). +calculate(AllocationPrototype, PartyConfigRef, ShopConfigRef, Cost) -> FeeTarget = construct_target(#{ - party_id => PartyID, - shop_id => ShopID + party_config_ref => PartyConfigRef, + shop_config_ref => ShopConfigRef }), calculate(AllocationPrototype, FeeTarget, Cost). diff --git a/apps/hellgate/src/hg_cashflow.erl b/apps/hellgate/src/hg_cashflow.erl index 57cfed83..986e6dce 100644 --- a/apps/hellgate/src/hg_cashflow.erl +++ b/apps/hellgate/src/hg_cashflow.erl @@ -17,7 +17,7 @@ -type account_id() :: dmsl_domain_thrift:'AccountID'(). -type account_map() :: #{ account() => account_id(), - merchant := {party_id(), shop_id()}, + merchant := {party_config_ref(), shop_config_ref()}, provider := route() }. -type context() :: dmsl_domain_thrift:'CashFlowContext'(). @@ -27,8 +27,8 @@ -type cash_volume() :: dmsl_domain_thrift:'CashVolume'(). -type final_cash_flow_account() :: dmsl_domain_thrift:'FinalCashFlowAccount'(). --type shop_id() :: dmsl_domain_thrift:'ShopID'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type route() :: hg_route:payment_route(). %% @@ -80,10 +80,10 @@ construct_final_account(AccountType, AccountMap) -> transaction_account = construct_transaction_account(AccountType, AccountMap) }. -construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyID, ShopID}}) -> +construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyConfigRef, ShopConfigRef}}) -> AccountOwner = #domain_MerchantTransactionAccountOwner{ - party_id = PartyID, - shop_id = ShopID + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef }, {merchant, #domain_MerchantTransactionAccount{ type = MerchantFlowAccount, diff --git a/apps/hellgate/src/hg_cashflow_utils.erl b/apps/hellgate/src/hg_cashflow_utils.erl index 119b02c2..fad186d8 100644 --- a/apps/hellgate/src/hg_cashflow_utils.erl +++ b/apps/hellgate/src/hg_cashflow_utils.erl @@ -10,8 +10,8 @@ -type cash_flow_context() :: #{ operation := refund | payment, provision_terms := dmsl_domain_thrift:'PaymentsProvisionTerms'(), - party := {party_id(), party()}, - shop := {shop_id(), shop()}, + party := {party_config_ref(), party()}, + shop := {shop_config_ref(), shop()}, route := route(), payment := payment(), provider := provider(), @@ -29,9 +29,9 @@ -export([collect_cashflow/2]). -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type route() :: dmsl_domain_thrift:'PaymentRoute'(). -type payment() :: dmsl_domain_thrift:'InvoicePayment'(). -type refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'(). @@ -70,12 +70,13 @@ collect_allocation_cash_flow( ) -> lists:foldl( fun(?allocation_trx(_ID, Target, Amount), Acc) -> - ?allocation_trx_target_shop(PartyID, ShopID) = Target, - {PartyID, TargetParty} = hg_party:get_party(PartyID), - {ShopID, TargetShop} = hg_party:get_shop(ShopID, TargetParty, Revision), + ?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef) = Target, + {PartyConfigRef, TargetParty} = hg_party:get_party(PartyConfigRef), + {#domain_ShopConfigRef{id = ShopConfigID} = ShopConfigRef, TargetShop} = + hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), VS1 = VS0#{ - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_id => ShopConfigID, cost => Amount }, AllocationPaymentInstitution = @@ -83,7 +84,7 @@ collect_allocation_cash_flow( construct_transaction_cashflow( Amount, AllocationPaymentInstitution, - Context#{party => {PartyID, TargetParty}, shop => {ShopID, TargetShop}} + Context#{party => {PartyConfigRef, TargetParty}, shop => {ShopConfigRef, TargetShop}} ) ++ Acc end, [], @@ -161,7 +162,7 @@ get_selector_value(Name, Selector) -> hg_accounting:collect_account_context(). make_collect_account_context(PaymentInstitution, #{ payment := Payment, - party := {PartyID, _}, + party := {PartyConfigRef, _}, shop := Shop, route := Route, provider := Provider, @@ -170,7 +171,7 @@ make_collect_account_context(PaymentInstitution, #{ }) -> #{ payment => Payment, - party_id => PartyID, + party_config_ref => PartyConfigRef, shop => Shop, route => Route, payment_institution => PaymentInstitution, diff --git a/apps/hellgate/src/hg_inspector.erl b/apps/hellgate/src/hg_inspector.erl index e980abd9..4efd5d5d 100644 --- a/apps/hellgate/src/hg_inspector.erl +++ b/apps/hellgate/src/hg_inspector.erl @@ -105,8 +105,8 @@ get_payment_info( location = Location }, #domain_Invoice{ - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, id = InvoiceID, created_at = InvoiceCreatedAt, due = InvoiceDue, @@ -123,14 +123,14 @@ get_payment_info( } ) -> Party = #proxy_inspector_Party{ - party_id = PartyID + party_ref = PartyConfigRef }, ShopCategory = hg_domain:get( Revision, {category, CategoryRef} ), ProxyShop = #proxy_inspector_Shop{ - id = ShopID, + shop_ref = ShopConfigRef, category = ShopCategory, name = Shop#domain_ShopConfig.name, description = Shop#domain_ShopConfig.description, diff --git a/apps/hellgate/src/hg_invoice.erl b/apps/hellgate/src/hg_invoice.erl index d199ddec..ad4822d0 100644 --- a/apps/hellgate/src/hg_invoice.erl +++ b/apps/hellgate/src/hg_invoice.erl @@ -31,7 +31,7 @@ -export_type([payment_id/0]). -export_type([payment_st/0]). -export_type([party/0]). --export_type([party_id/0]). +-export_type([party_config_ref/0]). %% Public interface @@ -77,7 +77,7 @@ -type invoice() :: dmsl_domain_thrift:'Invoice'(). -type allocation() :: dmsl_domain_thrift:'Allocation'(). -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type revision() :: dmt_client:vsn(). -type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'(). @@ -109,17 +109,17 @@ get_payment(PaymentID, St) -> -spec get_payment_opts(st()) -> hg_invoice_payment:opts(). get_payment_opts(St = #st{invoice = Invoice, party = undefined}) -> - {PartyID, Party} = hg_party:get_party(get_party_id(St)), + {PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)), #{ party => Party, - party_id => PartyID, + party_config_ref => PartyConfigRef, invoice => Invoice, timestamp => hg_datetime:format_now() }; -get_payment_opts(#st{invoice = Invoice, party = Party, party_id = PartyID}) -> +get_payment_opts(#st{invoice = Invoice, party = Party, party_config_ref = PartyConfigRef}) -> #{ party => Party, - party_id => PartyID, + party_config_ref => PartyConfigRef, invoice => Invoice, timestamp => hg_datetime:format_now() }. @@ -127,10 +127,10 @@ get_payment_opts(#st{invoice = Invoice, party = Party, party_id = PartyID}) -> -spec get_payment_opts(hg_domain:revision(), st()) -> hg_invoice_payment:opts(). get_payment_opts(Revision, St = #st{invoice = Invoice}) -> - {PartyID, Party} = hg_party:checkout(get_party_id(St), Revision), + {PartyConfigRef, Party} = hg_party:checkout(get_party_config_ref(St), Revision), #{ party => Party, - party_id => PartyID, + party_config_ref => PartyConfigRef, invoice => Invoice, timestamp => hg_datetime:format_now() }. @@ -145,13 +145,13 @@ get_payment_opts(Revision, St = #st{invoice = Invoice}) -> ) -> invoice(). create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations, DomainRevision) -> - OwnerID = V#payproc_InvoiceParams.party_id, - ShopID = V#payproc_InvoiceParams.shop_id, + PartyConfigRef = V#payproc_InvoiceParams.party_id, + ShopConfigRef = V#payproc_InvoiceParams.shop_id, Cost = V#payproc_InvoiceParams.cost, hg_invoice_mutation:apply_mutations(Mutations, #domain_Invoice{ id = ID, - shop_id = ShopID, - owner_id = OwnerID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, created_at = hg_datetime:format_now(), status = ?invoice_unpaid(), cost = Cost, @@ -169,13 +169,13 @@ assert_invoice(Checks, #st{} = St) when is_list(Checks) -> lists:foldl(fun assert_invoice/2, St, Checks); assert_invoice(operable, #st{party = Party} = St) when Party =/= undefined -> assert_party_shop_operable( - hg_party:get_shop(get_shop_id(St), Party, hg_party:get_party_revision()), + hg_party:get_shop(get_shop_config_ref(St), get_party_config_ref(St), hg_party:get_party_revision()), Party ), St; assert_invoice(unblocked, #st{party = Party} = St) when Party =/= undefined -> assert_party_shop_unblocked( - hg_party:get_shop(get_shop_id(St), Party, hg_party:get_party_revision()), + hg_party:get_shop(get_shop_config_ref(St), get_party_config_ref(St), hg_party:get_party_revision()), Party ), St; @@ -898,14 +898,14 @@ check_non_idle_payments_([{PaymentID, PaymentSession} | Rest], St) -> end. add_party_to_st(St) -> - {PartyID, Party} = hg_party:get_party(get_party_id(St)), - St#st{party = Party, party_id = PartyID}. + {PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)), + St#st{party = Party, party_config_ref = PartyConfigRef}. -get_party_id(#st{invoice = #domain_Invoice{owner_id = PartyID}}) -> - PartyID. +get_party_config_ref(#st{invoice = #domain_Invoice{party_ref = PartyConfigRef}}) -> + PartyConfigRef. -get_shop_id(#st{invoice = #domain_Invoice{shop_id = ShopID}}) -> - ShopID. +get_shop_config_ref(#st{invoice = #domain_Invoice{shop_ref = ShopConfigRef}}) -> + ShopConfigRef. get_payment_session(PaymentID, St) -> case try_get_payment_session(PaymentID, St) of @@ -970,11 +970,16 @@ get_invoice_event_log(EventType, StatusName, Invoice) -> get_invoice_params(Invoice) -> #domain_Invoice{ id = ID, - owner_id = PartyID, cost = ?cash(Amount, Currency), - shop_id = ShopID + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef } = Invoice, - [{id, ID}, {owner_id, PartyID}, {cost, [{amount, Amount}, {currency, Currency}]}, {shop_id, ShopID}]. + [ + {id, ID}, + {party_ref, PartyConfigRef}, + {shop_ref, ShopConfigRef}, + {cost, [{amount, Amount}, {currency, Currency}]} + ]. get_message(invoice_created) -> "Invoice is created"; diff --git a/apps/hellgate/src/hg_invoice_handler.erl b/apps/hellgate/src/hg_invoice_handler.erl index cda145ca..582b5400 100644 --- a/apps/hellgate/src/hg_invoice_handler.erl +++ b/apps/hellgate/src/hg_invoice_handler.erl @@ -35,16 +35,16 @@ handle_function_('Create', {InvoiceParams}, _Opts) -> DomainRevision = hg_domain:head(), InvoiceID = InvoiceParams#payproc_InvoiceParams.id, _ = set_invoicing_meta(InvoiceID), - PartyID = InvoiceParams#payproc_InvoiceParams.party_id, - ShopID = InvoiceParams#payproc_InvoiceParams.shop_id, - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = assert_shop_exists(hg_party:get_shop(ShopID, Party, DomainRevision)), + PartyConfigRef = InvoiceParams#payproc_InvoiceParams.party_id, + #domain_ShopConfigRef{id = ShopConfigID} = ShopConfigRef = InvoiceParams#payproc_InvoiceParams.shop_id, + {PartyConfigRef, Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = assert_shop_exists(hg_party:get_shop(ShopConfigRef, PartyConfigRef, DomainRevision)), _ = assert_party_shop_operable(Shop, Party), ok = validate_invoice_mutations(InvoiceParams), {Cost, Mutations} = maybe_make_mutations(InvoiceParams), VS = #{ cost => Cost, - shop_id => ShopID + shop_id => ShopConfigID }, MerchantTerms = hg_invoice_utils:compute_shop_terms(DomainRevision, Shop, VS), ok = validate_invoice_params(InvoiceParams, Shop, MerchantTerms), @@ -55,12 +55,12 @@ handle_function_('CreateWithTemplate', {Params}, _Opts) -> InvoiceID = Params#payproc_InvoiceWithTemplateParams.id, _ = set_invoicing_meta(InvoiceID), TplID = Params#payproc_InvoiceWithTemplateParams.template_id, - {_Party, {ShopID, Shop}, InvoiceParams} = make_invoice_params(Params), + {_Party, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, InvoiceParams} = make_invoice_params(Params), ok = validate_invoice_mutations(InvoiceParams), {Cost, Mutations} = maybe_make_mutations(InvoiceParams), VS = #{ cost => Cost, - shop_id => ShopID + shop_id => ShopConfigID }, MerchantTerms = hg_invoice_utils:compute_shop_terms(DomainRevision, Shop, VS), ok = validate_invoice_params(InvoiceParams, Shop, MerchantTerms), @@ -100,13 +100,14 @@ handle_function_('ComputeTerms', {InvoiceID}, _Opts) -> _ = set_invoicing_meta(InvoiceID), St = get_state(InvoiceID), DomainRevision = hg_domain:head(), - {PartyID, Party} = hg_party:get_party(get_party_id(St)), - {ShopID, Shop} = assert_shop_exists(hg_party:get_shop(get_shop_id(St), Party, DomainRevision)), + {PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)), + {#domain_ShopConfigRef{id = ShopConfigID}, Shop} = + assert_shop_exists(hg_party:get_shop(get_shop_config_ref(St), PartyConfigRef, DomainRevision)), _ = assert_party_shop_operable(Shop, Party), VS = #{ cost => get_cost(St), - shop_id => ShopID, - party_id => PartyID, + shop_id => ShopConfigID, + party_config_ref => PartyConfigRef, category => Shop#domain_ShopConfig.category, currency => hg_invoice_utils:get_shop_currency(Shop) }, @@ -248,11 +249,11 @@ map_history_error({error, notfound}) -> %% -get_party_id(#st{invoice = #domain_Invoice{owner_id = PartyID}}) -> - PartyID. +get_party_config_ref(#st{invoice = #domain_Invoice{party_ref = PartyConfigRef}}) -> + PartyConfigRef. -get_shop_id(#st{invoice = #domain_Invoice{shop_id = ShopID}}) -> - ShopID. +get_shop_config_ref(#st{invoice = #domain_Invoice{shop_ref = ShopConfigRef}}) -> + ShopConfigRef. get_cost(#st{invoice = #domain_Invoice{cost = Cash}}) -> Cash. @@ -284,8 +285,8 @@ make_invoice_params(Params) -> external_id = ExternalID } = Params, #domain_InvoiceTemplate{ - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, invoice_lifetime = Lifetime, product = Product, description = Description, @@ -294,8 +295,8 @@ make_invoice_params(Params) -> mutations = MutationsParams } = hg_invoice_template:get(TplID), DomainRevision = hg_domain:head(), - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = assert_shop_exists(hg_party:get_shop(ShopID, Party, DomainRevision)), + {PartyConfigRef, Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = assert_shop_exists(hg_party:get_shop(ShopConfigRef, PartyConfigRef, DomainRevision)), _ = assert_party_shop_operable(Shop, Party), Cart = make_invoice_cart(Cost, TplDetails, Shop), InvoiceDetails = #domain_InvoiceDetails{ @@ -308,8 +309,8 @@ make_invoice_params(Params) -> InvoiceContext = make_invoice_context(Context, TplContext), InvoiceParams = #payproc_InvoiceParams{ id = InvoiceID, - party_id = PartyID, - shop_id = ShopID, + party_id = PartyConfigRef, + shop_id = ShopConfigRef, details = InvoiceDetails, due = InvoiceDue, cost = InvoiceCost, @@ -317,7 +318,7 @@ make_invoice_params(Params) -> external_id = ExternalID, mutations = MutationsParams }, - {{PartyID, Party}, {ShopID, Shop}, InvoiceParams}. + {{PartyConfigRef, Party}, {ShopConfigRef, Shop}, InvoiceParams}. validate_invoice_params(#payproc_InvoiceParams{cost = Cost}, Shop, MerchantTerms) -> ok = validate_invoice_cost(Cost, Shop, MerchantTerms), diff --git a/apps/hellgate/src/hg_invoice_mutation.erl b/apps/hellgate/src/hg_invoice_mutation.erl index 7c66d49d..b06caa43 100644 --- a/apps/hellgate/src/hg_invoice_mutation.erl +++ b/apps/hellgate/src/hg_invoice_mutation.erl @@ -164,8 +164,8 @@ calc_deviation(MaxDeviation, PrecisionFactor) -> -define(invoice_w_cart(Amount, Cart, Mutations), #domain_Invoice{ id = <<"invoice">>, - shop_id = <<"shop_id">>, - owner_id = <<"owner_id">>, + shop_ref = #domain_ShopConfigRef{id = <<"shop_ref">>}, + party_ref = #domain_PartyConfigRef{id = <<"party_ref">>}, created_at = <<"1970-01-01T00:00:00Z">>, domain_revision = 1223, status = {unpaid, #domain_InvoiceUnpaid{}}, diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 4ee61fc7..bc48ef3a 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -172,7 +172,7 @@ -type cash() :: dmsl_domain_thrift:'Cash'(). -type cart() :: dmsl_domain_thrift:'InvoiceCart'(). -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type payer() :: dmsl_domain_thrift:'Payer'(). -type payer_params() :: dmsl_payproc_thrift:'PayerParams'(). -type invoice() :: dmsl_domain_thrift:'Invoice'(). @@ -209,7 +209,7 @@ -type payment_session() :: dmsl_payproc_thrift:'InvoicePaymentSession'(). -type failure() :: dmsl_domain_thrift:'OperationFailure'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type payment_tool() :: dmsl_domain_thrift:'PaymentTool'(). -type recurrent_paytool_service_terms() :: dmsl_domain_thrift:'RecurrentPaytoolsServiceTerms'(). -type session() :: hg_session:t(). @@ -218,7 +218,7 @@ -type opts() :: #{ party => party(), - party_id => party_id(), + party_config_ref => party_config_ref(), invoice => invoice(), timestamp => hg_datetime:timestamp() }. @@ -416,19 +416,19 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt}) -> processing_deadline = Deadline } = Params, Revision = hg_domain:head(), - PartyID = get_party_id(Opts), + PartyConfigRef = get_party_config_ref(Opts), ShopObj = get_shop_obj(Opts, Revision), Invoice = get_invoice(Opts), Cost = #domain_Cash{currency = Currency} = get_invoice_cost(Invoice), {ok, Payer, VS0} = construct_payer(PayerParams), - VS1 = collect_validation_varset_(PartyID, ShopObj, Currency, VS0), + VS1 = collect_validation_varset_(PartyConfigRef, ShopObj, Currency, VS0), Payment1 = construct_payment( PaymentID, CreatedAt, Cost, Payer, FlowParams, - PartyID, + PartyConfigRef, ShopObj, VS1, Revision, @@ -497,8 +497,8 @@ construct_payment( Cost, Payer, FlowParams, - PartyID, - {ShopID, Shop} = ShopObj, + PartyConfigRef, + {ShopConfigRef, Shop} = ShopObj, VS0, Revision, MakeRecurrent @@ -529,8 +529,8 @@ construct_payment( #domain_InvoicePayment{ id = PaymentID, created_at = CreatedAt, - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, domain_revision = Revision, status = ?pending(), cost = Cost, @@ -588,7 +588,7 @@ validate_hold_lifetime(undefined, _PaymentTool) -> payer(), recurrent_paytool_service_terms(), payment_tool(), - {shop_id(), shop()}, + {shop_config_ref(), shop()}, payment(), make_recurrent() ) -> ok | no_return(). @@ -631,7 +631,7 @@ validate_recurrent_terms(RecurrentTerms, PaymentTool) -> end, ok. --spec validate_recurrent_parent({shop_id(), shop()}, st()) -> ok | no_return(). +-spec validate_recurrent_parent({shop_config_ref(), shop()}, st()) -> ok | no_return(). validate_recurrent_parent(ShopObj, ParentPayment) -> ok = validate_recurrent_token_present(ParentPayment), ok = validate_recurrent_parent_shop(ShopObj, ParentPayment), @@ -646,10 +646,10 @@ validate_recurrent_token_present(PaymentState) -> throw_invalid_recurrent_parent(<<"Parent payment has no recurrent token">>) end. --spec validate_recurrent_parent_shop({shop_id(), shop()}, st()) -> ok | no_return(). -validate_recurrent_parent_shop({ShopID, _}, PaymentState) -> - PaymentShopID = get_payment_shop_id(get_payment(PaymentState)), - case ShopID =:= PaymentShopID of +-spec validate_recurrent_parent_shop({shop_config_ref(), shop()}, st()) -> ok | no_return(). +validate_recurrent_parent_shop({ShopConfigRef, _}, PaymentState) -> + PaymentShopConfigRef = get_payment_shop_config_ref(get_payment(PaymentState)), + case ShopConfigRef =:= PaymentShopConfigRef of true -> ok; false -> @@ -815,23 +815,23 @@ collect_partial_refund_varset(undefined) -> collect_validation_varset(St, Opts) -> Revision = get_payment_revision(St), - collect_validation_varset(get_party_id(Opts), get_shop_obj(Opts, Revision), get_payment(St), #{}). + collect_validation_varset(get_party_config_ref(Opts), get_shop_obj(Opts, Revision), get_payment(St), #{}). -collect_validation_varset(PartyID, ShopObj, Payment, VS) -> +collect_validation_varset(PartyConfigRef, ShopObj, Payment, VS) -> Cost = #domain_Cash{currency = Currency} = get_payment_cost(Payment), - VS0 = collect_validation_varset_(PartyID, ShopObj, Currency, VS), + VS0 = collect_validation_varset_(PartyConfigRef, ShopObj, Currency, VS), VS0#{ cost => Cost, payment_tool => get_payment_tool(Payment) }. -collect_validation_varset_(PartyID, {ShopID, Shop}, Currency, VS) -> +collect_validation_varset_(PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Currency, VS) -> #domain_ShopConfig{ category = Category } = Shop, VS#{ - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_id => ShopConfigID, category => Category, currency => Currency }. @@ -2053,7 +2053,7 @@ process_cash_flow_building(Action, St) -> Payment = get_payment(St), Timestamp = get_payment_created_at(Payment), VS0 = reconstruct_payment_flow(Payment, #{}), - VS1 = collect_validation_varset(get_party_id(Opts), get_shop_obj(Opts, Revision), Payment, VS0), + VS1 = collect_validation_varset(get_party_config_ref(Opts), get_shop_obj(Opts, Revision), Payment, VS0), ProviderTerms = get_provider_terminal_terms(Route, VS1, Revision), Allocation = get_allocation(St), Context = #{ @@ -2483,7 +2483,7 @@ get_provider_terms(St, Revision) -> Route = get_route(St), Payment = get_payment(St), VS0 = reconstruct_payment_flow(Payment, #{}), - VS1 = collect_validation_varset(get_party_id(Opts), get_shop_obj(Opts, Revision), Payment, VS0), + VS1 = collect_validation_varset(get_party_config_ref(Opts), get_shop_obj(Opts, Revision), Payment, VS0), hg_routing:get_payment_terms(Route, VS1, Revision). filter_routes_with_limit_hold(Ctx0, VS, Iter, St) -> @@ -2531,40 +2531,40 @@ hold_shop_limits(Opts, St) -> Payment = get_payment(St), Revision = get_payment_revision(St), Invoice = get_invoice(Opts), - PartyID = get_party_id(Opts), - {ShopID, Shop} = get_shop_obj(Opts, Revision), + PartyConfigRef = get_party_config_ref(Opts), + {ShopConfigRef, Shop} = get_shop_obj(Opts, Revision), TurnoverLimits = get_shop_turnover_limits(Shop), - ok = hg_limiter:hold_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment). + ok = hg_limiter:hold_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment). commit_shop_limits(Opts, St) -> Payment = get_payment(St), Revision = get_payment_revision(St), Invoice = get_invoice(Opts), - PartyID = get_party_id(Opts), - {ShopID, Shop} = get_shop_obj(Opts, Revision), + PartyConfigRef = get_party_config_ref(Opts), + {ShopConfigRef, Shop} = get_shop_obj(Opts, Revision), TurnoverLimits = get_shop_turnover_limits(Shop), - ok = hg_limiter:commit_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment). + ok = hg_limiter:commit_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment). check_shop_limits(Opts, St) -> Payment = get_payment(St), Revision = get_payment_revision(St), Invoice = get_invoice(Opts), - PartyID = get_party_id(Opts), - {ShopID, Shop} = get_shop_obj(Opts, Revision), + PartyConfigRef = get_party_config_ref(Opts), + {ShopConfigRef, Shop} = get_shop_obj(Opts, Revision), TurnoverLimits = get_shop_turnover_limits(Shop), - hg_limiter:check_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment). + hg_limiter:check_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment). rollback_shop_limits(Opts, St, Flags) -> Payment = get_payment(St), Revision = get_payment_revision(St), Invoice = get_invoice(Opts), - PartyID = get_party_id(Opts), - {ShopID, Shop} = get_shop_obj(Opts, Revision), + PartyConfigRef = get_party_config_ref(Opts), + {ShopConfigRef, Shop} = get_shop_obj(Opts, Revision), TurnoverLimits = get_shop_turnover_limits(Shop), ok = hg_limiter:rollback_shop_limits( TurnoverLimits, - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, Invoice, Payment, Flags @@ -2842,15 +2842,17 @@ construct_proxy_invoice( }. construct_proxy_shop( - {ShopID, + { + #domain_ShopConfigRef{id = ShopConfigID}, Shop = #domain_ShopConfig{ location = Location, category = ShopCategoryRef - }} + } + } ) -> ShopCategory = hg_domain:get({category, ShopCategoryRef}), #proxy_provider_Shop{ - id = ShopID, + id = ShopConfigID, category = ShopCategory, name = Shop#domain_ShopConfig.name, description = Shop#domain_ShopConfig.description, @@ -2873,21 +2875,21 @@ construct_proxy_capture(?captured(_, Cost)) -> %% -get_party_obj(#{party := Party, party_id := PartyID}) -> - {PartyID, Party}. +get_party_obj(#{party := Party, party_config_ref := PartyConfigRef}) -> + {PartyConfigRef, Party}. get_party(#{party := Party}) -> Party. -get_party_id(#{party_id := PartyID}) -> - PartyID. +get_party_config_ref(#{party_config_ref := PartyConfigRef}) -> + PartyConfigRef. -get_shop(#{party := Party, invoice := Invoice}, Revision) -> - {_, Shop} = hg_party:get_shop(get_invoice_shop_id(Invoice), Party, Revision), +get_shop(Opts, Revision) -> + {_, Shop} = get_shop_obj(Opts, Revision), Shop. -get_shop_obj(#{party := Party, invoice := Invoice}, Revision) -> - hg_party:get_shop(get_invoice_shop_id(Invoice), Party, Revision). +get_shop_obj(#{invoice := Invoice, party_config_ref := PartyConfigRef}, Revision) -> + hg_party:get_shop(get_invoice_shop_config_ref(Invoice), PartyConfigRef, Revision). get_payment_institution_ref(Opts, Revision) -> Shop = get_shop(Opts, Revision), @@ -2903,8 +2905,8 @@ get_invoice_id(#domain_Invoice{id = ID}) -> get_invoice_cost(#domain_Invoice{cost = Cost}) -> Cost. -get_invoice_shop_id(#domain_Invoice{shop_id = ShopID}) -> - ShopID. +get_invoice_shop_config_ref(#domain_Invoice{shop_ref = ShopConfigRef}) -> + ShopConfigRef. get_payment_id(#domain_InvoicePayment{id = ID}) -> ID. @@ -2917,8 +2919,8 @@ get_payment_cost(#domain_InvoicePayment{cost = Cost}) -> get_payment_flow(#domain_InvoicePayment{flow = Flow}) -> Flow. -get_payment_shop_id(#domain_InvoicePayment{shop_id = ShopID}) -> - ShopID. +get_payment_shop_config_ref(#domain_InvoicePayment{shop_ref = ShopConfigRef}) -> + ShopConfigRef. get_payment_tool(#domain_InvoicePayment{payer = Payer}) -> get_payer_payment_tool(Payer). @@ -2964,7 +2966,7 @@ get_varset(St, InitialValue) -> Payment = get_payment(St), Revision = get_payment_revision(St), VS0 = reconstruct_payment_flow(Payment, InitialValue), - VS1 = collect_validation_varset(get_party_id(Opts), get_shop_obj(Opts, Revision), Payment, VS0), + VS1 = collect_validation_varset(get_party_config_ref(Opts), get_shop_obj(Opts, Revision), Payment, VS0), VS1. %% @@ -3356,15 +3358,15 @@ latest_adjustment_id(#st{adjustments = Adjustments}) -> get_routing_attempt_limit( St = #st{ payment = #domain_InvoicePayment{ - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, domain_revision = Revision } } ) -> - {PartyID, Party} = hg_party:checkout(PartyID, Revision), - ShopObj = {_, Shop} = hg_party:get_shop(ShopID, Party, Revision), - VS = collect_validation_varset(PartyID, ShopObj, get_payment(St), #{}), + {PartyConfigRef, _Party} = hg_party:checkout(PartyConfigRef, Revision), + ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), + VS = collect_validation_varset(PartyConfigRef, ShopObj, get_payment(St), #{}), Terms = hg_invoice_utils:compute_shop_terms(Revision, Shop, VS), #domain_TermSet{payments = PaymentTerms} = Terms, log_cascade_attempt_context(PaymentTerms, St), diff --git a/apps/hellgate/src/hg_invoice_payment_chargeback.erl b/apps/hellgate/src/hg_invoice_payment_chargeback.erl index 203bca34..e89887e9 100644 --- a/apps/hellgate/src/hg_invoice_payment_chargeback.erl +++ b/apps/hellgate/src/hg_invoice_payment_chargeback.erl @@ -72,7 +72,7 @@ -type opts() :: #{ party => party(), - party_id => party_id(), + party_config_ref => party_config_ref(), payment_state := payment_state(), party := party(), invoice := invoice() @@ -84,8 +84,8 @@ -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: - dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: + dmsl_domain_thrift:'PartyConfigRef'(). -type invoice() :: dmsl_domain_thrift:'Invoice'(). @@ -285,12 +285,12 @@ do_create(Opts, CreateParams = ?chargeback_params(Levy, Body, _Reason)) -> CreatedAt = hg_datetime:format_now(), Invoice = get_opts_invoice(Opts), Party = get_opts_party(Opts), - PartyID = get_opts_party_id(Opts), + PartyConfigRef = get_opts_party_config_ref(Opts), Route = get_opts_route(Opts), Payment = get_opts_payment(Opts), - ShopID = get_invoice_shop_id(Invoice), - ShopObj = {_, Shop} = hg_party:get_shop(ShopID, Party, Revision), - VS = collect_validation_varset(PartyID, ShopObj, Payment, Body), + ShopConfigRef = get_invoice_shop_config_ref(Invoice), + ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), + VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body), PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision), ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment), ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt), @@ -422,10 +422,10 @@ build_chargeback_final_cash_flow(State, Opts) -> Invoice = get_opts_invoice(Opts), Route = get_opts_route(Opts), Party = get_opts_party(Opts), - PartyID = get_opts_party_id(Opts), - ShopID = get_invoice_shop_id(Invoice), - ShopObj = {_, Shop} = hg_party:get_shop(ShopID, Party, Revision), - VS = collect_validation_varset(PartyID, ShopObj, Payment, Body), + PartyConfigRef = get_opts_party_config_ref(Opts), + ShopConfigRef = get_invoice_shop_config_ref(Invoice), + ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), + VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body), ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt), PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision), ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment), @@ -437,7 +437,7 @@ build_chargeback_final_cash_flow(State, Opts) -> Provider = get_route_provider(Route, Revision), CollectAccountContext = #{ payment => Payment, - party_id => PartyID, + party_config_ref => PartyConfigRef, shop => ShopObj, route => Route, payment_institution => PaymentInst, @@ -519,14 +519,14 @@ construct_chargeback_plan_id(State, Opts) -> genlib:to_binary(Stage) ]). -collect_validation_varset(PartyID, {ShopID, Shop}, Payment, Body) -> +collect_validation_varset(PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Payment, Body) -> #domain_InvoicePayment{cost = #domain_Cash{currency = Currency}} = Payment, #domain_ShopConfig{ category = Category } = Shop, #{ - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_id => ShopConfigID, category => Category, currency => Currency, cost => Body, @@ -721,8 +721,8 @@ get_route_provider(#domain_PaymentRoute{provider = ProviderRef}, Revision) -> get_opts_party(#{party := Party}) -> Party. -get_opts_party_id(#{party_id := PartyID}) -> - PartyID. +get_opts_party_config_ref(#{party_config_ref := PartyConfigRef}) -> + PartyConfigRef. get_opts_invoice(#{invoice := Invoice}) -> Invoice. @@ -759,8 +759,8 @@ get_resource_payment_tool(#domain_DisposablePaymentResource{payment_tool = Payme %% -get_invoice_shop_id(#domain_Invoice{shop_id = ShopID}) -> - ShopID. +get_invoice_shop_config_ref(#domain_Invoice{shop_ref = ShopConfigRef}) -> + ShopConfigRef. %% diff --git a/apps/hellgate/src/hg_invoice_payment_refund.erl b/apps/hellgate/src/hg_invoice_payment_refund.erl index 4aa42256..73acf988 100644 --- a/apps/hellgate/src/hg_invoice_payment_refund.erl +++ b/apps/hellgate/src/hg_invoice_payment_refund.erl @@ -78,11 +78,11 @@ %% Internal types -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type invoice() :: dmsl_domain_thrift:'Invoice'(). -type payment() :: dmsl_domain_thrift:'InvoicePayment'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type invoice_id() :: dmsl_domain_thrift:'InvoiceID'(). -type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'(). -type domain_refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'(). @@ -116,11 +116,11 @@ -type injected_context() :: #{ party := party(), - party_id := party_id(), + party_config_ref := party_config_ref(), invoice := invoice(), payment := payment(), shop := shop(), - shop_id := shop_id(), + shop_config_ref := shop_config_ref(), invoice_id := invoice_id(), payment_id := payment_id(), repair_scenario => repair_scenario(), @@ -129,7 +129,7 @@ -type options() :: #{ party => party(), - party_id => party_id(), + party_config_ref => party_config_ref(), invoice => invoice(), timestamp => hg_datetime:timestamp(), @@ -275,13 +275,13 @@ do_process(finished, _Refund) -> process_refund_cashflow(Refund) -> Action = hg_machine_action:set_timeout(0, hg_machine_action:new()), - PartyID = get_injected_party_id(Refund), - ShopID = get_injected_shop_id(Refund), + PartyConfigRef = get_injected_party_config_ref(Refund), + ShopConfigRef = get_injected_shop_config_ref(Refund), Shop = get_injected_shop(Refund), hold_refund_limits(Refund), #{{merchant, settlement} := SettlementID} = hg_accounting:collect_merchant_account_map( - PartyID, {ShopID, Shop}, #{} + PartyConfigRef, {ShopConfigRef, Shop}, #{} ), _ = prepare_refund_cashflow(Refund), % NOTE we assume that posting involving merchant settlement account MUST be present in the cashflow @@ -371,16 +371,16 @@ rollback_refund_limits(Refund) -> get_limits(Refund) -> Revision = revision(Refund), ProviderTerms = get_provider_terms( - Revision, get_injected_payment(Refund), get_injected_invoice(Refund), get_injected_party(Refund), Refund + Revision, get_injected_payment(Refund), get_injected_invoice(Refund), Refund ), get_turnover_limits(ProviderTerms). -get_provider_terms(Revision, Payment, Invoice, Party, Refund) -> +get_provider_terms(Revision, Payment, Invoice, Refund) -> Route = route(Refund), - #domain_Invoice{shop_id = ShopID} = Invoice, - ShopObj = hg_party:get_shop(ShopID, Party, Revision), + #domain_Invoice{shop_ref = ShopConfigRef, party_ref = PartyConfigRef} = Invoice, + ShopObj = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), VS0 = construct_payment_flow(Payment), - VS1 = collect_validation_varset(get_injected_party_id(Refund), ShopObj, Payment, VS0), + VS1 = collect_validation_varset(get_injected_party_config_ref(Refund), ShopObj, Payment, VS0), hg_routing:get_payment_terms(Route, VS1, Revision). construct_payment_flow(Payment) -> @@ -396,7 +396,7 @@ reconstruct_payment_flow(?invoice_payment_flow_hold(_OnHoldExpiration, HeldUntil Seconds = hg_datetime:parse_ts(HeldUntil) - hg_datetime:parse_ts(CreatedAt), #{flow => {hold, ?hold_lifetime(Seconds)}}. -collect_validation_varset(PartyID, {ShopID, Shop}, Payment, VS) -> +collect_validation_varset(PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Payment, VS) -> #domain_ShopConfig{ category = Category } = Shop, @@ -405,8 +405,8 @@ collect_validation_varset(PartyID, {ShopID, Shop}, Payment, VS) -> payer = Payer } = Payment, VS#{ - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_id => ShopConfigID, category => Category, currency => Currency, cost => Cost, @@ -493,18 +493,18 @@ get_initial_retry_strategy() -> inject_context(Options, Refund) -> Invoice = maps:get(invoice, Options), Payment = maps:get(payment, Options), - #domain_Invoice{id = InvoiceID, shop_id = ShopID} = Invoice, + #domain_Invoice{id = InvoiceID, shop_ref = ShopConfigRef} = Invoice, #domain_InvoicePayment{id = PaymentID, domain_revision = Revision} = Payment, Party = maps:get(party, Options), - PartyID = maps:get(party_id, Options), - {ShopID, Shop} = hg_party:get_shop(ShopID, Party, Revision), + PartyConfigRef = maps:get(party_config_ref, Options), + {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), Context = genlib_map:compact(#{ party => Party, - party_id => PartyID, + shop => Shop, + party_config_ref => PartyConfigRef, + shop_config_ref => ShopConfigRef, invoice => Invoice, payment => Payment, - shop => Shop, - shop_id => ShopID, invoice_id => InvoiceID, payment_id => PaymentID, repair_scenario => maps:get(repair_scenario, Options, undefined), @@ -512,12 +512,11 @@ inject_context(Options, Refund) -> }), Refund#{injected_context => Context}. -get_injected_party(#{injected_context := #{party := V}}) -> V. -get_injected_party_id(#{injected_context := #{party_id := V}}) -> V. +get_injected_party_config_ref(#{injected_context := #{party_config_ref := V}}) -> V. get_injected_invoice(#{injected_context := #{invoice := V}}) -> V. get_injected_payment(#{injected_context := #{payment := V}}) -> V. get_injected_shop(#{injected_context := #{shop := V}}) -> V. -get_injected_shop_id(#{injected_context := #{shop_id := V}}) -> V. +get_injected_shop_config_ref(#{injected_context := #{shop_config_ref := V}}) -> V. get_injected_invoice_id(#{injected_context := #{invoice_id := V}}) -> V. get_injected_payment_id(#{injected_context := #{payment_id := V}}) -> V. get_injected_repair_scenario(#{injected_context := Context}) -> maps:get(repair_scenario, Context, undefined). diff --git a/apps/hellgate/src/hg_invoice_registered_payment.erl b/apps/hellgate/src/hg_invoice_registered_payment.erl index 98f42377..613ff759 100644 --- a/apps/hellgate/src/hg_invoice_registered_payment.erl +++ b/apps/hellgate/src/hg_invoice_registered_payment.erl @@ -45,14 +45,14 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt0}) -> } = Params, CreatedAt1 = genlib:define(OccurredAt, CreatedAt0), Revision = hg_domain:head(), - PartyID = get_party_id(Opts), - ShopObj = {ShopID, Shop} = get_shop(Opts, Revision), + PartyConfigRef = get_party_config_ref(Opts), + ShopObj = {ShopConfigRef, Shop} = get_shop(Opts, Revision), Invoice = get_invoice(Opts), %% NOTE even if payment cost < invoice cost, invoice will gain status 'paid' Cost1 = genlib:define(Cost0, get_invoice_cost(Invoice)), {ok, Payer, _} = hg_invoice_payment:construct_payer(PayerParams), PaymentTool = get_payer_payment_tool(Payer), - VS = collect_validation_varset(PartyID, ShopObj, Cost1, PaymentTool, RiskScore), + VS = collect_validation_varset(PartyConfigRef, ShopObj, Cost1, PaymentTool, RiskScore), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS, Revision), @@ -61,8 +61,8 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt0}) -> CreatedAt1, Cost1, Payer, - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, PayerSessionInfo, Context, ExternalID, @@ -195,7 +195,7 @@ get_turnover_limits(Payment, Route, St) -> Route = hg_invoice_payment:get_route(St), Opts = hg_invoice_payment:get_opts(St), Revision = hg_invoice_payment:get_payment_revision(St), - PartyID = get_party_id(Opts), + PartyConfigRef = get_party_config_ref(Opts), ShopObj = get_shop(Opts, Revision), #domain_InvoicePayment{ cost = Cost, @@ -204,7 +204,7 @@ get_turnover_limits(Payment, Route, St) -> } = Payment = hg_invoice_payment:get_payment(St), PaymentTool = get_payer_payment_tool(Payer), RiskScore = hg_invoice_payment:get_risk_score(St), - VS = collect_validation_varset(PartyID, ShopObj, Cost, PaymentTool, RiskScore), + VS = collect_validation_varset(PartyConfigRef, ShopObj, Cost, PaymentTool, RiskScore), ProviderTerms = hg_routing:get_payment_terms(Route, VS, Revision), TurnoverLimitSelector = ProviderTerms#domain_PaymentsProvisionTerms.turnover_limits, hg_limiter:get_turnover_limits(TurnoverLimitSelector). @@ -214,8 +214,8 @@ construct_payment( CreatedAt, Cost, Payer, - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, PayerSessionInfo, Context, ExternalID, @@ -224,8 +224,8 @@ construct_payment( #domain_InvoicePayment{ id = PaymentID, created_at = CreatedAt, - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, domain_revision = Revision, status = ?pending(), cost = Cost, @@ -238,13 +238,19 @@ construct_payment( registration_origin = ?invoice_payment_provider_reg_origin() }. -collect_validation_varset(PartyID, {ShopID, Shop}, #domain_Cash{currency = Currency} = Cost, PaymentTool, RiskScore) -> +collect_validation_varset( + PartyConfigRef, + {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, + #domain_Cash{currency = Currency} = Cost, + PaymentTool, + RiskScore +) -> #domain_ShopConfig{ category = Category } = Shop, #{ - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_id => ShopConfigID, category => Category, currency => Currency, cost => Cost, @@ -255,11 +261,12 @@ collect_validation_varset(PartyID, {ShopID, Shop}, #domain_Cash{currency = Curre %% -get_party_id(#{party_id := PartyID}) -> - PartyID. +get_party_config_ref(#{party_config_ref := PartyConfigRef}) -> + PartyConfigRef. + +get_shop(#{invoice := Invoice, party_config_ref := PartyConfigRef}, Revision) -> + hg_party:get_shop(get_invoice_shop_config_ref(Invoice), PartyConfigRef, Revision). -get_shop(#{party := Party, invoice := Invoice}, Revision) -> - hg_party:get_shop(get_invoice_shop_id(Invoice), Party, Revision). get_payment_institution_ref(Opts, Revision) -> {_, Shop} = get_shop(Opts, Revision), Shop#domain_ShopConfig.payment_institution. @@ -270,8 +277,8 @@ get_invoice(#{invoice := Invoice}) -> get_invoice_cost(#domain_Invoice{cost = Cost}) -> Cost. -get_invoice_shop_id(#domain_Invoice{shop_id = ShopID}) -> - ShopID. +get_invoice_shop_config_ref(#domain_Invoice{shop_ref = ShopConfigRef}) -> + ShopConfigRef. get_payer_payment_tool(?payment_resource_payer(PaymentResource, _ContactInfo)) -> get_resource_payment_tool(PaymentResource). diff --git a/apps/hellgate/src/hg_invoice_template.erl b/apps/hellgate/src/hg_invoice_template.erl index ed02e06e..df6f1c69 100644 --- a/apps/hellgate/src/hg_invoice_template.erl +++ b/apps/hellgate/src/hg_invoice_template.erl @@ -60,8 +60,11 @@ handle_function(Func, Args, Opts) -> handle_function_('Create', {Params}, _Opts) -> TplID = Params#payproc_InvoiceTemplateCreateParams.template_id, _ = set_meta(TplID), - Party = get_party(Params#payproc_InvoiceTemplateCreateParams.party_id), - Shop = get_shop(Params#payproc_InvoiceTemplateCreateParams.shop_id, Party), + _Party = get_party(Params#payproc_InvoiceTemplateCreateParams.party_id), + Shop = get_shop( + Params#payproc_InvoiceTemplateCreateParams.shop_id, + Params#payproc_InvoiceTemplateCreateParams.party_id + ), ok = validate_create_params(Params, Shop), ok = start(TplID, Params), get_invoice_template(TplID); @@ -71,14 +74,14 @@ handle_function_('Get', {TplID}, _Opts) -> handle_function_('Update' = Fun, {TplID, Params} = Args, _Opts) -> _ = set_meta(TplID), Tpl = get_invoice_template(TplID), - Party = get_party(Tpl#domain_InvoiceTemplate.owner_id), - Shop = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party), + _ = get_party(Tpl#domain_InvoiceTemplate.party_ref), + Shop = get_shop(Tpl#domain_InvoiceTemplate.shop_ref, Tpl#domain_InvoiceTemplate.party_ref), ok = validate_update_params(Params, Shop), call(TplID, Fun, Args); handle_function_('Delete' = Fun, {TplID} = Args, _Opts) -> Tpl = get_invoice_template(TplID), - Party = get_party(Tpl#domain_InvoiceTemplate.owner_id), - _ = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party), + _ = get_party(Tpl#domain_InvoiceTemplate.party_ref), + _ = get_shop(Tpl#domain_InvoiceTemplate.shop_ref, Tpl#domain_InvoiceTemplate.party_ref), _ = set_meta(TplID), call(TplID, Fun, Args); handle_function_('ComputeTerms', {TplID}, _Opts) -> @@ -92,13 +95,17 @@ handle_function_('ComputeTerms', {TplID}, _Opts) -> undefined end, Revision = hg_party:get_party_revision(), - {PartyID, Party} = hg_party:checkout(Tpl#domain_InvoiceTemplate.owner_id, Revision), - {ShopID, Shop} = hg_party:get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party, Revision), + {PartyConfigRef, Party} = hg_party:checkout(Tpl#domain_InvoiceTemplate.party_ref, Revision), + {#domain_ShopConfigRef{id = ShopConfigID}, Shop} = hg_party:get_shop( + Tpl#domain_InvoiceTemplate.shop_ref, + Tpl#domain_InvoiceTemplate.party_ref, + Revision + ), _ = assert_party_shop_operable(Shop, Party), VS = #{ cost => Cost, - shop_id => ShopID, - party_id => PartyID, + shop_id => ShopConfigID, + party_config_ref => PartyConfigRef, category => Shop#domain_ShopConfig.category, currency => hg_invoice_utils:get_shop_currency(Shop) }, @@ -113,14 +120,14 @@ assert_party_shop_operable(Shop, Party) -> _ = hg_invoice_utils:assert_shop_operable(Shop), ok. -get_party(PartyID) -> - {PartyID, Party} = hg_party:get_party(PartyID), +get_party(PartyConfigRef) -> + {PartyConfigRef, Party} = hg_party:get_party(PartyConfigRef), _ = hg_invoice_utils:assert_party_operable(Party), Party. -get_shop(ShopID, Party) -> - {ShopID, Shop} = hg_invoice_utils:assert_shop_exists( - hg_party:get_shop(ShopID, Party, hg_party:get_party_revision()) +get_shop(ShopConfigRef, PartyConfigRef) -> + {ShopConfigRef, Shop} = hg_invoice_utils:assert_shop_exists( + hg_party:get_shop(ShopConfigRef, PartyConfigRef, hg_party:get_party_revision()) ), _ = hg_invoice_utils:assert_shop_operable(Shop), Shop. @@ -227,8 +234,8 @@ init(EncodedParams, #{id := ID}) -> create_invoice_template(ID, P) -> #domain_InvoiceTemplate{ id = ID, - owner_id = P#payproc_InvoiceTemplateCreateParams.party_id, - shop_id = P#payproc_InvoiceTemplateCreateParams.shop_id, + party_ref = P#payproc_InvoiceTemplateCreateParams.party_id, + shop_ref = P#payproc_InvoiceTemplateCreateParams.shop_id, invoice_lifetime = P#payproc_InvoiceTemplateCreateParams.invoice_lifetime, product = P#payproc_InvoiceTemplateCreateParams.product, name = P#payproc_InvoiceTemplateCreateParams.name, diff --git a/apps/hellgate/src/hg_invoice_utils.erl b/apps/hellgate/src/hg_invoice_utils.erl index 9a2d8b28..50d584d2 100644 --- a/apps/hellgate/src/hg_invoice_utils.erl +++ b/apps/hellgate/src/hg_invoice_utils.erl @@ -30,7 +30,7 @@ -type cash_range() :: dmsl_domain_thrift:'CashRange'(). -type party() :: dmsl_domain_thrift:'PartyConfig'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type term_set() :: dmsl_domain_thrift:'TermSet'(). -type payment_service_terms() :: dmsl_domain_thrift:'PaymentsServiceTerms'(). -type varset() :: dmsl_payproc_thrift:'Varset'(). @@ -83,7 +83,7 @@ assert_shop_operable(V) -> _ = assert_shop_active(V), V. --spec assert_shop_exists({shop_id(), shop()} | undefined) -> {shop_id(), shop()}. +-spec assert_shop_exists({shop_config_ref(), shop()} | undefined) -> {shop_config_ref(), shop()}. assert_shop_exists({_, #domain_ShopConfig{}} = V) -> V; assert_shop_exists(undefined) -> diff --git a/apps/hellgate/src/hg_limiter.erl b/apps/hellgate/src/hg_limiter.erl index 6859f53e..72dd3d87 100644 --- a/apps/hellgate/src/hg_limiter.erl +++ b/apps/hellgate/src/hg_limiter.erl @@ -16,8 +16,8 @@ -type cash() :: dmsl_domain_thrift:'Cash'(). -type handling_flag() :: ignore_business_error | ignore_not_found. -type turnover_limit_value() :: dmsl_payproc_thrift:'TurnoverLimitValue'(). --type party_id() :: hg_party:party_id(). --type shop_id() :: dmsl_domain_thrift:'ShopConfigID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type change_queue() :: [hg_limiter_client:limit_change()]. @@ -108,12 +108,14 @@ check_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> {error, {limit_overflow, IDs, Limits}} end. --spec check_shop_limits([turnover_limit()], party_id(), shop_id(), invoice(), payment()) -> +-spec check_shop_limits([turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment()) -> ok | {error, {limit_overflow, [binary()]}}. -check_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> +check_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> Context = gen_limit_shop_context(Invoice, Payment), - Limits = get_limit_values(Context, TurnoverLimits, make_shop_operation_segments(PartyID, ShopID, Invoice, Payment)), + Limits = get_limit_values( + Context, TurnoverLimits, make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) + ), try check_limits_(Limits, Context) catch @@ -122,10 +124,10 @@ check_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> {error, {limit_overflow, IDs}} end. -make_shop_operation_segments(PartyID, ShopID, Invoice, Payment) -> +make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) -> [ - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, get_invoice_id(Invoice), get_payment_id(Payment) ]. @@ -171,17 +173,17 @@ batch_hold_limits(Context, TurnoverLimits, OperationIdSegments) -> _ = hg_limiter_client:hold_batch(LimitRequest, Context), ok. --spec hold_shop_limits([turnover_limit()], party_id(), shop_id(), invoice(), payment()) -> ok. -hold_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> +-spec hold_shop_limits([turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment()) -> ok. +hold_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> Context = gen_limit_shop_context(Invoice, Payment), {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), - ok = legacy_hold_shop_limits(Context, LegacyTurnoverLimits, PartyID, ShopID, Invoice, Payment), + ok = legacy_hold_shop_limits(Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment), ok = batch_hold_limits( - Context, BatchTurnoverLimits, make_shop_operation_segments(PartyID, ShopID, Invoice, Payment) + Context, BatchTurnoverLimits, make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) ). -legacy_hold_shop_limits(Context, TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> - ChangeIDs = [construct_shop_change_id(PartyID, ShopID, Invoice, Payment)], +legacy_hold_shop_limits(Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> + ChangeIDs = [construct_shop_change_id(PartyConfigRef, ShopConfigRef, Invoice, Payment)], LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), hold(LimitChanges, get_latest_clock(), Context). @@ -228,18 +230,20 @@ legacy_commit_payment_limits(Clock, Context, TurnoverLimits, Invoice, Payment, R LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), commit(LimitChanges, Clock, Context). --spec commit_shop_limits([turnover_limit()], party_id(), shop_id(), invoice(), payment()) -> ok. -commit_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> +-spec commit_shop_limits([turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment()) -> ok. +commit_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> Context = gen_limit_shop_context(Invoice, Payment), {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), Clock = get_latest_clock(), - ok = legacy_commit_shop_limits(Clock, Context, LegacyTurnoverLimits, PartyID, ShopID, Invoice, Payment), - OperationIdSegments = make_shop_operation_segments(PartyID, ShopID, Invoice, Payment), + ok = legacy_commit_shop_limits( + Clock, Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment + ), + OperationIdSegments = make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment), ok = batch_commit_limits(Context, BatchTurnoverLimits, OperationIdSegments), ok = log_limit_changes(TurnoverLimits, Clock, Context). -legacy_commit_shop_limits(Clock, Context, TurnoverLimits, PartyID, ShopID, Invoice, Payment) -> - ChangeIDs = [construct_shop_change_id(PartyID, ShopID, Invoice, Payment)], +legacy_commit_shop_limits(Clock, Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> + ChangeIDs = [construct_shop_change_id(PartyConfigRef, ShopConfigRef, Invoice, Payment)], LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), ok = commit(LimitChanges, Clock, Context). @@ -289,17 +293,25 @@ legacy_rollback_payment_limits(Context, TurnoverLimits, Invoice, Payment, Route, LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), rollback(LimitChanges, get_latest_clock(), Context, Flags). --spec rollback_shop_limits([turnover_limit()], party_id(), shop_id(), invoice(), payment(), [handling_flag()]) -> - ok. -rollback_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment, Flags) -> +-spec rollback_shop_limits( + [turnover_limit()], + party_config_ref(), + shop_config_ref(), + invoice(), + payment(), + [handling_flag()] +) -> ok. +rollback_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment, Flags) -> Context = gen_limit_shop_context(Invoice, Payment), {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), - ok = legacy_rollback_shop_limits(Context, LegacyTurnoverLimits, PartyID, ShopID, Invoice, Payment, Flags), - OperationIdSegments = make_shop_operation_segments(PartyID, ShopID, Invoice, Payment), + ok = legacy_rollback_shop_limits( + Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment, Flags + ), + OperationIdSegments = make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). -legacy_rollback_shop_limits(Context, TurnoverLimits, PartyID, ShopID, Invoice, Payment, Flags) -> - ChangeIDs = [construct_shop_change_id(PartyID, ShopID, Invoice, Payment)], +legacy_rollback_shop_limits(Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment, Flags) -> + ChangeIDs = [construct_shop_change_id(PartyConfigRef, ShopConfigRef, Invoice, Payment)], LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), rollback(LimitChanges, get_latest_clock(), Context, Flags). @@ -452,10 +464,10 @@ construct_payment_change_id(?route(ProviderRef, TerminalRef), Iter, Invoice, Pay integer_to_binary(Iter) ]). -construct_shop_change_id(PartyID, ShopID, Invoice, Payment) -> +construct_shop_change_id(PartyConfigRef, ShopConfigRef, Invoice, Payment) -> hg_utils:construct_complex_id([ - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, get_invoice_id(Invoice), get_payment_id(Payment) ]). @@ -507,7 +519,7 @@ mk_limit_log_attributes(#limiter_LimitContext{ payment_processing = #context_payproc_Context{op = Op, invoice = CtxInvoice} }) -> #context_payproc_Invoice{ - invoice = #domain_Invoice{owner_id = PartyID, shop_id = ShopID}, + invoice = #domain_Invoice{party_ref = PartyConfigRef, shop_ref = ShopConfigRef}, payment = #context_payproc_InvoicePayment{ payment = Payment, refund = Refund, @@ -528,8 +540,8 @@ mk_limit_log_attributes(#limiter_LimitContext{ %% Current amount with accounted change amount => undefined, route => maybe_route_context(Route), - party_id => PartyID, - shop_id => ShopID, + party_config_ref => PartyConfigRef, + shop_config_ref => ShopConfigRef, change => #{ amount => Amount, currency => Currency#domain_CurrencyRef.symbolic_code diff --git a/apps/hellgate/src/hg_party.erl b/apps/hellgate/src/hg_party.erl index 1dcd003c..3fdefd36 100644 --- a/apps/hellgate/src/hg_party.erl +++ b/apps/hellgate/src/hg_party.erl @@ -1,6 +1,7 @@ -module(hg_party). -include_lib("damsel/include/dmsl_domain_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl"). %% Party support functions @@ -9,52 +10,83 @@ -export([checkout/2]). -export([get_shop/2]). -export([get_shop/3]). +-export([get_shops_by_party_config_ref/2]). -export_type([party/0]). --export_type([party_id/0]). +-export_type([party_config_ref/0]). %% -type party() :: dmsl_domain_thrift:'PartyConfig'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type shop() :: dmsl_domain_thrift:'ShopConfig'(). --type shop_id() :: dmsl_domain_thrift:'ShopID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). %% Interface --spec get_party(party_id()) -> {party_id(), party()} | hg_domain:get_error(). -get_party(PartyID) -> - checkout(PartyID, get_party_revision()). +-spec get_party(party_config_ref()) -> {party_config_ref(), party()} | hg_domain:get_error(). +get_party(PartyConfigRef) -> + checkout(PartyConfigRef, get_party_revision()). -spec get_party_revision() -> hg_domain:revision() | no_return(). get_party_revision() -> hg_domain:head(). --spec checkout(party_id(), hg_domain:revision()) -> {party_id(), party()} | hg_domain:get_error(). -checkout(PartyID, Revision) -> - Ref = {party_config, #domain_PartyConfigRef{id = PartyID}}, - case hg_domain:get(Revision, Ref) of +-spec checkout(party_config_ref(), hg_domain:revision()) -> + {party_config_ref(), party()} | hg_domain:get_error(). +checkout(PartyConfigRef, Revision) -> + case hg_domain:get(Revision, {party_config, PartyConfigRef}) of {object_not_found, _} = Error -> Error; PartyConfig -> - {PartyID, PartyConfig} + {PartyConfigRef, PartyConfig} end. --spec get_shop(shop_id(), party()) -> {shop_id(), shop()} | undefined. -get_shop(ID, Party) -> - get_shop(ID, Party, get_party_revision()). - --spec get_shop(shop_id(), party(), hg_domain:revision()) -> {shop_id(), shop()} | undefined. -get_shop(ID, #domain_PartyConfig{shops = Shops}, Revision) -> - Ref = #domain_ShopConfigRef{id = ID}, - case lists:member(Ref, Shops) of - true -> - case hg_domain:get(Revision, {shop_config, Ref}) of - {object_not_found, _} = Error -> - Error; - ShopConfig -> - {ID, ShopConfig} - end; - false -> +-spec get_shop(shop_config_ref(), party_config_ref()) -> {shop_config_ref(), shop()} | undefined. +get_shop(ShopConfigRef, PartyConfigRef) -> + get_shop(ShopConfigRef, PartyConfigRef, get_party_revision()). + +-spec get_shop(shop_config_ref(), party_config_ref(), hg_domain:revision()) -> + {shop_config_ref(), shop()} | undefined. +get_shop(ShopConfigRef, PartyConfigRef, Revision) -> + try dmt_client:checkout_object(Revision, {shop_config, ShopConfigRef}) of + #domain_conf_v2_VersionedObject{ + object = + {shop_config, #domain_ShopConfigObject{ + data = #domain_ShopConfig{party_ref = PartyConfigRef} = ShopConfig + }} + } -> + {ShopConfigRef, ShopConfig}; + ShopConfig -> + _ = logger:warning("Shop config ~p not found for party ~p", [ShopConfig, PartyConfigRef]), + undefined + catch + throw:#domain_conf_v2_ObjectNotFound{} -> undefined end. + +-spec get_shops_by_party_config_ref(party_config_ref(), hg_domain:revision()) -> [shop()]. +get_shops_by_party_config_ref(PartyConfigRef, Revision) -> + try dmt_client:checkout_object_with_references(Revision, {party_config, PartyConfigRef}) of + #domain_conf_v2_VersionedObjectWithReferences{ + referenced_by = ReferencedBy + } -> + lists:foldl( + fun(VersionedObject, Acc) -> + case VersionedObject of + #domain_conf_v2_VersionedObject{ + object = {shop_config, _} = Object + } -> + [Object | Acc]; + _ -> + Acc + end + end, + [], + ReferencedBy + ) + catch + % If the object is not found, return an empty list + error:#domain_conf_v2_ObjectNotFound{} -> + [] + end. diff --git a/apps/hellgate/src/hg_varset.erl b/apps/hellgate/src/hg_varset.erl index da688a29..ee98390b 100644 --- a/apps/hellgate/src/hg_varset.erl +++ b/apps/hellgate/src/hg_varset.erl @@ -1,6 +1,7 @@ -module(hg_varset). -include_lib("damsel/include/dmsl_payproc_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_thrift.hrl"). -export([prepare_varset/1]). @@ -11,11 +12,11 @@ currency => dmsl_domain_thrift:'CurrencyRef'(), cost => dmsl_domain_thrift:'Cash'(), payment_tool => dmsl_domain_thrift:'PaymentTool'(), - party_id => dmsl_domain_thrift:'PartyID'(), - shop_id => dmsl_domain_thrift:'ShopID'(), + party_config_ref => dmsl_domain_thrift:'PartyConfigRef'(), + shop_id => dmsl_base_thrift:'ID'(), risk_score => hg_inspector:risk_score(), flow => instant | {hold, dmsl_domain_thrift:'HoldLifetime'()}, - wallet_id => dmsl_domain_thrift:'WalletID'() + wallet_id => dmsl_base_thrift:'ID'() }. -spec prepare_varset(varset()) -> dmsl_payproc_thrift:'Varset'(). @@ -26,6 +27,6 @@ prepare_varset(Varset) -> amount = genlib_map:get(cost, Varset), wallet_id = genlib_map:get(wallet_id, Varset), payment_tool = genlib_map:get(payment_tool, Varset), - party_id = genlib_map:get(party_id, Varset), + party_ref = genlib_map:get(party_config_ref, Varset), shop_id = genlib_map:get(shop_id, Varset) }. diff --git a/apps/hellgate/test/hg_allocation_tests.erl b/apps/hellgate/test/hg_allocation_tests.erl index a6137e46..a08a901f 100644 --- a/apps/hellgate/test/hg_allocation_tests.erl +++ b/apps/hellgate/test/hg_allocation_tests.erl @@ -8,16 +8,19 @@ -spec test() -> _. +-define(PARTY_CONFIG_REF(ID), #domain_PartyConfigRef{id = ID}). +-define(SHOP_CONFIG_REF(ID), #domain_ShopConfigRef{id = ID}). + generic_prototype() -> Cart = ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(30, <<"RUB">>))]), ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_fixed(?cash(10, <<"RUB">>)) @@ -25,7 +28,7 @@ generic_prototype() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_share(15, 100) @@ -40,36 +43,36 @@ calculate_test() -> AllocationPrototype = generic_prototype(), ?allocation(AllocationTrxs) = hg_allocation:calculate( AllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(90, <<"RUB">>) ), ?assertMatch( [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ), ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(20, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(10, <<"RUB">>) ) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(25, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(5, <<"RUB">>), ?allocation_trx_fee_share(15, 100) @@ -77,7 +80,7 @@ calculate_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -89,44 +92,44 @@ calculate_without_generating_agg_trx_test() -> Cart = ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(30, <<"RUB">>))]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart) ) ]), ?allocation(AllocationTrxs) = hg_allocation:calculate( AllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(90, <<"RUB">>) ), ?assertMatch( [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ), ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ) @@ -139,7 +142,7 @@ calculate_amount_exceeded_error_1_test() -> Cart = ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(30, <<"RUB">>))]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_total( ?cash(50, <<"RUB">>), ?allocation_trx_prototype_fee_share(1, 2) @@ -147,7 +150,7 @@ calculate_amount_exceeded_error_1_test() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_total( ?cash(50, <<"RUB">>), ?allocation_trx_prototype_fee_share(1, 2) @@ -155,7 +158,7 @@ calculate_amount_exceeded_error_1_test() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_total( ?cash(50, <<"RUB">>), ?allocation_trx_prototype_fee_share(1, 2) @@ -165,7 +168,12 @@ calculate_amount_exceeded_error_1_test() -> ]), ?assertThrow( amount_exceeded, - hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)) + hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ) ). -spec calculate_amount_exceeded_error_2_test() -> _. @@ -173,7 +181,12 @@ calculate_amount_exceeded_error_2_test() -> AllocationPrototype = generic_prototype(), ?assertThrow( amount_exceeded, - hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(100, <<"RUB">>)) + hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(100, <<"RUB">>) + ) ). -spec subtract_one_transaction_1_test() -> _. @@ -182,15 +195,20 @@ subtract_one_transaction_1_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)) ) ]), - Allocation = hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)), + Allocation = hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ), RefundAllocation = hg_allocation:calculate( RefundAllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(30, <<"RUB">>) ), {ok, ?allocation(SubbedAllocationTrxs)} = hg_allocation:sub(Allocation, RefundAllocation), @@ -198,22 +216,22 @@ subtract_one_transaction_1_test() -> [ ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(20, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(10, <<"RUB">>) ) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(25, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(5, <<"RUB">>), ?allocation_trx_fee_share(15, 100) @@ -221,7 +239,7 @@ subtract_one_transaction_1_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -234,7 +252,7 @@ subtract_one_transaction_2_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_fixed(?cash(10, <<"RUB">>)) @@ -242,11 +260,16 @@ subtract_one_transaction_2_test() -> ?allocation_trx_details(Cart) ) ]), - Allocation = hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)), + Allocation = hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ), RefundAllocation = hg_allocation:calculate( RefundAllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(30, <<"RUB">>) ), {ok, ?allocation(SubbedAllocationTrxs)} = hg_allocation:sub(Allocation, RefundAllocation), @@ -254,17 +277,17 @@ subtract_one_transaction_2_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(25, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(5, <<"RUB">>), ?allocation_trx_fee_share(15, 100) @@ -272,7 +295,7 @@ subtract_one_transaction_2_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(5, <<"RUB">>) ) ], @@ -285,7 +308,7 @@ subtract_one_transaction_3_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_share(15, 100) @@ -293,11 +316,16 @@ subtract_one_transaction_3_test() -> ?allocation_trx_details(Cart) ) ]), - Allocation = hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)), + Allocation = hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ), RefundAllocation = hg_allocation:calculate( RefundAllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(30, <<"RUB">>) ), {ok, ?allocation(SubbedAllocationTrxs)} = hg_allocation:sub(Allocation, RefundAllocation), @@ -305,24 +333,24 @@ subtract_one_transaction_3_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ), ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(20, <<"RUB">>), ?allocation_trx_details(Cart), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(10, <<"RUB">>) ) ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(10, <<"RUB">>) ) ], @@ -338,12 +366,12 @@ subtract_partial_transaction_test() -> ]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart1) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_fixed(?cash(10, <<"RUB">>)) @@ -351,7 +379,7 @@ subtract_partial_transaction_test() -> ?allocation_trx_details(Cart0) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_share(15, 100) @@ -361,16 +389,23 @@ subtract_partial_transaction_test() -> ]), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(18, <<"RUB">>)), - ?allocation_trx_details(?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(18, <<"RUB">>))])) + ?allocation_trx_details( + ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(18, <<"RUB">>))]) + ) ) ]), - Allocation = hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)), + Allocation = hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ), RefundAllocation = hg_allocation:calculate( RefundAllocationPrototype, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(18, <<"RUB">>) ), {ok, ?allocation(SubbedAllocationTrxs)} = hg_allocation:sub(Allocation, RefundAllocation), @@ -378,28 +413,28 @@ subtract_partial_transaction_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?cash(12, <<"RUB">>), ?allocation_trx_details(Cart1) ), ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(20, <<"RUB">>), ?allocation_trx_details(Cart0), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(10, <<"RUB">>) ) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(25, <<"RUB">>), ?allocation_trx_details(Cart0), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(5, <<"RUB">>), ?allocation_trx_fee_share(15, 100) @@ -407,7 +442,7 @@ subtract_partial_transaction_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -423,12 +458,12 @@ consecutive_subtract_of_partial_transaction_test() -> ]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)), ?allocation_trx_details(Cart1) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_fixed(?cash(10, <<"RUB">>)) @@ -436,7 +471,7 @@ consecutive_subtract_of_partial_transaction_test() -> ?allocation_trx_details(Cart0) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?allocation_trx_prototype_body_total( ?cash(30, <<"RUB">>), ?allocation_trx_prototype_fee_share(15, 100) @@ -446,23 +481,32 @@ consecutive_subtract_of_partial_transaction_test() -> ]), RefundAllocationPrototype0 = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(18, <<"RUB">>)), - ?allocation_trx_details(?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(18, <<"RUB">>))])) + ?allocation_trx_details( + ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(18, <<"RUB">>))]) + ) ) ]), RefundAllocationPrototype1 = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop(<<"PARTY1">>, <<"SHOP1">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(12, <<"RUB">>)), - ?allocation_trx_details(?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(12, <<"RUB">>))])) + ?allocation_trx_details( + ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(12, <<"RUB">>))]) + ) ) ]), - Allocation0 = hg_allocation:calculate(AllocationPrototype, <<"PARTY0">>, <<"SHOP0">>, ?cash(90, <<"RUB">>)), + Allocation0 = hg_allocation:calculate( + AllocationPrototype, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), + ?cash(90, <<"RUB">>) + ), RefundAllocation0 = hg_allocation:calculate( RefundAllocationPrototype0, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(18, <<"RUB">>) ), {ok, Allocation1} = hg_allocation:sub( @@ -471,8 +515,8 @@ consecutive_subtract_of_partial_transaction_test() -> ), RefundAllocation1 = hg_allocation:calculate( RefundAllocationPrototype1, - <<"PARTY0">>, - <<"SHOP0">>, + ?PARTY_CONFIG_REF(<<"PARTY0">>), + ?SHOP_CONFIG_REF(<<"SHOP0">>), ?cash(12, <<"RUB">>) ), {ok, ?allocation(SubbedAllocationTrxs)} = hg_allocation:sub(Allocation1, RefundAllocation1), @@ -480,22 +524,22 @@ consecutive_subtract_of_partial_transaction_test() -> [ ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop(<<"PARTY2">>, <<"SHOP2">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"SHOP2">>)), ?cash(20, <<"RUB">>), ?allocation_trx_details(Cart0), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(10, <<"RUB">>) ) ), ?allocation_trx( <<"3">>, - ?allocation_trx_target_shop(<<"PARTY3">>, <<"SHOP3">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(25, <<"RUB">>), ?allocation_trx_details(Cart0), ?allocation_trx_body_total( - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(30, <<"RUB">>), ?cash(5, <<"RUB">>), ?allocation_trx_fee_share(15, 100) @@ -503,7 +547,7 @@ consecutive_subtract_of_partial_transaction_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop(<<"PARTY0">>, <<"SHOP0">>), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], diff --git a/apps/hellgate/test/hg_ct_domain.hrl b/apps/hellgate/test/hg_ct_domain.hrl index aab43154..383f7742 100644 --- a/apps/hellgate/test/hg_ct_domain.hrl +++ b/apps/hellgate/test/hg_ct_domain.hrl @@ -46,7 +46,7 @@ -define(cashrng(Lower, Upper), #domain_CashRange{lower = Lower, upper = Upper}). -define(prvacc(Stl), #domain_ProviderAccount{settlement = Stl}). --define(partycond(ID, Def), {condition, {party, #domain_PartyCondition{id = ID, definition = Def}}}). +-define(partycond(Ref, Def), {condition, {party, #domain_PartyCondition{party_ref = Ref, definition = Def}}}). -define(fixed(Amount, Currency), {fixed, #domain_CashVolumeFixed{ diff --git a/apps/hellgate/test/hg_ct_helper.erl b/apps/hellgate/test/hg_ct_helper.erl index 70b7fab8..02e82481 100644 --- a/apps/hellgate/test/hg_ct_helper.erl +++ b/apps/hellgate/test/hg_ct_helper.erl @@ -437,12 +437,12 @@ create_client_w_context(RootUrl, WoodyCtx) -> -type invoice_id() :: dmsl_domain_thrift:'InvoiceID'(). -type invoice_template_id() :: dmsl_domain_thrift:'InvoiceTemplateID'(). --type party_id() :: dmsl_domain_thrift:'PartyID'(). +-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type party() :: dmsl_domain_thrift:'PartyConfig'(). -type termset_ref() :: dmsl_domain_thrift:'TermSetHierarchyRef'(). -type turnover_limit() :: dmsl_domain_thrift:'TurnoverLimit'(). -type turnover_limits() :: ordsets:ordset(turnover_limit()). --type shop_id() :: dmsl_domain_thrift:'ShopID'(). +-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type category() :: dmsl_domain_thrift:'CategoryRef'(). -type cash() :: dmsl_domain_thrift:'Cash'(). -type invoice_tpl_id() :: dmsl_domain_thrift:'InvoiceTemplateID'(). @@ -462,8 +462,8 @@ create_client_w_context(RootUrl, WoodyCtx) -> -type payment_inst_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'(). -type allocation_prototype() :: dmsl_domain_thrift:'AllocationPrototype'(). --spec create_party(party_id(), party_client()) -> party(). -create_party(PartyID, _Client) -> +-spec create_party(party_config_ref(), party_client()) -> party(). +create_party(PartyConfigRef, _Client) -> % Создаем Party как объект конфигурации PartyConfig = #domain_PartyConfig{ contact_info = #domain_PartyContactInfo{ @@ -478,24 +478,22 @@ create_party(PartyID, _Client) -> suspension = {active, #domain_Active{ since = hg_datetime:format_now() - }}, - shops = [], - wallets = [] + }} }, % Вставляем Party в домен _ = hg_domain:upsert( {party_config, #domain_PartyConfigObject{ - ref = #domain_PartyConfigRef{id = PartyID}, + ref = PartyConfigRef, data = PartyConfig }} ), PartyConfig. --spec suspend_party(party_id()) -> ok. -suspend_party(PartyID) -> - change_party(PartyID, fun(PartyConfig) -> +-spec suspend_party(party_config_ref()) -> ok. +suspend_party(PartyConfigRef) -> + change_party(PartyConfigRef, fun(PartyConfig) -> PartyConfig#domain_PartyConfig{ suspension = {suspended, #domain_Suspended{ @@ -504,9 +502,9 @@ suspend_party(PartyID) -> } end). --spec activate_party(party_id()) -> ok. -activate_party(PartyID) -> - change_party(PartyID, fun(PartyConfig) -> +-spec activate_party(party_config_ref()) -> ok. +activate_party(PartyConfigRef) -> + change_party(PartyConfigRef, fun(PartyConfig) -> PartyConfig#domain_PartyConfig{ suspension = {active, #domain_Active{ @@ -515,9 +513,9 @@ activate_party(PartyID) -> } end). --spec block_party(party_id()) -> ok. -block_party(PartyID) -> - change_party(PartyID, fun(PartyConfig) -> +-spec block_party(party_config_ref()) -> ok. +block_party(PartyConfigRef) -> + change_party(PartyConfigRef, fun(PartyConfig) -> PartyConfig#domain_PartyConfig{ block = {blocked, #domain_Blocked{ @@ -527,9 +525,9 @@ block_party(PartyID) -> } end). --spec unblock_party(party_id()) -> ok. -unblock_party(PartyID) -> - change_party(PartyID, fun(PartyConfig) -> +-spec unblock_party(party_config_ref()) -> ok. +unblock_party(PartyConfigRef) -> + change_party(PartyConfigRef, fun(PartyConfig) -> PartyConfig#domain_PartyConfig{ block = {unblocked, #domain_Unblocked{ @@ -539,28 +537,28 @@ unblock_party(PartyID) -> } end). -change_party(PartyID, Fun) -> - PartyConfig0 = hg_domain:get({party_config, #domain_PartyConfigRef{id = PartyID}}), +change_party(PartyConfigRef, Fun) -> + PartyConfig0 = hg_domain:get({party_config, PartyConfigRef}), PartyConfig1 = Fun(PartyConfig0), _ = hg_domain:upsert( {party_config, #domain_PartyConfigObject{ - ref = #domain_PartyConfigRef{id = PartyID}, + ref = PartyConfigRef, data = PartyConfig1 }} ), ok. -spec create_shop( - party_id(), + party_config_ref(), category(), currency(), termset_ref(), payment_inst_ref(), undefined | turnover_limits(), party_client() -) -> shop_id(). -create_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, TurnoverLimits, _Client) -> - ShopID = hg_utils:unique_id(), +) -> shop_config_ref(). +create_shop(PartyConfigRef, Category, Currency, TermsRef, PaymentInstRef, TurnoverLimits, _Client) -> + ShopConfigRef = #domain_ShopConfigRef{id = hg_utils:unique_id()}, % Создаем счета SettlementID = hg_accounting:create_account(Currency), @@ -588,37 +586,31 @@ create_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, TurnoverLimit }, payment_institution = PaymentInstRef, terms = TermsRef, - party_id = PartyID, + party_ref = PartyConfigRef, turnover_limits = TurnoverLimits }, % Вставляем Shop в домен _ = hg_domain:upsert( {shop_config, #domain_ShopConfigObject{ - ref = #domain_ShopConfigRef{id = ShopID}, + ref = ShopConfigRef, data = ShopConfig }} ), - change_party(PartyID, fun(PartyConfig) -> - PartyConfig#domain_PartyConfig{ - shops = [#domain_ShopConfigRef{id = ShopID} | PartyConfig#domain_PartyConfig.shops] - } - end), - - ShopID. + ShopConfigRef. --spec shop_set_terms(shop_id(), _) -> ok. -shop_set_terms(ShopID, TermsRef) -> - change_shop(ShopID, fun(ShopConfig) -> +-spec shop_set_terms(shop_config_ref(), _) -> ok. +shop_set_terms(ShopConfigRef, TermsRef) -> + change_shop(ShopConfigRef, fun(ShopConfig) -> ShopConfig#domain_ShopConfig{ terms = TermsRef } end). --spec suspend_shop(shop_id()) -> ok. -suspend_shop(ShopID) -> - change_shop(ShopID, fun(ShopConfig) -> +-spec suspend_shop(shop_config_ref()) -> ok. +suspend_shop(ShopConfigRef) -> + change_shop(ShopConfigRef, fun(ShopConfig) -> ShopConfig#domain_ShopConfig{ suspension = {suspended, #domain_Suspended{ @@ -627,9 +619,9 @@ suspend_shop(ShopID) -> } end). --spec activate_shop(shop_id()) -> ok. -activate_shop(ShopID) -> - change_shop(ShopID, fun(ShopConfig) -> +-spec activate_shop(shop_config_ref()) -> ok. +activate_shop(ShopConfigRef) -> + change_shop(ShopConfigRef, fun(ShopConfig) -> ShopConfig#domain_ShopConfig{ suspension = {active, #domain_Active{ @@ -638,9 +630,9 @@ activate_shop(ShopID) -> } end). --spec block_shop(party_id()) -> ok. -block_shop(ShopID) -> - change_shop(ShopID, fun(ShopConfig) -> +-spec block_shop(shop_config_ref()) -> ok. +block_shop(ShopConfigRef) -> + change_shop(ShopConfigRef, fun(ShopConfig) -> ShopConfig#domain_ShopConfig{ block = {blocked, #domain_Blocked{ @@ -650,9 +642,9 @@ block_shop(ShopID) -> } end). --spec unblock_shop(party_id()) -> ok. -unblock_shop(ShopID) -> - change_shop(ShopID, fun(ShopConfig) -> +-spec unblock_shop(shop_config_ref()) -> ok. +unblock_shop(ShopConfigRef) -> + change_shop(ShopConfigRef, fun(ShopConfig) -> ShopConfig#domain_ShopConfig{ block = {unblocked, #domain_Unblocked{ @@ -662,27 +654,27 @@ unblock_shop(ShopID) -> } end). -change_shop(ShopID, Fun) -> - ShopConfig0 = hg_domain:get({shop_config, #domain_ShopConfigRef{id = ShopID}}), +change_shop(ShopConfigRef, Fun) -> + ShopConfig0 = hg_domain:get({shop_config, ShopConfigRef}), ShopConfig1 = Fun(ShopConfig0), _ = hg_domain:upsert( {shop_config, #domain_ShopConfigObject{ - ref = #domain_ShopConfigRef{id = ShopID}, + ref = ShopConfigRef, data = ShopConfig1 }} ), ok. -spec create_party_and_shop( - party_id(), + party_config_ref(), category(), currency(), termset_ref(), payment_inst_ref(), party_client() -) -> shop_id(). -create_party_and_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, _Client) -> - ShopID = hg_utils:unique_id(), +) -> shop_config_ref(). +create_party_and_shop(PartyConfigRef, Category, Currency, TermsRef, PaymentInstRef, _Client) -> + ShopConfigRef = #domain_ShopConfigRef{id = hg_utils:unique_id()}, % Создаем Party как объект конфигурации PartyConfig = #domain_PartyConfig{ @@ -698,15 +690,13 @@ create_party_and_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, _Cl suspension = {active, #domain_Active{ since = hg_datetime:format_now() - }}, - shops = [], - wallets = [] + }} }, % Вставляем Party в домен _ = hg_domain:upsert( {party_config, #domain_PartyConfigObject{ - ref = #domain_PartyConfigRef{id = PartyID}, + ref = PartyConfigRef, data = PartyConfig }} ), @@ -737,47 +727,40 @@ create_party_and_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, _Cl }, terms = TermsRef, payment_institution = PaymentInstRef, - party_id = PartyID + party_ref = PartyConfigRef }, % Вставляем Shop в домен _ = hg_domain:upsert( {shop_config, #domain_ShopConfigObject{ - ref = #domain_ShopConfigRef{id = ShopID}, + ref = ShopConfigRef, data = ShopConfig }} ), - change_party(PartyID, fun(PartyConfig0) -> - PartyConfig0#domain_PartyConfig{ - shops = [#domain_ShopConfigRef{id = ShopID}] - } - end), - - ShopID. + ShopConfigRef. -spec create_shop( - party_id(), + party_config_ref(), category(), currency(), termset_ref(), payment_inst_ref(), party_client() -) -> shop_id(). -create_shop(PartyID, Category, Currency, TemplateRef, PaymentInstRef, Client) -> - create_shop(PartyID, Category, Currency, TemplateRef, PaymentInstRef, undefined, Client). +) -> shop_config_ref(). +create_shop(PartyConfigRef, Category, Currency, TemplateRef, PaymentInstRef, Client) -> + create_shop(PartyConfigRef, Category, Currency, TemplateRef, PaymentInstRef, undefined, Client). -spec create_battle_ready_shop( - party_id(), + party_config_ref(), category(), currency(), termset_ref(), payment_inst_ref(), party_client() -) -> shop_id(). -create_battle_ready_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, _PartyPair) -> - ShopID = hg_utils:unique_id(), - PartyConfig = hg_domain:get({party_config, #domain_PartyConfigRef{id = PartyID}}), +) -> shop_config_ref(). +create_battle_ready_shop(PartyConfigRef, Category, Currency, TermsRef, PaymentInstRef, _PartyPair) -> + ShopConfigRef = #domain_ShopConfigRef{id = hg_utils:unique_id()}, % Создаем счета SettlementID = hg_accounting:create_account(Currency), @@ -805,52 +788,53 @@ create_battle_ready_shop(PartyID, Category, Currency, TermsRef, PaymentInstRef, }, payment_institution = PaymentInstRef, terms = TermsRef, - party_id = PartyID + party_ref = PartyConfigRef }, % Вставляем Shop в домен _ = hg_domain:upsert( {shop_config, #domain_ShopConfigObject{ - ref = #domain_ShopConfigRef{id = ShopID}, + ref = ShopConfigRef, data = ShopConfig }} ), - change_party(PartyID, fun(PartyConfig0) -> - PartyConfig0#domain_PartyConfig{ - shops = [#domain_ShopConfigRef{id = ShopID} | PartyConfig#domain_PartyConfig.shops] - } - end), - - ShopID. + ShopConfigRef. --spec make_invoice_params(party_id(), shop_id(), binary(), cash()) -> invoice_params(). -make_invoice_params(PartyID, ShopID, Product, Cost) -> - make_invoice_params(PartyID, ShopID, Product, make_due_date(), Cost). +-spec make_invoice_params(party_config_ref(), shop_config_ref(), binary(), cash()) -> + invoice_params(). +make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Cost) -> + make_invoice_params(PartyConfigRef, ShopConfigRef, Product, make_due_date(), Cost). --spec make_invoice_params(party_id(), shop_id(), binary(), timestamp(), cash()) -> invoice_params(). -make_invoice_params(PartyID, ShopID, Product, Due, Cost) -> +-spec make_invoice_params(party_config_ref(), shop_config_ref(), binary(), timestamp(), cash()) -> + invoice_params(). +make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Due, Cost) -> InvoiceID = hg_utils:unique_id(), - make_invoice_params(InvoiceID, PartyID, ShopID, Product, Due, Cost). + make_invoice_params(InvoiceID, PartyConfigRef, ShopConfigRef, 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) -> - make_invoice_params(InvoiceID, PartyID, ShopID, Product, Due, Cost, undefined). +-spec make_invoice_params( + invoice_id(), party_config_ref(), shop_config_ref(), binary(), timestamp(), cash() +) -> + invoice_params(). +make_invoice_params(InvoiceID, PartyConfigRef, ShopConfigRef, Product, Due, Cost) -> + make_invoice_params(InvoiceID, PartyConfigRef, ShopConfigRef, Product, Due, Cost, undefined). -spec make_invoice_params( invoice_id(), - party_id(), - shop_id(), + party_config_ref(), + shop_config_ref(), binary(), timestamp(), cash(), allocation_prototype() | undefined ) -> invoice_params(). -make_invoice_params(InvoiceID, PartyID, ShopID, Product, Due, Cost, AllocationPrototype) -> +make_invoice_params( + InvoiceID, PartyConfigRef, ShopConfigRef, Product, Due, Cost, AllocationPrototype +) -> #payproc_InvoiceParams{ id = InvoiceID, - party_id = PartyID, - shop_id = ShopID, + party_id = PartyConfigRef, + shop_id = ShopConfigRef, details = make_invoice_details(Product), due = hg_datetime:format_ts(Due), cost = Cost, @@ -866,12 +850,15 @@ make_invoice_params_tpl(TplID) -> make_invoice_params_tpl(TplID, Cost) -> make_invoice_params_tpl(TplID, Cost, undefined). --spec make_invoice_params_tpl(invoice_tpl_id(), undefined | cash(), undefined | context()) -> invoice_params_tpl(). +-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()) -> +-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{ @@ -881,50 +868,69 @@ make_invoice_params_tpl(InvoiceID, TplID, Cost, Context) -> context = Context }. --spec make_invoice_tpl_create_params(party_id(), shop_id(), lifetime_interval(), binary(), invoice_tpl_details()) -> +-spec make_invoice_tpl_create_params( + party_config_ref(), shop_config_ref(), lifetime_interval(), binary(), invoice_tpl_details() +) -> invoice_tpl_create_params(). -make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details) -> - make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details, make_invoice_context()). +make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef, Lifetime, Product, Details) -> + make_invoice_tpl_create_params( + PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, make_invoice_context() + ). -spec make_invoice_tpl_create_params( - party_id(), - shop_id(), + party_config_ref(), + shop_config_ref(), lifetime_interval(), binary(), invoice_tpl_details(), context() ) -> invoice_tpl_create_params(). -make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details, Context) -> +make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, Context) -> InvoiceTemplateID = hg_utils:unique_id(), - make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context). + make_invoice_tpl_create_params( + InvoiceTemplateID, PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, Context + ). -spec make_invoice_tpl_create_params( invoice_template_id(), - party_id(), - shop_id(), + party_config_ref(), + shop_config_ref(), lifetime_interval(), binary(), invoice_tpl_details(), context() ) -> invoice_tpl_create_params(). -make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context) -> - make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context, undefined). +make_invoice_tpl_create_params( + InvoiceTemplateID, PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, Context +) -> + make_invoice_tpl_create_params( + InvoiceTemplateID, + PartyConfigRef, + ShopConfigRef, + Lifetime, + Product, + Details, + Context, + undefined + ). -spec make_invoice_tpl_create_params( invoice_template_id(), - party_id(), - shop_id(), + party_config_ref(), + shop_config_ref(), lifetime_interval(), binary(), invoice_tpl_details(), context(), [mutation()] | undefined ) -> invoice_tpl_create_params(). -make_invoice_tpl_create_params(InvoiceTemplateID, PartyID, ShopID, Lifetime, Product, Details, Context, Mutations) -> +make_invoice_tpl_create_params( + InvoiceTemplateID, PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, Context, Mutations +) -> #payproc_InvoiceTemplateCreateParams{ template_id = InvoiceTemplateID, - party_id = PartyID, - shop_id = ShopID, + party_id = PartyConfigRef, + shop_id = ShopConfigRef, invoice_lifetime = Lifetime, product = Product, details = Details, diff --git a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl index cbbb25bf..0a864cec 100644 --- a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl +++ b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl @@ -104,21 +104,25 @@ init_per_suite(C) -> ]), _ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())), RootUrl = maps:get(hellgate_root_url, Ret), - PartyID = hg_utils:unique_id(), + PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, PartyClient = {party_client:create_client(), party_client:create_context()}, - _ = hg_ct_helper:create_party(PartyID, PartyClient), + _ = hg_ct_helper:create_party(PartyConfigRef, PartyClient), ok = hg_context:save(hg_context:create()), - Shop1ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), undefined, PartyClient), - Shop2ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), undefined, PartyClient), + Shop1ConfigRef = hg_ct_helper:create_shop( + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), undefined, PartyClient + ), + Shop2ConfigRef = hg_ct_helper:create_shop( + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), undefined, PartyClient + ), ok = hg_context:cleanup(), {ok, SupPid} = supervisor:start_link(?MODULE, []), _ = unlink(SupPid), C1 = [ {apps, Apps}, {root_url, RootUrl}, - {party_id, PartyID}, - {shop_id, Shop1ID}, - {another_shop_id, Shop2ID}, + {party_config_ref, PartyConfigRef}, + {shop_config_ref, Shop1ConfigRef}, + {another_shop_config_ref, Shop2ConfigRef}, {test_sup, SupPid} | C ], @@ -192,7 +196,7 @@ second_recurrent_payment_success_test(C) -> -spec another_shop_test(config()) -> test_result(). another_shop_test(C) -> Client = cfg(client, C), - Invoice1ID = start_invoice(cfg(another_shop_id, C), <<"rubberduck">>, make_due_date(10), 42000, C), + Invoice1ID = start_invoice(cfg(another_shop_config_ref, C), <<"rubberduck">>, make_due_date(10), 42000, C), %% first payment in recurrent session Payment1Params = make_payment_params(?pmt_sys(<<"visa-ref">>)), {ok, Payment1ID} = start_payment(Invoice1ID, Payment1Params, Client), @@ -366,13 +370,13 @@ make_due_date(LifetimeSeconds) -> genlib_time:unow() + LifetimeSeconds. start_invoice(Product, Due, Amount, C) -> - start_invoice(cfg(shop_id, C), Product, Due, Amount, C). + start_invoice(cfg(shop_config_ref, C), Product, Due, Amount, C). -start_invoice(ShopID, Product, Due, Amount, C) -> +start_invoice(ShopConfigRef, Product, Due, Amount, C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), Cash = hg_ct_helper:make_cash(Amount, <<"RUB">>), - InvoiceParams = hg_ct_helper:make_invoice_params(PartyID, ShopID, Product, Due, Cash), + InvoiceParams = hg_ct_helper:make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Due, Cash), InvoiceID = create_invoice(InvoiceParams, Client), _Events = await_events(InvoiceID, [?evp(?invoice_created(?invoice_w_status(?invoice_unpaid())))], Client), InvoiceID. diff --git a/apps/hellgate/test/hg_invoice_helper.erl b/apps/hellgate/test/hg_invoice_helper.erl index de387926..9bf3895b 100644 --- a/apps/hellgate/test/hg_invoice_helper.erl +++ b/apps/hellgate/test/hg_invoice_helper.erl @@ -125,28 +125,28 @@ make_cash(Amount) -> make_cash(Amount, Currency) -> hg_ct_helper:make_cash(Amount, Currency). -make_invoice_params(PartyID, ShopID, Product, Due, Cost) -> - hg_ct_helper:make_invoice_params(PartyID, ShopID, Product, Due, Cost). +make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Due, Cost) -> + hg_ct_helper:make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Due, Cost). -spec start_invoice(_, _, _, _) -> _. start_invoice(Product, Due, Amount, C) -> - start_invoice(cfg(shop_id, C), Product, Due, Amount, C). + start_invoice(cfg(shop_config_ref, C), Product, Due, Amount, C). -spec start_invoice(_, _, _, _, _) -> _. -start_invoice(ShopID, Product, Due, Amount, C) -> +start_invoice(ShopConfigRef, Product, Due, Amount, C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), - start_invoice(PartyID, ShopID, Product, Due, Amount, Client). + PartyConfigRef = cfg(party_config_ref, C), + start_invoice(PartyConfigRef, ShopConfigRef, Product, Due, Amount, Client). -spec start_invoice(_, _, _, _, _, _) -> _. -start_invoice(PartyID, ShopID, Product, Due, Amount, Client) -> +start_invoice(PartyConfigRef, ShopConfigRef, Product, Due, Amount, Client) -> % Проверяем, что Party и Shop существуют как объекты конфигурации #domain_PartyConfig{} = - hg_domain:get({party_config, #domain_PartyConfigRef{id = PartyID}}), + hg_domain:get({party_config, PartyConfigRef}), #domain_ShopConfig{} = - hg_domain:get({shop_config, #domain_ShopConfigRef{id = ShopID}}), + hg_domain:get({shop_config, ShopConfigRef}), % Создаем параметры инвойса с помощью существующих функций - InvoiceParams = make_invoice_params(PartyID, ShopID, Product, Due, make_cash(Amount)), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, Product, Due, make_cash(Amount)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), InvoiceID. @@ -340,10 +340,10 @@ await_payment_cash_flow(InvoiceID, PaymentID, Client) -> {CashFlow, Route}. -spec construct_ta_context(_, _, _) -> _. -construct_ta_context(Party, Shop, Route) -> +construct_ta_context(PartyConfigRef, ShopConfigRef, Route) -> #{ - party => Party, - shop => Shop, + party_config_ref => PartyConfigRef, + shop_config_ref => ShopConfigRef, route => Route }. @@ -372,12 +372,15 @@ get_cashflow_volume(Source, Destination, CF, CFContext) -> Volume. -spec convert_transaction_account(_, _) -> _. -convert_transaction_account({merchant, Type}, #{party := Party, shop := Shop}) -> +convert_transaction_account( + {merchant, Type}, + #{party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef} +) -> {merchant, #domain_MerchantTransactionAccount{ type = Type, owner = #domain_MerchantTransactionAccountOwner{ - party_id = Party, - shop_id = Shop + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef } }}; convert_transaction_account({provider, Type}, #{route := Route}) -> diff --git a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl index 34f26eac..0c121aaa 100644 --- a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl @@ -99,17 +99,19 @@ init_per_suite(C) -> RootUrl = maps:get(hellgate_root_url, Ret), _ = hg_limiter_helper:init_per_suite(C), _ = hg_domain:insert(construct_domain_fixture()), - PartyID = hg_utils:unique_id(), + PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, PartyClient = {party_client:create_client(), party_client:create_context()}, ok = hg_context:save(hg_context:create()), - ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + ShopConfigRef = hg_ct_helper:create_party_and_shop( + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient + ), ok = hg_context:cleanup(), {ok, SupPid} = supervisor:start_link(?MODULE, []), _ = unlink(SupPid), ok = hg_invoice_helper:start_kv_store(SupPid), NewC = [ - {party_id, PartyID}, - {shop_id, ShopID}, + {party_config_ref, PartyConfigRef}, + {shop_config_ref, ShopConfigRef}, {root_url, RootUrl}, {test_sup, SupPid}, {apps, Apps} @@ -433,13 +435,13 @@ payment_w_crypto_currency_success(C) -> PaymentParams = make_payment_params(PaymentTool, Session, instant), ?payment_state(#domain_InvoicePayment{ id = PaymentID, - owner_id = PartyID, - shop_id = ShopID + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef }) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(PartyID, ShopID, Route), + CFContext = construct_ta_context(PartyConfigRef, ShopConfigRef, Route), ?cash(PayCash, <<"RUB">>) = get_cashflow_volume({provider, settlement}, {merchant, settlement}, CF, CFContext), ?cash(36, <<"RUB">>) = get_cashflow_volume({system, settlement}, {provider, settlement}, CF, CFContext), ?cash(90, <<"RUB">>) = get_cashflow_volume({merchant, settlement}, {system, settlement}, CF, CFContext). @@ -478,9 +480,9 @@ payment_has_optional_fields(C) -> ?payment_route(Route) = InvoicePayment, ?payment_cashflow(CashFlow) = InvoicePayment, ?payment_last_trx(TrxInfo) = InvoicePayment, - PartyID = cfg(party_id, C), - ShopID = cfg(shop_id, C), - #domain_InvoicePayment{owner_id = PartyID, shop_id = ShopID} = Payment, + PartyConfigRef = cfg(party_config_ref, C), + ShopConfigRef = cfg(shop_config_ref, C), + #domain_InvoicePayment{party_ref = PartyConfigRef, shop_ref = ShopConfigRef} = Payment, false = Route =:= undefined, false = CashFlow =:= undefined, false = TrxInfo =:= undefined. @@ -569,8 +571,8 @@ await_payment_capture(InvoiceID, PaymentID, Client) -> await_payment_cash_flow(InvoiceID, PaymentID, Client) -> hg_invoice_helper:await_payment_cash_flow(InvoiceID, PaymentID, Client). -construct_ta_context(PartyID, ShopID, Route) -> - hg_invoice_helper:construct_ta_context(PartyID, ShopID, Route). +construct_ta_context(PartyConfigRef, ShopConfigRef, Route) -> + hg_invoice_helper:construct_ta_context(PartyConfigRef, ShopConfigRef, Route). get_cashflow_volume(Source, Destination, CF, CFContext) -> hg_invoice_helper:get_cashflow_volume(Source, Destination, CF, CFContext). diff --git a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl index 425dfddb..c0997207 100644 --- a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl @@ -42,7 +42,7 @@ -type config() :: hg_ct_helper:config(). -type test_case_name() :: hg_ct_helper:test_case_name(). --define(MISSING_SHOP_ID, <<"42">>). +-define(MISSING_SHOP_CONFIG_REF, #domain_ShopConfigRef{id = <<"42">>}). -define(invoice_tpl(ID), #domain_InvoiceTemplate{id = ID}). @@ -93,15 +93,16 @@ init_per_suite(C) -> ]), _ = hg_domain:insert(construct_domain_fixture()), RootUrl = maps:get(hellgate_root_url, Ret), - PartyID = hg_utils:unique_id(), + PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, Client = {party_client:create_client(), party_client:create_context()}, ok = hg_context:save(hg_context:create()), - ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), Client), + ShopConfigRef = + hg_ct_helper:create_party_and_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), Client), ok = hg_context:cleanup(), [ - {party_id, PartyID}, + {party_config_ref, PartyConfigRef}, {party_client, Client}, - {shop_id, ShopID}, + {shop_config_ref, ShopConfigRef}, {root_url, RootUrl}, {apps, Apps} | C @@ -129,42 +130,42 @@ end_per_testcase(_Name, _C) -> -spec create_invalid_shop(config()) -> _. create_invalid_shop(C) -> Client = cfg(client, C), - ShopID = ?MISSING_SHOP_ID, - PartyID = cfg(party_id, C), - Params = make_invoice_tpl_create_params(PartyID, ShopID), + ShopConfigRef = ?MISSING_SHOP_CONFIG_REF, + PartyConfigRef = cfg(party_config_ref, C), + Params = make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef), {exception, #payproc_ShopNotFound{}} = hg_client_invoice_templating:create(Params, Client). -spec create_invalid_party_status(config()) -> _. create_invalid_party_status(C) -> - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = create_invoice_tpl(C), - ok = hg_ct_helper:activate_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:block_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = create_invoice_tpl(C), - ok = hg_ct_helper:unblock_party(PartyID). + ok = hg_ct_helper:unblock_party(PartyConfigRef). -spec create_invalid_shop_status(config()) -> _. create_invalid_shop_status(C) -> - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = create_invoice_tpl(C), - ok = hg_ct_helper:activate_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:block_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = create_invoice_tpl(C), - ok = hg_ct_helper:unblock_shop(ShopID). + ok = hg_ct_helper:unblock_shop(ShopConfigRef). -spec create_invalid_cost_fixed_amount(config()) -> _. create_invalid_cost_fixed_amount(C) -> @@ -240,68 +241,68 @@ make_mutations(Deviation) -> -spec get_invoice_template_anyhow(config()) -> _. get_invoice_template_anyhow(C) -> - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), InvoiceTpl = ?invoice_tpl(TplID) = create_invoice_tpl(C), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), InvoiceTpl = hg_client_invoice_templating:get(TplID, Client), - ok = hg_ct_helper:activate_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:block_party(PartyConfigRef), InvoiceTpl = hg_client_invoice_templating:get(TplID, Client), - ok = hg_ct_helper:unblock_party(PartyID), + ok = hg_ct_helper:unblock_party(PartyConfigRef), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), InvoiceTpl = hg_client_invoice_templating:get(TplID, Client), - ok = hg_ct_helper:activate_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:block_shop(ShopConfigRef), InvoiceTpl = hg_client_invoice_templating:get(TplID, Client), - ok = hg_ct_helper:unblock_shop(ShopID), + ok = hg_ct_helper:unblock_shop(ShopConfigRef), InvoiceTpl = hg_client_invoice_templating:get(TplID, Client). -spec update_invalid_party_status(config()) -> _. update_invalid_party_status(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), Diff = make_invoice_tpl_update_params( #{details => hg_ct_helper:make_invoice_tpl_details(<<"teddy bear">>, make_cost(fixed, 42, <<"RUB">>))} ), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoice_templating:update(TplID, Diff, Client), - ok = hg_ct_helper:activate_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:block_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoice_templating:update(TplID, Diff, Client), - ok = hg_ct_helper:unblock_party(PartyID). + ok = hg_ct_helper:unblock_party(PartyConfigRef). -spec update_invalid_shop_status(config()) -> _. update_invalid_shop_status(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), Diff = make_invoice_tpl_update_params( #{details => hg_ct_helper:make_invoice_tpl_details(<<"teddy bear">>, make_cost(fixed, 42, <<"RUB">>))} ), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoice_templating:update(TplID, Diff, Client), - ok = hg_ct_helper:activate_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:block_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoice_templating:update(TplID, Diff, Client), - ok = hg_ct_helper:unblock_shop(ShopID). + ok = hg_ct_helper:unblock_shop(ShopConfigRef). -spec update_invalid_cost_fixed_amount(config()) -> _. update_invalid_cost_fixed_amount(C) -> @@ -340,8 +341,8 @@ update_invalid_cost_range(C) -> -spec update_invoice_template(config()) -> _. update_invoice_template(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), - ShopID = cfg(shop_id, C), + PartyConfigRef = cfg(party_config_ref, C), + ShopConfigRef = cfg(shop_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), NewProduct = <<"teddy bear">>, CostUnlim = make_cost(unlim, sale, "50%"), @@ -355,8 +356,8 @@ update_invoice_template(C) -> Tpl1 = #domain_InvoiceTemplate{ id = TplID, - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, product = NewProduct, details = NewDetails, invoice_lifetime = NewLifetime @@ -379,8 +380,8 @@ update_cost(Cost, Tpl, Client) -> -spec update_with_cart(config()) -> _. update_with_cart(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), - ShopID = cfg(shop_id, C), + PartyConfigRef = cfg(party_config_ref, C), + ShopConfigRef = cfg(shop_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), NewDetails = {cart, #domain_InvoiceCart{ @@ -404,8 +405,8 @@ update_with_cart(C) -> }), #domain_InvoiceTemplate{ id = TplID, - owner_id = PartyID, - shop_id = ShopID, + party_ref = PartyConfigRef, + shop_ref = ShopConfigRef, details = NewDetails } = hg_client_invoice_templating:update(TplID, Diff, Client), #domain_InvoiceTemplate{} = hg_client_invoice_templating:get(TplID, Client). @@ -434,40 +435,40 @@ update_with_mutations(C) -> -spec delete_invalid_party_status(config()) -> _. delete_invalid_party_status(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoice_templating:delete(TplID, Client), - ok = hg_ct_helper:activate_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:block_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoice_templating:delete(TplID, Client), - ok = hg_ct_helper:unblock_party(PartyID). + ok = hg_ct_helper:unblock_party(PartyConfigRef). -spec delete_invalid_shop_status(config()) -> _. delete_invalid_shop_status(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoice_templating:delete(TplID, Client), - ok = hg_ct_helper:activate_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:block_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoice_templating:delete(TplID, Client), - ok = hg_ct_helper:unblock_shop(ShopID). + ok = hg_ct_helper:unblock_shop(ShopConfigRef). -spec delete_invoice_template(config()) -> _. delete_invoice_template(C) -> @@ -519,28 +520,28 @@ terms_retrieval(C) -> create_invoice_tpl(Config) -> Client = cfg(client, Config), - ShopID = cfg(shop_id, Config), - PartyID = cfg(party_id, Config), - Params = make_invoice_tpl_create_params(PartyID, ShopID), + ShopConfigRef = cfg(shop_config_ref, Config), + PartyConfigRef = cfg(party_config_ref, Config), + Params = make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef), hg_client_invoice_templating:create(Params, Client). create_invoice_tpl(Config, Product, Lifetime, Cost) -> Client = cfg(client, Config), - ShopID = cfg(shop_id, Config), - PartyID = cfg(party_id, Config), + ShopConfigRef = cfg(shop_config_ref, Config), + PartyConfigRef = cfg(party_config_ref, Config), Details = hg_ct_helper:make_invoice_tpl_details(Product, Cost), - Params = make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details), + Params = make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef, Lifetime, Product, Details), hg_client_invoice_templating:create(Params, Client). create_invoice_tpl_w_mutations(Config, Product, Lifetime, Cost, Mutations) -> Client = cfg(client, Config), - ShopID = cfg(shop_id, Config), - PartyID = cfg(party_id, Config), + ShopConfigRef = cfg(shop_config_ref, Config), + PartyConfigRef = cfg(party_config_ref, Config), Details = hg_ct_helper:make_invoice_tpl_details(Product, Cost), Params = hg_ct_helper:make_invoice_tpl_create_params( hg_utils:unique_id(), - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, Lifetime, Product, Details, @@ -569,11 +570,11 @@ create_invalid_cost(Cost, Error, Config) -> {exception, #base_InvalidRequest{errors = [Error]}} = create_invoice_tpl(Config, Product, Lifetime, Cost), ok. -make_invoice_tpl_create_params(PartyID, ShopID) -> +make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef) -> Lifetime = make_lifetime(0, 0, 2), Product = <<"rubberduck">>, Details = hg_ct_helper:make_invoice_tpl_details(Product, make_cost(fixed, 5000, <<"RUB">>)), - make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details). + make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef, Lifetime, Product, Details). make_cost(Type, P1, P2) -> hg_ct_helper:make_invoice_tpl_cost(Type, P1, P2). diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 87e54ff3..22165ebd 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -219,10 +219,15 @@ init([]) -> -type group_name() :: hg_ct_helper:group_name(). -type test_return() :: _ | no_return(). --define(PARTY_ID_WITH_LIMIT, <<"bIg merch limit">>). --define(PARTY_ID_WITH_SEVERAL_LIMITS, <<"bIg merch limit cascading">>). --define(PARTY_ID_WITH_SHOP_LIMITS, <<"small merch limit shop">>). --define(PARTYID_EXTERNAL, <<"DUBTV">>). +-define(PARTY_CONFIG_REF, #domain_PartyConfigRef{id = <<"bIg merch">>}). +-define(PARTY_CONFIG_REF_WITH_LIMIT, #domain_PartyConfigRef{id = <<"bIg merch limit">>}). +-define(PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS, #domain_PartyConfigRef{ + id = <<"bIg merch limit cascading">> +}). +-define(PARTY_CONFIG_REF_WITH_SHOP_LIMITS, #domain_PartyConfigRef{id = <<"small merch limit shop">>}). +-define(PARTY_CONFIG_REF_EXTERNAL, #domain_PartyConfigRef{id = <<"DUBTV">>}). +-define(PARTY_CONFIG_REF_DEPRIVED_1, #domain_PartyConfigRef{id = <<"DEPRIVED">>}). +-define(PARTY_CONFIG_REF_DEPRIVED_2, #domain_PartyConfigRef{id = <<"DEPRIVED2">>}). -define(LIMIT_ID, <<"ID">>). -define(LIMIT_ID2, <<"ID2">>). -define(LIMIT_ID3, <<"ID3">>). @@ -510,23 +515,35 @@ init_per_suite(C) -> ]), BaseLimitsRevision = hg_limiter_helper:init_per_suite(C), - _BaseRevision = hg_domain:insert(construct_domain_fixture()), + _ = logger:error("BaseLimitsRevision: ~p", [BaseLimitsRevision]), RootUrl = maps:get(hellgate_root_url, Ret), - PartyID = hg_utils:unique_id(), + PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, PartyClient = {party_client:create_client(), party_client:create_context()}, - Party2ID = hg_utils:unique_id(), + Party2ConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, PartyClient2 = {party_client:create_client(), party_client:create_context()}, - Party3ID = <<"bIg merch">>, - _ = hg_ct_helper:create_party(Party3ID, PartyClient), - _ = hg_ct_helper:create_party(?PARTYID_EXTERNAL, PartyClient), + Party3ConfigRef = ?PARTY_CONFIG_REF, + _ = hg_ct_helper:create_party(Party3ConfigRef, PartyClient), + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_EXTERNAL, PartyClient), + + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_DEPRIVED_1, PartyClient), + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_DEPRIVED_2, PartyClient), + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_WITH_LIMIT, PartyClient), + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS, PartyClient), + _ = hg_ct_helper:create_party(?PARTY_CONFIG_REF_WITH_SHOP_LIMITS, PartyClient), + + _BaseRevision = hg_domain:insert(construct_domain_fixture(BaseLimitsRevision)), ok = hg_context:save(hg_context:create()), - ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - Shop2ID = hg_ct_helper:create_party_and_shop(Party2ID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient2), + ShopConfigRef = hg_ct_helper:create_party_and_shop( + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient + ), + Shop2ConfigRef = hg_ct_helper:create_party_and_shop( + Party2ConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient2 + ), ok = hg_context:cleanup(), {ok, SupPid} = supervisor:start_link(?MODULE, []), @@ -534,12 +551,12 @@ init_per_suite(C) -> ok = start_kv_store(SupPid), _ = mock_fault_detector(SupPid), NewC = [ - {party_id, PartyID}, + {party_config_ref, PartyConfigRef}, {party_client, PartyClient}, - {party_id_big_merch, Party3ID}, - {shop_id, ShopID}, - {another_party_id, Party2ID}, - {another_shop_id, Shop2ID}, + {party_config_ref_big_merch, Party3ConfigRef}, + {shop_config_ref, ShopConfigRef}, + {another_party_config_ref, Party2ConfigRef}, + {another_shop_config_ref, Shop2ConfigRef}, {root_url, RootUrl}, {apps, Apps}, {test_sup, SupPid}, @@ -783,11 +800,11 @@ maybe_end_trace(C) -> -spec invoice_creation_idempotency(config()) -> _ | no_return(). invoice_creation_idempotency(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), InvoiceID = hg_utils:unique_id(), ExternalID = <<"123">>, - InvoiceParams0 = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100000, <<"RUB">>)), + InvoiceParams0 = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000, <<"RUB">>)), InvoiceParams1 = InvoiceParams0#payproc_InvoiceParams{ id = InvoiceID, external_id = ExternalID @@ -804,33 +821,33 @@ invoice_creation_idempotency(C) -> -spec invalid_invoice_shop(config()) -> _ | no_return(). invalid_invoice_shop(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), - ShopID = genlib:unique(), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(10000)), + PartyConfigRef = cfg(party_config_ref, C), + ShopConfigRef = #domain_ShopConfigRef{id = hg_utils:unique_id()}, + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(10000)), {exception, #payproc_ShopNotFound{}} = hg_client_invoicing:create(InvoiceParams, Client). -spec invalid_invoice_amount(config()) -> test_return(). invalid_invoice_amount(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), - InvoiceParams0 = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(-10000)), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), + InvoiceParams0 = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(-10000)), {exception, #base_InvalidRequest{ errors = [<<"Invalid amount">>] }} = hg_client_invoicing:create(InvoiceParams0, Client), - InvoiceParams1 = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(5)), + InvoiceParams1 = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(5)), {exception, #payproc_InvoiceTermsViolated{reason = {invoice_unpayable, _}}} = hg_client_invoicing:create(InvoiceParams1, Client), - InvoiceParams2 = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(42000000000)), + InvoiceParams2 = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(42000000000)), {exception, #payproc_InvoiceTermsViolated{reason = {invoice_unpayable, _}}} = hg_client_invoicing:create(InvoiceParams2, Client). -spec invalid_invoice_currency(config()) -> test_return(). invalid_invoice_currency(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100, <<"KEK">>)), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100, <<"KEK">>)), {exception, #base_InvalidRequest{ errors = [<<"Invalid currency">>] }} = hg_client_invoicing:create(InvoiceParams, Client). @@ -838,56 +855,56 @@ invalid_invoice_currency(C) -> -spec invalid_party_status(config()) -> test_return(). invalid_party_status(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100000)), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:create(InvoiceParams, Client), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:create_with_tpl(InvoiceParamsWithTpl, Client), - ok = hg_ct_helper:activate_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:block_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:create(InvoiceParams, Client), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:create_with_tpl(InvoiceParamsWithTpl, Client), - ok = hg_ct_helper:unblock_party(PartyID). + ok = hg_ct_helper:unblock_party(PartyConfigRef). -spec invalid_shop_status(config()) -> test_return(). invalid_shop_status(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(100000)), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:create(InvoiceParams, Client), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:create_with_tpl(InvoiceParamsWithTpl, Client), - ok = hg_ct_helper:activate_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:block_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:create(InvoiceParams, Client), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:create_with_tpl(InvoiceParamsWithTpl, Client), - ok = hg_ct_helper:unblock_shop(ShopID). + ok = hg_ct_helper:unblock_shop(ShopConfigRef). -spec invalid_invoice_template_cost(config()) -> _ | no_return(). invalid_invoice_template_cost(C) -> @@ -953,8 +970,8 @@ invoice_w_template_idempotency(C) -> TplContext1 = hg_ct_helper:make_invoice_context(<<"default context">>), TplID = create_invoice_tpl(C, TplCost1, TplContext1), #domain_InvoiceTemplate{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, context = TplContext1 } = get_invoice_tpl(TplID, C), InvoiceCost1 = FixedCost, @@ -968,8 +985,8 @@ invoice_w_template_idempotency(C) -> }, ?invoice_state(#domain_Invoice{ id = InvoiceID, - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = InvoiceContext1, @@ -982,8 +999,8 @@ invoice_w_template_idempotency(C) -> }, ?invoice_state(#domain_Invoice{ id = InvoiceID, - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = InvoiceContext1, @@ -997,15 +1014,15 @@ invoice_w_template_amount_randomization(C) -> TplCost1 = {_, FixedCost} = make_tpl_cost(fixed, OriginalAmount, <<"RUB">>), TplContext1 = hg_ct_helper:make_invoice_context(<<"default context">>), TplClient = cfg(client_tpl, C), - PartyID = cfg(party_id, C), - ShopID = cfg(shop_id, C), + PartyConfigRef = cfg(party_config_ref, C), + ShopConfigRef = cfg(shop_config_ref, C), Lifetime = hg_ct_helper:make_lifetime(0, 1, 0), Product = <<"rubberduck">>, Details = hg_ct_helper:make_invoice_tpl_details(Product, TplCost1), TplParams = #payproc_InvoiceTemplateCreateParams{ template_id = hg_utils:unique_id(), - party_id = PartyID, - shop_id = ShopID, + party_id = PartyConfigRef, + shop_id = ShopConfigRef, invoice_lifetime = Lifetime, product = Product, details = Details, @@ -1039,8 +1056,8 @@ invoice_w_template(C) -> TplContext1 = hg_ct_helper:make_invoice_context(<<"default context">>), TplID = create_invoice_tpl(C, TplCost1, TplContext1), #domain_InvoiceTemplate{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, context = TplContext1 } = get_invoice_tpl(TplID, C), InvoiceCost1 = FixedCost, @@ -1048,8 +1065,8 @@ invoice_w_template(C) -> Params1 = hg_ct_helper:make_invoice_params_tpl(TplID, InvoiceCost1, InvoiceContext1), ?invoice_state(#domain_Invoice{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = InvoiceContext1 @@ -1057,8 +1074,8 @@ invoice_w_template(C) -> Params2 = hg_ct_helper:make_invoice_params_tpl(TplID), ?invoice_state(#domain_Invoice{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = TplContext1 @@ -1067,8 +1084,8 @@ invoice_w_template(C) -> TplCost2 = make_tpl_cost(range, {inclusive, 100, <<"RUB">>}, {inclusive, 10000, <<"RUB">>}), _ = update_invoice_tpl(TplID, TplCost2, C), ?invoice_state(#domain_Invoice{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = InvoiceContext1 @@ -1077,8 +1094,8 @@ invoice_w_template(C) -> TplCost3 = make_tpl_cost(unlim, sale, "146%"), _ = update_invoice_tpl(TplID, TplCost3, C), ?invoice_state(#domain_Invoice{ - owner_id = TplPartyID, - shop_id = TplShopID, + party_ref = TplPartyRef, + shop_ref = TplShopRef, template_id = TplID, cost = InvoiceCost1, context = InvoiceContext1 @@ -1087,9 +1104,9 @@ invoice_w_template(C) -> -spec invoice_cancellation(config()) -> test_return(). invoice_cancellation(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - PartyID = cfg(party_id, C), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(10000)), + ShopConfigRef = cfg(shop_config_ref, C), + PartyConfigRef = cfg(party_config_ref, C), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(10000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invalid_invoice_status(_) = hg_client_invoicing:fulfill(InvoiceID, <<"perfect">>, Client), ok = hg_client_invoicing:rescind(InvoiceID, <<"whynot">>, Client). @@ -1154,17 +1171,14 @@ register_invoice_payment(Route, ShopID, Client, C) -> -spec init_operation_limits_group(config()) -> config(). init_operation_limits_group(C) -> - PartyID1 = ?PARTY_ID_WITH_LIMIT, - PartyID2 = ?PARTY_ID_WITH_SEVERAL_LIMITS, - PartyID3 = ?PARTY_ID_WITH_SHOP_LIMITS, - _ = hg_ct_helper:create_party(PartyID1, cfg(party_client, C)), - _ = hg_ct_helper:create_party(PartyID2, cfg(party_client, C)), - _ = hg_ct_helper:create_party(PartyID3, cfg(party_client, C)), + PartyConfigRef1 = ?PARTY_CONFIG_REF_WITH_LIMIT, + PartyConfigRef2 = ?PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS, + PartyConfigRef3 = ?PARTY_CONFIG_REF_WITH_SHOP_LIMITS, [ {limits, #{ - party_id => PartyID1, - party_id_w_several_limits => PartyID2, - party_id_w_shop_limits => PartyID3 + party_config_ref => PartyConfigRef1, + party_config_ref_w_several_limits => PartyConfigRef2, + party_config_ref_w_shop_limits => PartyConfigRef3 }} | C ]. @@ -1173,20 +1187,20 @@ init_operation_limits_group(C) -> payment_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment)] - ) = create_payment(PartyID, ShopID, 10000, Client, ?pmt_sys(<<"visa-ref">>)). + ) = create_payment(PartyConfigRef, ShopConfigRef, 10000, Client, ?pmt_sys(<<"visa-ref">>)). -spec payment_shop_limit_success(config()) -> test_return(). payment_shop_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), TurnoverLimits = [ #domain_TurnoverLimit{ id = ?SHOPLIMIT_ID, @@ -1194,20 +1208,21 @@ payment_shop_limit_success(C) -> domain_revision = hg_domain:head() } ], - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1, ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment)] - ) = create_payment(PartyID, ShopID, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)). + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)). -spec payment_shop_limit_overflow(config()) -> test_return(). payment_shop_limit_overflow(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), TurnoverLimits = ordsets:from_list([ #domain_TurnoverLimit{ id = ?SHOPLIMIT_ID, @@ -1215,11 +1230,14 @@ payment_shop_limit_overflow(C) -> domain_revision = hg_domain:head() } ]), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PaymentAmount = ?LIMIT_UPPER_BOUNDARY + 1, - Failure = create_payment_shop_limit_overflow(PartyID, ShopID, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)), + Failure = create_payment_shop_limit_overflow( + PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>) + ), ok = payproc_errors:match('PaymentFailure', Failure, fun( {authorization_failed, {shop_limit_exceeded, {unknown, _}}} ) -> @@ -1230,7 +1248,7 @@ payment_shop_limit_overflow(C) -> payment_shop_limit_more_overflow(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), TurnoverLimits = ordsets:from_list([ #domain_TurnoverLimit{ id = ?SHOPLIMIT_ID, @@ -1238,16 +1256,19 @@ payment_shop_limit_more_overflow(C) -> domain_revision = hg_domain:head() } ]), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1, ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment)] - ) = create_payment(PartyID, ShopID, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)), + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)), - Failure = create_payment_shop_limit_overflow(PartyID, ShopID, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)), + Failure = create_payment_shop_limit_overflow( + PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>) + ), ok = payproc_errors:match('PaymentFailure', Failure, fun( {authorization_failed, {shop_limit_exceeded, {unknown, _}}} ) -> @@ -1258,8 +1279,8 @@ payment_shop_limit_more_overflow(C) -> payment_routes_limit_values(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), #payproc_Invoice{ @@ -1267,7 +1288,7 @@ payment_routes_limit_values(C) -> payments = [ #payproc_InvoicePayment{payment = #domain_InvoicePayment{id = PaymentId}} ] - } = create_payment(PartyID, ShopID, 10000, Client, ?pmt_sys(<<"visa-ref">>)), + } = create_payment(PartyConfigRef, ShopConfigRef, 10000, Client, ?pmt_sys(<<"visa-ref">>)), Route = ?route(?prv(5), ?trm(12)), #{ Route := [ @@ -1282,11 +1303,11 @@ payment_routes_limit_values(C) -> register_payment_limit_success(C0) -> Client = cfg(client, C0), PartyClient = cfg(party_client, C0), - #{party_id := PartyID} = cfg(limits, C0), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - C1 = [{party_id, PartyID}, {shop_id, ShopID} | C0], + #{party_config_ref := PartyConfigRef} = cfg(limits, C0), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + C1 = [{party_config_ref, PartyConfigRef}, {shop_config_ref, ShopConfigRef} | C0], Route = ?route(?prv(5), ?trm(12)), - {InvoiceID, PaymentID} = register_invoice_payment(Route, ShopID, Client, C1), + {InvoiceID, PaymentID} = register_invoice_payment(Route, ShopConfigRef, Client, C1), ?invoice_state(?invoice_w_status(?invoice_paid())) = hg_client_invoicing:get(InvoiceID, Client), ?payment_state(?payment_w_status(PaymentID, ?captured())) = @@ -1297,43 +1318,50 @@ payment_limit_other_shop_success(C) -> PmtSys = ?pmt_sys(<<"visa-ref">>), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID1 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - ShopID2 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef1 = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + ShopConfigRef2 = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1, ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment1)] - ) = create_payment(PartyID, ShopID1, PaymentAmount, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef1, PaymentAmount, Client, PmtSys), ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment2)] - ) = create_payment(PartyID, ShopID2, PaymentAmount, Client, PmtSys). + ) = create_payment(PartyConfigRef, ShopConfigRef2, PaymentAmount, Client, PmtSys). -spec payment_limit_overflow(config()) -> test_return(). payment_limit_overflow(C) -> PmtSys = ?pmt_sys(<<"visa-ref">>), RootUrl = cfg(root_url, C), - #{party_id := PartyID} = cfg(limits, C), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1, ?invoice_state( ?invoice_w_status(?invoice_paid()) = Invoice, [?payment_state(Payment)] - ) = create_payment(PartyID, ShopID, PaymentAmount, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, PmtSys), - Failure = create_payment_limit_overflow(PartyID, ShopID, 1000, Client, PmtSys), + Failure = create_payment_limit_overflow(PartyConfigRef, ShopConfigRef, 1000, Client, PmtSys), + _ = logger:error("configured_limit_version(?LIMIT_ID, C): ~p", [configured_limit_version(?LIMIT_ID, C)]), + Res = dmt_client:checkout_object( + configured_limit_version(?LIMIT_ID, C), {limit_config, #domain_LimitConfigRef{id = ?LIMIT_ID}} + ), + _ = logger:error("dmt_client:checkout_object({limit_config, #domain_LimitConfigRef{id = ?LIMIT_ID}}: ~p", [Res]), ok = hg_limiter_helper:assert_payment_limit_amount( ?LIMIT_ID, configured_limit_version(?LIMIT_ID, C), PaymentAmount, Payment, Invoice ), - ok = payproc_errors:match('PaymentFailure', Failure, fun({no_route_found, {rejected, {limit_overflow, _}}}) -> - ok - end). + ok = payproc_errors:match( + 'PaymentFailure', + Failure, + fun({no_route_found, {rejected, {limit_overflow, _}}}) -> ok end + ). -spec limit_hold_currency_error(config()) -> test_return(). limit_hold_currency_error(C) -> @@ -1364,12 +1392,12 @@ payment_route_not_found(C) -> payment_route_not_found(PaymentTool, Session, C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), Cash = make_cash(10000, <<"RUB">>), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), Cash), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), Cash), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -1386,22 +1414,23 @@ switch_provider_after_limit_overflow(C) -> PmtSys = ?pmt_sys(<<"visa-ref">>), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id_w_several_limits := PartyID} = cfg(limits, C), + #{party_config_ref_w_several_limits := PartyConfigRef} = cfg(limits, C), PaymentAmount = 69999, - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), ?invoice_state( ?invoice_w_status(?invoice_paid()) = Invoice, [?payment_state(Payment)] - ) = create_payment(PartyID, ShopID, PaymentAmount, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, PmtSys), ok = hg_limiter_helper:assert_payment_limit_amount( ?LIMIT_ID, configured_limit_version(?LIMIT_ID, C), PaymentAmount, Payment, Invoice ), #domain_InvoicePayment{id = PaymentID} = Payment, - InvoiceID = start_invoice(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), PaymentAmount, Client), + InvoiceID = + start_invoice(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), PaymentAmount, Client), ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( InvoiceID, make_payment_params(PmtSys), @@ -1418,15 +1447,15 @@ limit_not_found(C) -> PmtSys = ?pmt_sys(<<"visa-ref">>), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id_w_several_limits := PartyID} = cfg(limits, C), + #{party_config_ref_w_several_limits := PartyConfigRef} = cfg(limits, C), PaymentAmount = 69999, - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), ?invoice_state( ?invoice_w_status(?invoice_paid()) = Invoice, [?payment_state(Payment)] - ) = create_payment(PartyID, ShopID, PaymentAmount, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, PmtSys), {exception, _} = hg_limiter_helper:get_payment_limit_amount(<<"WrongID">>, 0, Payment, Invoice). @@ -1435,26 +1464,28 @@ refund_limit_success(C) -> PmtSys = ?pmt_sys(<<"visa-ref">>), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_Payment)] - ) = create_payment(PartyID, ShopID, 50000, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef, 50000, Client, PmtSys), ?invoice_state( ?invoice_w_status(?invoice_paid()) = Invoice, [?payment_state(Payment)] - ) = create_payment(PartyID, ShopID, 40000, Client, PmtSys), + ) = create_payment(PartyConfigRef, ShopConfigRef, 40000, Client, PmtSys), ?invoice(InvoiceID) = Invoice, ?payment(PaymentID) = Payment, - Failure = create_payment_limit_overflow(PartyID, ShopID, 50000, Client, PmtSys), - ok = payproc_errors:match('PaymentFailure', Failure, fun({no_route_found, {rejected, {limit_overflow, _}}}) -> - ok - end), + Failure = create_payment_limit_overflow(PartyConfigRef, ShopConfigRef, 50000, Client, PmtSys), + ok = payproc_errors:match( + 'PaymentFailure', + Failure, + fun({no_route_found, {rejected, {limit_overflow, _}}}) -> ok end + ), % create a refund finally RefundParams = make_refund_params(), RefundID = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), @@ -1467,7 +1498,7 @@ refund_limit_success(C) -> ?invoice_state( ?invoice_w_status(?invoice_paid()), [?payment_state(_)] - ) = create_payment(PartyID, ShopID, 40000, Client, PmtSys). + ) = create_payment(PartyConfigRef, ShopConfigRef, 40000, Client, PmtSys). -spec payment_partial_capture_limit_success(config()) -> test_return(). payment_partial_capture_limit_success(C) -> @@ -1477,11 +1508,13 @@ payment_partial_capture_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(100), make_cash(InitialCost)), + InvoiceParams = make_invoice_params( + PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(100), make_cash(InitialCost) + ), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -1502,15 +1535,19 @@ payment_partial_capture_limit_success(C) -> InvoiceState = hg_client_invoicing:get(InvoiceID, Client), ?invoice_state(Invoice, [PaymentState]) = InvoiceState, ?assertMatch(?invoice_w_status(?invoice_paid()), Invoice), - ?assertMatch(?payment_state(?payment_w_status(PaymentID, ?captured(Reason, Cash))), PaymentState), + ?assertMatch( + ?payment_state(?payment_w_status(PaymentID, ?captured(Reason, Cash))), + PaymentState + ), ?payment_cashflow(CF2) = PaymentState, ?assertNotEqual(undefined, CF2), ?assertNotEqual(CF1, CF2). %%----------------- operation_limits helpers -create_payment(PartyID, ShopID, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), +create_payment(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -1518,8 +1555,9 @@ create_payment(PartyID, ShopID, Amount, Client, PmtSys) -> _PaymentID = execute_payment(InvoiceID, PaymentParams, Client), hg_client_invoicing:get(InvoiceID, Client). -create_payment_limit_overflow(PartyID, ShopID, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), +create_payment_limit_overflow(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), PaymentParams = make_payment_params(PmtSys), @@ -1527,8 +1565,9 @@ create_payment_limit_overflow(PartyID, ShopID, Amount, Client, PmtSys) -> PaymentID = await_payment_started(InvoiceID, PaymentID, Client), await_payment_rollback(InvoiceID, PaymentID, Client). -create_payment_shop_limit_overflow(PartyID, ShopID, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), +create_payment_shop_limit_overflow(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), PaymentParams = make_payment_params(PmtSys), @@ -1540,12 +1579,13 @@ create_payment_shop_limit_overflow(PartyID, ShopID, Amount, Client, PmtSys) -> -spec payment_success_ruleset(config()) -> test_return(). payment_success_ruleset(C) -> - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), @@ -1604,7 +1644,7 @@ payment_w_misconfigured_routing_failed_fixture(_Revision, _C) -> {delegates, [ ?delegate( <<"Inexistent merchant">>, - {condition, {party, #domain_PartyCondition{id = hg_utils:unique_id()}}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF_DEPRIVED_1}}}, ?ruleset(1) ), ?delegate( @@ -1853,13 +1893,14 @@ payment_partial_capture_success(C) -> -spec payment_error_in_cancel_session_does_not_cause_payment_failure(config()) -> test_return(). payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = hg_party:get_shop(ShopID, Party), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), + {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _GuaranteeID} = hg_invoice_utils:get_shop_account(Shop), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(1000), 42000, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}, ?pmt_sys(<<"visa-ref">>)), PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch(#{max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), @@ -1878,15 +1919,16 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> -spec payment_error_in_capture_session_does_not_cause_payment_failure(config()) -> test_return(). payment_error_in_capture_session_does_not_cause_payment_failure(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), Amount = 42000, Cost = ?cash(Amount, <<"RUB">>), - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = hg_party:get_shop(ShopID, Party), + {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _GuaranteeID} = hg_invoice_utils:get_shop_account(Shop), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}, ?pmt_sys(<<"visa-ref">>)), PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), @@ -1929,12 +1971,15 @@ payment_success_ruleset_provider_available(C) -> with_fault_detector( mk_fd_stat(?prv(1), {0.5, 0.5}), fun() -> - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = make_invoice_params( + PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000) + ), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), @@ -1962,12 +2007,15 @@ route_found_provider_lacking_conversion(C) -> with_fault_detector( mk_fd_stat(?prv(1), {0.9, 0.5}), fun() -> - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = make_invoice_params( + PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000) + ), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -1982,12 +2030,13 @@ route_found_provider_lacking_conversion(C) -> ). failed_payment_wo_cascade(C) -> - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -2053,7 +2102,7 @@ payment_bank_card_category_condition(C) -> ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), ?cash(200, <<"RUB">>) = get_cashflow_volume({merchant, settlement}, {system, settlement}, CF, CFContext). -spec payment_success_on_second_try(config()) -> test_return(). @@ -2098,16 +2147,16 @@ payment_success_with_increased_cost(C) -> -spec refund_payment_with_increased_cost(config()) -> test_return(). refund_payment_with_increased_cost(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), Amount = 42000, NewAmount = 2 * Amount, % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), NewAmount, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Amount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Amount, C), {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_increase, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), @@ -2124,7 +2173,7 @@ refund_payment_with_increased_cost(C) -> ?payment_ev(PaymentID, ?payment_status_changed(?processed())) ] = next_changes(InvoiceID, 5, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF, CFContext), @@ -2155,9 +2204,18 @@ refund_payment_with_increased_cost(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF, CFContext), #domain_Cash{amount = MrcAmountFixed} = hg_cashflow:compute_volume(?merchant_to_system_fixed, Context), - ?assertEqual(maps:get(own_amount, MrcAccount2), maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed), - ?assertEqual(maps:get(own_amount, PrvAccount2), maps:get(own_amount, PrvAccount1) + NewAmount), - ?assertEqual(MrcAmountFixed, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)). + ?assertEqual( + maps:get(own_amount, MrcAccount2), + maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed + ), + ?assertEqual( + maps:get(own_amount, PrvAccount2), + maps:get(own_amount, PrvAccount1) + NewAmount + ), + ?assertEqual( + MrcAmountFixed, + maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1) + ). -spec payment_success_with_decreased_cost(config()) -> test_return(). payment_success_with_decreased_cost(C) -> @@ -2180,16 +2238,16 @@ payment_success_with_decreased_cost(C) -> -spec refund_payment_with_decreased_cost(config()) -> test_return(). refund_payment_with_decreased_cost(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), Amount = 42000, NewAmount = Amount div 2, % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), NewAmount, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Amount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Amount, C), {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_decrease, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), @@ -2206,7 +2264,7 @@ refund_payment_with_decreased_cost(C) -> ?payment_ev(PaymentID, ?payment_status_changed(?processed())) ] = next_changes(InvoiceID, 5, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF, CFContext), @@ -2237,9 +2295,18 @@ refund_payment_with_decreased_cost(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF, CFContext), #domain_Cash{amount = MrcAmountFixed} = hg_cashflow:compute_volume(?merchant_to_system_fixed, Context), - ?assertEqual(maps:get(own_amount, MrcAccount2), maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed), - ?assertEqual(maps:get(own_amount, PrvAccount2), maps:get(own_amount, PrvAccount1) + NewAmount), - ?assertEqual(MrcAmountFixed, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)). + ?assertEqual( + maps:get(own_amount, MrcAccount2), + maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed + ), + ?assertEqual( + maps:get(own_amount, PrvAccount2), + maps:get(own_amount, PrvAccount1) + NewAmount + ), + ?assertEqual( + MrcAmountFixed, + maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1) + ). execute_cash_changed_payment(InvoiceID, PaymentParams, Client) -> PaymentID = hg_invoice_helper:start_payment(InvoiceID, PaymentParams, Client), @@ -2303,7 +2370,7 @@ payments_w_bank_card_issuer_conditions(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(4), @@ -2351,7 +2418,7 @@ payments_w_bank_conditions(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(4), @@ -2520,7 +2587,7 @@ payment_adjustment_success(C) -> next_change(InvoiceID, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), @@ -2590,7 +2657,7 @@ payment_adjustment_w_amount_success(C) -> next_change(InvoiceID, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), @@ -2631,9 +2698,18 @@ payment_adjustment_w_amount_success(C) -> {NewOpDiffMrc, NewOpDiffSys, NewOpDiffPrv} = compute_operation_amount_diffs( NewAmount, ?merchant_to_system_share_1, ?system_to_provider_share_actual, ?system_to_external_fixed ), - ?assertEqual(NewOpDiffMrc - OpDiffMrc, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), - ?assertEqual(NewOpDiffPrv - OpDiffPrv, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), - ?assertEqual(NewOpDiffSys - OpDiffSys, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)), + ?assertEqual( + NewOpDiffMrc - OpDiffMrc, + maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1) + ), + ?assertEqual( + NewOpDiffPrv - OpDiffPrv, + maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1) + ), + ?assertEqual( + NewOpDiffSys - OpDiffSys, + maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1) + ), ?payment_state(#domain_InvoicePayment{cost = OriginalCost, changed_cost = NewCost}) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -2643,8 +2719,9 @@ payment_adjustment_w_amount_success(C) -> payment_adjustment_refunded_success(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_shop(cfg(party_id, C), ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 10000, C), + ShopConfigRef = + hg_ct_helper:create_shop(cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 10000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), CashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), _RefundID = execute_payment_refund(InvoiceID, PaymentID, make_refund_params(1000, <<"RUB">>), Client), @@ -2679,12 +2756,12 @@ payment_adjustment_refunded_success(C) -> -spec payment_adjustment_chargeback_success(config()) -> test_return(). payment_adjustment_chargeback_success(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), % % Контракт на основе шаблона ?trms(1) - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(3), ?pinst(1), PartyPair), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(3), ?pinst(1), PartyPair), % {ShopID, Shop} = hg_party:get_shop(PartyID, ShopID, PartyClient, , hg_party:get_party_revision()), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 10000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 10000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), CashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), Params = make_chargeback_params(?cash(10000, <<"RUB">>)), @@ -2722,9 +2799,9 @@ payment_adjustment_captured_partial(C) -> InitialCost = 1000 * 100, PartialCost = 700 * 100, Client = cfg(client, C), - ShopID = cfg(shop_id, C), - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(1)), - InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), InitialCost, C), + ShopConfigRef = cfg(shop_config_ref, C), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(1)), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), InitialCost, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), % start payment ?payment_state(?payment(PaymentID)) = @@ -2739,14 +2816,14 @@ payment_adjustment_captured_partial(C) -> ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, Reason, Cash, Client), PaymentID = await_payment_partial_capture(InvoiceID, PaymentID, Reason, Cash, Client), % get balances - CFContext = construct_ta_context(cfg(party_id, C), ShopID, Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), ShopConfigRef, Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), % update terminal cashflow ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), % update merchant fees - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(3)), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(3)), % make an adjustment Params = make_adjustment_params(AdjReason = <<"because punk you that's why">>), AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, Params, Client), @@ -2774,10 +2851,10 @@ payment_adjustment_captured_partial(C) -> -spec payment_adjustment_captured_from_failed(config()) -> test_return(). payment_adjustment_captured_from_failed(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(1)), + ShopConfigRef = cfg(shop_config_ref, C), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(1)), Amount = 42000, - InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(3), Amount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(3), Amount, C), PaymentParams = make_scenario_payment_params([temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), CaptureAmount = Amount div 2, CaptureCost = ?cash(CaptureAmount, <<"RUB">>), @@ -2795,14 +2872,14 @@ payment_adjustment_captured_from_failed(C) -> await_payment_process_failure(InvoiceID, PaymentID, Client, 3), ?invoice_status_changed(?invoice_cancelled(<<"overdue">>)) = next_change(InvoiceID, Client), % get balances - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), % update terminal cashflow ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), % update merchant fees - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(3)), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(3)), InvalidAdjustmentParams1 = make_status_adjustment_params({processed, #domain_InvoicePaymentProcessed{}}), ?invalid_payment_target_status(?processed()) = @@ -2845,10 +2922,10 @@ payment_adjustment_captured_from_failed(C) -> -spec payment_adjustment_failed_from_captured(config()) -> test_return(). payment_adjustment_failed_from_captured(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(1)), + ShopConfigRef = cfg(shop_config_ref, C), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(1)), Amount = 100000, - InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Amount, C), %% start payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), @@ -2858,14 +2935,14 @@ payment_adjustment_failed_from_captured(C) -> PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), % get balances - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), % update terminal cashflow ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), % update merchant fees - ok = hg_ct_helper:shop_set_terms(ShopID, ?trms(3)), + ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(3)), % make an adjustment Failed = ?failed({failure, #domain_Failure{code = <<"404">>}}), AdjustmentParams = make_status_adjustment_params(Failed, AdjReason = <<"because i can">>), @@ -2905,7 +2982,7 @@ payment_adjustment_change_amount_and_captured(C) -> %% DIFF---| 95500 | 2400 | -97900 | 0 Client = cfg(client, C), - % PartyID = cfg(party_id, C), + % PartyID = cfg(party_config_ref, C), % {PartyClient, PartyCtx} = PartyPair = cfg(party_client, C), % {ShopID, Shop} = hg_party:get_shop(PartyID, cfg(shop_id, C), hg_party:get_party_revision()), @@ -2927,7 +3004,7 @@ payment_adjustment_change_amount_and_captured(C) -> PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), @@ -3050,8 +3127,8 @@ payment_adjustment_change_amount_and_refund_all(C) -> %% DIFF---| 95500 | 2400 | -97900 | 0 Client = cfg(client, C), - % PartyID = cfg(party_id, C), - ShopID = cfg(shop_id, C), + % PartyID = cfg(party_config_ref, C), + ShopConfigRef = cfg(shop_config_ref, C), % {PartyClient, PartyCtx} = PartyPair = cfg(party_client, C), % {ShopID, Shop} = hg_party:get_shop(PartyID, ShopID, hg_party:get_party_revision()), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(initial)), @@ -3060,7 +3137,7 @@ payment_adjustment_change_amount_and_refund_all(C) -> NewAmount = 200000, % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), NewAmount, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), @@ -3070,7 +3147,7 @@ payment_adjustment_change_amount_and_refund_all(C) -> ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) = next_change(InvoiceID, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), @@ -3145,16 +3222,25 @@ payment_adjustment_change_amount_and_refund_all(C) -> Context2 = #{operation_amount => ChangedCost}, #domain_Cash{amount = MrcAmountFixed} = hg_cashflow:compute_volume(?merchant_to_system_fixed, Context2), - ?assertEqual(maps:get(own_amount, MrcAccount2), maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed), - ?assertEqual(maps:get(own_amount, PrvAccount2), maps:get(own_amount, PrvAccount1) + NewAmount), - ?assertEqual(MrcAmountFixed, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)). + ?assertEqual( + maps:get(own_amount, MrcAccount2), + maps:get(own_amount, MrcAccount1) - NewAmount - MrcAmountFixed + ), + ?assertEqual( + maps:get(own_amount, PrvAccount2), + maps:get(own_amount, PrvAccount1) + NewAmount + ), + ?assertEqual( + MrcAmountFixed, + maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1) + ). -spec status_adjustment_of_partial_refunded_payment(config()) -> test_return(). status_adjustment_of_partial_refunded_payment(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), @@ -3213,7 +3299,7 @@ registered_payment_adjustment_success(C) -> PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), PrvAccount1 = get_deprecated_cashflow_account({provider, settlement}, CF1, CFContext), SysAccount1 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount1 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), @@ -3311,8 +3397,8 @@ compute_operation_amount_diffs(Amount, MrcSysShare, SysPrvShare, SysExtShare) -> SysPrv = compute_operation_amount_share(Amount, SysPrvShare), {Amount - MrcSys, MrcSys - SysPrv - SysExt, SysPrv - Amount}. -construct_ta_context(Party, Shop, Route) -> - hg_invoice_helper:construct_ta_context(Party, Shop, Route). +construct_ta_context(PartyConfigRef, ShopConfigRef, Route) -> + hg_invoice_helper:construct_ta_context(PartyConfigRef, ShopConfigRef, Route). get_deprecated_cashflow_account(Type, CF, CFContext) -> ID = get_deprecated_cashflow_account_id(Type, CF, CFContext), @@ -3336,12 +3422,14 @@ get_deprecated_cashflow_account_id(Type, CF, CFContext) -> -spec invalid_payment_w_deprived_party(config()) -> test_return(). invalid_payment_w_deprived_party(C) -> - PartyID = <<"DEPRIVED ONE-II">>, + PartyConfigRef = ?PARTY_CONFIG_REF_DEPRIVED_2, RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_party_and_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, InvoicingClient), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, InvoicingClient), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), @@ -3351,12 +3439,14 @@ invalid_payment_w_deprived_party(C) -> -spec external_account_posting(config()) -> test_return(). external_account_posting(C) -> % Party создается в инициализации suite - PartyID = ?PARTYID_EXTERNAL, + PartyConfigRef = ?PARTY_CONFIG_REF_EXTERNAL, RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubbermoss">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, InvoicingClient), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, InvoicingClient), ?payment_state( @@ -3379,7 +3469,7 @@ external_account_posting(C) -> details = <<"Kek">> } <- CF ], - CFContext = construct_ta_context(PartyID, ShopID, Route), + CFContext = construct_ta_context(PartyConfigRef, ShopConfigRef, Route), AssistAccountID = get_deprecated_cashflow_account_id({external, outcome}, CF, CFContext), #domain_ExternalAccountSet{ accounts = #{?cur(<<"RUB">>) := #domain_ExternalAccount{outcome = AssistAccountID}} @@ -3388,12 +3478,14 @@ external_account_posting(C) -> -spec terminal_cashflow_overrides_provider(config()) -> test_return(). terminal_cashflow_overrides_provider(C) -> % Party создается в инициализации suite - PartyID = ?PARTYID_EXTERNAL, + PartyConfigRef = ?PARTY_CONFIG_REF_EXTERNAL, RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(4), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(4), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubbermoss">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, InvoicingClient), _ = next_change(InvoiceID, InvoicingClient), ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( @@ -3416,7 +3508,7 @@ terminal_cashflow_overrides_provider(C) -> details = <<"Kek">> } <- CF ], - CFContext = construct_ta_context(PartyID, ShopID, Route), + CFContext = construct_ta_context(PartyConfigRef, ShopConfigRef, Route), AssistAccountID = get_deprecated_cashflow_account_id({external, outcome}, CF, CFContext), #domain_ExternalAccountSet{ accounts = #{?cur(<<"RUB">>) := #domain_ExternalAccount{outcome = AssistAccountID}} @@ -3429,15 +3521,15 @@ create_chargeback_not_allowed(C) -> Cost = 42000, Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Cost, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Cost, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), CBParams = make_chargeback_params(?cash(1000, <<"RUB">>)), Result = hg_client_invoicing:create_chargeback(InvoiceID, PaymentID, CBParams, Client), @@ -3449,15 +3541,15 @@ create_chargeback_provision_terms_not_allowed(C) -> Cost = 42000, Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Cost, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Cost, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), CBParams = make_chargeback_params(?cash(1000, <<"RUB">>)), Result = hg_client_invoicing:create_chargeback(InvoiceID, PaymentID, CBParams, Client), @@ -4446,17 +4538,18 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> start_chargeback(C, Cost, CBParams, PaymentParams) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = hg_party:get_shop(ShopID, Party), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), + {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _} = hg_invoice_utils:get_shop_account(Shop), Settlement0 = hg_accounting:get_balance(SettlementID), % 0.045 Fee = 1890, ?assertEqual(0, maps:get(min_available_amount, Settlement0)), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Cost, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Cost, C), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), Settlement1 = hg_accounting:get_balance(SettlementID), ?assertEqual(Cost - Fee, maps:get(min_available_amount, Settlement1)), @@ -4465,17 +4558,18 @@ start_chargeback(C, Cost, CBParams, PaymentParams) -> start_chargeback_partial_capture(C, Cost, Partial, CBParams, PmtSys) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), Cash = ?cash(Partial, <<"RUB">>), PartyPair = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), - {PartyID, Party} = hg_party:get_party(PartyID), - {ShopID, Shop} = hg_party:get_shop(ShopID, Party), + ShopConfigRef = + hg_ct_helper:create_battle_ready_shop(PartyConfigRef, ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyPair), + {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), + {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _} = hg_invoice_utils:get_shop_account(Shop), Settlement0 = hg_accounting:get_balance(SettlementID), % Fee = 450, % 0.045 ?assertEqual(0, maps:get(min_available_amount, Settlement0)), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), Cost, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), Cost, C), {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, PmtSys), PaymentParams = make_payment_params(PaymentTool, Session, {hold, cancel}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), @@ -4499,36 +4593,36 @@ start_chargeback_partial_capture(C, Cost, Partial, CBParams, PmtSys) -> -spec invalid_refund_party_status(config()) -> _ | no_return(). invalid_refund_party_status(C) -> Client = cfg(client, C), - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), - ok = hg_ct_helper:suspend_party(PartyID), + ok = hg_ct_helper:suspend_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, make_refund_params(), Client), - ok = hg_ct_helper:activate_party(PartyID), - ok = hg_ct_helper:block_party(PartyID), + ok = hg_ct_helper:activate_party(PartyConfigRef), + ok = hg_ct_helper:block_party(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, make_refund_params(), Client), - ok = hg_ct_helper:unblock_party(PartyID). + ok = hg_ct_helper:unblock_party(PartyConfigRef). -spec invalid_refund_shop_status(config()) -> _ | no_return(). invalid_refund_shop_status(C) -> Client = cfg(client, C), - ShopID = cfg(shop_id, C), + ShopConfigRef = cfg(shop_config_ref, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), - ok = hg_ct_helper:suspend_shop(ShopID), + ok = hg_ct_helper:suspend_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} }} = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, make_refund_params(), Client), - ok = hg_ct_helper:activate_shop(ShopID), - ok = hg_ct_helper:block_shop(ShopID), + ok = hg_ct_helper:activate_shop(ShopConfigRef), + ok = hg_ct_helper:block_shop(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {blocking, {blocked, _}} }} = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, make_refund_params(), Client), - ok = hg_ct_helper:unblock_shop(ShopID). + ok = hg_ct_helper:unblock_shop(ShopConfigRef). -spec payment_refund_idempotency(config()) -> _ | no_return(). payment_refund_idempotency(C) -> @@ -4575,15 +4669,15 @@ payment_refund_idempotency(C) -> payment_refund_success(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, capture}), Client), RefundParams = make_refund_params(), % not finished yet @@ -4605,7 +4699,7 @@ payment_refund_success(C) -> ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally RefundID = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), @@ -4619,15 +4713,15 @@ payment_refund_success(C) -> payment_refund_failure(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentParams = make_scenario_payment_params([good, good, fail], {hold, capture}, ?pmt_sys(<<"visa-ref">>)), PaymentID = process_payment(InvoiceID, PaymentParams, Client), RefundParams = make_refund_params(), @@ -4650,7 +4744,7 @@ payment_refund_failure(C) -> ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally ?refund_id(RefundID) = @@ -4670,8 +4764,8 @@ payment_refund_failure(C) -> payment_refund_success_after_callback(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), @@ -4679,10 +4773,10 @@ payment_refund_success_after_callback(C) -> PartyClient ), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % start invoice that will be refunded - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), %% simulate user interaction @@ -4726,15 +4820,15 @@ payment_refund_success_after_callback(C) -> deadline_doesnt_affect_payment_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), % ms ProcessingDeadline = 4000, PaymentParams = set_processing_deadline( @@ -4762,7 +4856,7 @@ deadline_doesnt_affect_payment_refund(C) -> ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally RefundID = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), @@ -4773,15 +4867,15 @@ deadline_doesnt_affect_payment_refund(C) -> payment_manual_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), TrxInfo = ?trx_info(<<"test">>, #{}), RefundParams = #payproc_InvoicePaymentRefundParams{ @@ -4805,7 +4899,7 @@ payment_manual_refund(C) -> ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 3, Client), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % prevent proxy access OriginalRevision = hg_domain:head(), @@ -4824,19 +4918,19 @@ payment_manual_refund(C) -> payment_partial_refunds_success(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundParams0 = make_refund_params(43000, <<"RUB">>), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 3000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 3000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % refund amount exceeds payment amount ?invoice_payment_amount_exceeded(_) = @@ -4908,15 +5002,15 @@ payment_partial_refunds_success(C) -> invalid_currency_payment_partial_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundParams1 = make_refund_params(50, <<"EUR">>), ?inconsistent_refund_currency(<<"EUR">>) = @@ -4927,15 +5021,15 @@ invalid_amount_payment_partial_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), InvoiceAmount = 42000, - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), InvoiceAmount, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), InvoiceAmount, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundParams1 = make_refund_params(50, <<"RUB">>), {exception, #base_InvalidRequest{ @@ -4986,15 +5080,15 @@ invalid_amount_partial_capture_and_refund(C) -> cant_start_simultaneous_partial_refunds(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundParams = make_refund_params(10000, <<"RUB">>), ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), @@ -5026,15 +5120,15 @@ cant_start_simultaneous_partial_refunds(C) -> ineligible_payment_partial_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(100), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundParams = make_refund_params(5000, <<"RUB">>), ?operation_not_permitted() = @@ -5044,15 +5138,15 @@ ineligible_payment_partial_refund(C) -> retry_temporary_unavailability_refund(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentParams = make_scenario_payment_params([good, good, temp, temp], ?pmt_sys(<<"visa-ref">>)), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), RefundParams1 = make_refund_params(1000, <<"RUB">>), @@ -5081,20 +5175,20 @@ retry_temporary_unavailability_refund(C) -> payment_refund_id_types(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), ?pinst(2), PartyClient ), - InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), TrxInfo = ?trx_info(<<"test">>, #{}), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create refund RefundParams = #payproc_InvoicePaymentRefundParams{ @@ -5130,8 +5224,8 @@ payment_refund_id_types(C) -> -spec registered_payment_manual_refund_success(config()) -> test_return(). registered_payment_manual_refund_success(C) -> Client = cfg(client, C), - ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + ShopConfigRef = hg_ct_helper:create_battle_ready_shop( + cfg(party_config_ref, C), ?cat(2), <<"RUB">>, ?trms(2), @@ -5140,11 +5234,11 @@ registered_payment_manual_refund_success(C) -> ), %% create balance - InvoiceID1 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 50000, C), + InvoiceID1 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 50000, C), _PaymentID1 = execute_payment(InvoiceID1, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), %% register_payment - {InvoiceID, PaymentID} = register_invoice_payment(ShopID, Client, C), + {InvoiceID, PaymentID} = register_invoice_payment(ShopConfigRef, Client, C), RefundParams = make_manual_refund_params(), RefundID = execute_payment_manual_refund(InvoiceID, PaymentID, RefundParams, Client), @@ -5316,7 +5410,7 @@ invalid_permit_partial_capture_in_service(C) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(5), @@ -5364,7 +5458,7 @@ rounding_cashflow_volume(C) -> {CF, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), - CFContext = construct_ta_context(cfg(party_id, C), cfg(shop_id, C), Route), + CFContext = construct_ta_context(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), ?cash(0, <<"RUB">>) = get_cashflow_volume({provider, settlement}, {merchant, settlement}, CF, CFContext), ?cash(1, <<"RUB">>) = get_cashflow_volume({system, settlement}, {provider, settlement}, CF, CFContext), ?cash(1, <<"RUB">>) = get_cashflow_volume({system, settlement}, {system, subagent}, CF, CFContext), @@ -5568,11 +5662,12 @@ repair_fail_routing_succeeded(C) -> RootUrl = cfg(root_url, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), %% Invoice - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(10000)), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(10000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -5626,11 +5721,12 @@ repair_fail_cash_flow_building_succeeded(C) -> RootUrl = cfg(root_url, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PartyClient = cfg(party_client, C), - #{party_id := PartyID} = cfg(limits, C), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + #{party_config_ref := PartyConfigRef} = cfg(limits, C), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), %% Invoice - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(10000)), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(10000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), @@ -5890,14 +5986,12 @@ consistent_account_balances(C) -> end end, - {_PartyID, Party} = hg_party:get_party(cfg(party_id, C)), - #domain_PartyConfig{shops = Shops} = Party, + Shops = hg_party:get_shops_by_party_config_ref(cfg(party_config_ref, C), hg_domain:head()), _ = lists:foreach( - fun(#domain_ShopConfigRef{id = ShopID}) -> - {ShopID, Shop} = hg_party:get_shop(ShopID, Party), - {ID1, ID2} = hg_invoice_utils:get_shop_account(Shop), - ok = Fun(ID1, Shop), - ok = Fun(ID2, Shop) + fun({shop_config, #domain_ShopConfigObject{data = Data}}) -> + {ID1, ID2} = hg_invoice_utils:get_shop_account(Data), + ok = Fun(ID1, Data), + ok = Fun(ID2, Data) end, Shops ), @@ -5938,8 +6032,12 @@ cascade_fixture_pre_shop_create(Revision, C) -> payment_cascade_fail_wo_available_attempt_limit_fixture_pre(Revision, C) ++ payment_cascade_fail_provider_error_fixture_pre(Revision, C). +shop_id_from_config_ref(ConfigRef) -> + #domain_ShopConfigRef{id = ShopID} = ConfigRef, + ShopID. + cascade_fixture(Revision, C) -> - PartyID = cfg(party_id, C), + PartyConfigRef = cfg(party_config_ref, C), [ hg_ct_fixture:construct_payment_routing_ruleset( @@ -5947,46 +6045,83 @@ cascade_fixture(Revision, C) -> <<"Multiple routes with failing providers">>, {delegates, [ ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, + shop_id_from_config_ref( + cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, C) + )} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, + shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID)) ), ?delegate( ?partycond( - PartyID, - {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, C)} + PartyConfigRef, + {shop_is, + shop_id_from_config_ref( + cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, C) + )} ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_FAILURES_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, + shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, + shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, + shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID)) ), ?delegate( - ?partycond(PartyID, {shop_is, cfg({shop_id, ?PAYMENT_CASCADE_FAIL_UI_ID}, C)}), + ?partycond( + PartyConfigRef, + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_UI_ID}, C))} + ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID)) ) ]} @@ -6004,20 +6139,20 @@ cascade_fixture(Revision, C) -> payment_cascade_deadline_failures_fixture(Revision, C). init_route_cascading_group(C1) -> - PartyID = cfg(party_id, C1), + PartyConfigRef = cfg(party_config_ref, C1), PartyClient = cfg(party_client, C1), Revision = hg_domain:head(), ok = hg_context:save(hg_context:create()), _ = hg_domain:upsert(cascade_fixture_pre_shop_create(Revision, C1)), C2 = [ { - {shop_id, ?PAYMENT_CASCADE_SUCCESS_ID}, - hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) + {shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { - {shop_id, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, + {shop_config_ref, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID)), @@ -6026,9 +6161,9 @@ init_route_cascading_group(C1) -> ) }, { - {shop_id, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, + {shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID)), @@ -6037,13 +6172,13 @@ init_route_cascading_group(C1) -> ) }, { - {shop_id, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, - hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) + {shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { - {shop_id, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, + {shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID)), @@ -6052,17 +6187,17 @@ init_route_cascading_group(C1) -> ) }, { - {shop_id, ?PAYMENT_CASCADE_FAILURES_ID}, - hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) + {shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { - {shop_id, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, - hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) + {shop_config_ref, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { - {shop_id, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, + {shop_config_ref, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID)), @@ -6071,9 +6206,9 @@ init_route_cascading_group(C1) -> ) }, { - {shop_id, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, + {shop_config_ref, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID)), @@ -6082,9 +6217,9 @@ init_route_cascading_group(C1) -> ) }, { - {shop_id, ?PAYMENT_CASCADE_FAIL_UI_ID}, + {shop_config_ref, ?PAYMENT_CASCADE_FAIL_UI_ID}, hg_ct_helper:create_shop( - PartyID, + PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID)), @@ -6099,35 +6234,35 @@ init_route_cascading_group(C1) -> [{base_limits_domain_revision, Revision} | C2]. init_per_cascade_case(payment_cascade_success, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_fail_wo_route_candidates, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_success_w_refund, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_big_cascade_success, C) -> - ShopID = cfg({shop_id, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_limit_overflow, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_fail_wo_available_attempt_limit, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_failures, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_FAILURES_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_deadline_failures, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_fail_provider_error, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(payment_cascade_fail_ui, C) -> - ShopID = cfg({shop_id, ?PAYMENT_CASCADE_FAIL_UI_ID}, C), - [{shop_id, ShopID} | C]; + ShopConfigRef = cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_UI_ID}, C), + [{shop_config_ref, ShopConfigRef} | C]; init_per_cascade_case(_Name, C) -> C. @@ -6201,8 +6336,8 @@ payment_cascade_success(C) -> Client = cfg(client, C), Amount = 42000, InvoiceParams = make_invoice_params( - cfg(party_id, C), - cfg(shop_id, C), + cfg(party_config_ref, C), + cfg(shop_config_ref, C), <<"rubberduck">>, make_due_date(10), make_cash(Amount) @@ -6236,7 +6371,11 @@ payment_cascade_success(C) -> ] = next_changes(InvoiceID, 4, Client), {Route1, _CashFlow1, TrxID1, Failure1} = await_cascade_triggering(InvoiceID, PaymentID, Client), - ok = payproc_errors:match('PaymentFailure', Failure1, fun({preauthorization_failed, {card_blocked, _}}) -> ok end), + ok = payproc_errors:match( + 'PaymentFailure', + Failure1, + fun({preauthorization_failed, {card_blocked, _}}) -> ok end + ), %% Assert payment status IS NOT failed ?invoice_state(?invoice_w_status(_), [?payment_state(PaymentInterim)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -6361,10 +6500,10 @@ payment_cascade_success_w_refund_fixture(Revision, _C) -> payment_cascade_success_w_refund(C) -> Client = cfg(client, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - InvoiceID = start_invoice(cfg(shop_id, C), <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID = start_invoice(cfg(shop_config_ref, C), <<"rubberduck">>, make_due_date(10), 42000, C), {PaymentID, [_FailedRoute, _UsedRoute]} = execute_payment_w_cascade(InvoiceID, PaymentParams, Client, 1), % top up merchant account - InvoiceID2 = start_invoice(cfg(shop_id, C), <<"rubberduck">>, make_due_date(10), 42000, C), + InvoiceID2 = start_invoice(cfg(shop_config_ref, C), <<"rubberduck">>, make_due_date(10), 42000, C), {_PaymentID2, _Routes} = execute_payment_w_cascade(InvoiceID2, PaymentParams, Client, 1), RefundID = execute_payment_refund(InvoiceID, PaymentID, make_refund_params(), Client), #domain_InvoicePaymentRefund{status = ?refund_succeeded()} = @@ -6585,8 +6724,8 @@ payment_cascade_limit_overflow(C) -> Client = cfg(client, C), Amount = 42000 + ?LIMIT_UPPER_BOUNDARY, InvoiceParams = make_invoice_params( - cfg(party_id, C), - cfg(shop_id, C), + cfg(party_config_ref, C), + cfg(shop_config_ref, C), <<"rubberduck">>, make_due_date(10), make_cash(Amount) @@ -6647,8 +6786,8 @@ payment_big_cascade_success(C) -> Client = cfg(client, C), Amount = 42000, InvoiceParams = make_invoice_params( - cfg(party_id, C), - cfg(shop_id, C), + cfg(party_config_ref, C), + cfg(shop_config_ref, C), <<"rubberduck">>, make_due_date(10), make_cash(Amount) @@ -6703,7 +6842,8 @@ payment_big_cascade_success(C) -> ] = next_changes(InvoiceID, 2, Client), ?assertMatch( - #domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1))}, RouteFinal + #domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1))}, + RouteFinal ), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), @@ -7359,12 +7499,14 @@ payment_cascade_deadline_failures(C) -> -spec payment_tool_contact_info_passed_to_provider(config()) -> test_return(). payment_tool_contact_info_passed_to_provider(C) -> - PartyID = cfg(party_id_big_merch, C), + PartyConfigRef = cfg(party_config_ref_big_merch, C), RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), - InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)), + ShopConfigRef = + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), + InvoiceParams = + make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(42000)), InvoiceID = create_invoice(InvoiceParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), PaymentID = process_payment( @@ -7450,12 +7592,14 @@ create_invoice_tpl(Config) -> create_invoice_tpl(Config, Cost, Context) -> Client = cfg(client_tpl, Config), - PartyID = cfg(party_id, Config), - ShopID = cfg(shop_id, Config), + PartyConfigRef = cfg(party_config_ref, Config), + ShopConfigRef = cfg(shop_config_ref, Config), Lifetime = hg_ct_helper:make_lifetime(0, 1, 0), Product = <<"rubberduck">>, Details = hg_ct_helper:make_invoice_tpl_details(Product, Cost), - Params = hg_ct_helper:make_invoice_tpl_create_params(PartyID, ShopID, Lifetime, Product, Details, Context), + Params = hg_ct_helper:make_invoice_tpl_create_params( + PartyConfigRef, ShopConfigRef, Lifetime, Product, Details, Context + ), #domain_InvoiceTemplate{id = TplID} = hg_client_invoice_templating:create(Params, Client), TplID. @@ -7641,11 +7785,11 @@ repair_invoice_with_scenario(InvoiceID, Scenario, Client) -> start_invoice(Product, Due, Amount, C) -> hg_invoice_helper:start_invoice(Product, Due, Amount, C). -start_invoice(ShopID, Product, Due, Amount, C) -> - hg_invoice_helper:start_invoice(ShopID, Product, Due, Amount, C). +start_invoice(ShopConfigRef, Product, Due, Amount, C) -> + hg_invoice_helper:start_invoice(ShopConfigRef, Product, Due, Amount, C). -start_invoice(PartyID, ShopID, Product, Due, Amount, Client) -> - hg_invoice_helper:start_invoice(PartyID, ShopID, Product, Due, Amount, Client). +start_invoice(PartyConfigRef, ShopConfigRef, Product, Due, Amount, Client) -> + hg_invoice_helper:start_invoice(PartyConfigRef, ShopConfigRef, Product, Due, Amount, Client). start_payment(InvoiceID, PaymentParams, Client) -> hg_invoice_helper:start_payment(InvoiceID, PaymentParams, Client). @@ -7986,7 +8130,7 @@ payment_risk_score_check(Cat, C, PmtSys) -> Client = cfg(client, C), PartyClient = cfg(party_client, C), ShopID = hg_ct_helper:create_battle_ready_shop( - cfg(party_id, C), + cfg(party_config_ref, C), ?cat(Cat), <<"RUB">>, ?trms(2), @@ -8020,8 +8164,8 @@ get_payment_cashflow_mapped(InvoiceID, PaymentID, Client) -> ]. % --spec construct_domain_fixture() -> [hg_domain:object()]. -construct_domain_fixture() -> +-spec construct_domain_fixture(hg_domain:revision()) -> [hg_domain:object()]. +construct_domain_fixture(BaseLimitsRevision) -> TestTermSet = #domain_TermSet{ payments = #domain_PaymentsServiceTerms{ currencies = @@ -8038,11 +8182,11 @@ construct_domain_fixture() -> payment_methods = {decisions, [ #domain_PaymentMethodDecision{ - if_ = ?partycond(<<"DEPRIVED ONE">>, undefined), + if_ = ?partycond(?PARTY_CONFIG_REF_DEPRIVED_1, undefined), then_ = {value, ordsets:new()} }, #domain_PaymentMethodDecision{ - if_ = ?partycond(<<"DEPRIVED ONE-II">>, undefined), + if_ = ?partycond(?PARTY_CONFIG_REF_DEPRIVED_2, undefined), then_ = {value, ordsets:new()} }, #domain_PaymentMethodDecision{ @@ -8407,17 +8551,17 @@ construct_domain_fixture() -> {delegates, [ ?delegate( <<"Important merch">>, - {condition, {party, #domain_PartyCondition{id = <<"bIg merch">>}}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF}}}, ?ruleset(1) ), ?delegate( <<"Provider with turnover limit">>, - {condition, {party, #domain_PartyCondition{id = ?PARTY_ID_WITH_LIMIT}}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF_WITH_LIMIT}}}, ?ruleset(4) ), ?delegate( <<"Provider cascading with turnover limit">>, - {condition, {party, #domain_PartyCondition{id = ?PARTY_ID_WITH_SEVERAL_LIMITS}}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS}}}, ?ruleset(6) ), ?delegate(<<"Common">>, {constant, true}, ?ruleset(1)) @@ -8593,7 +8737,7 @@ construct_domain_fixture() -> if_ = {condition, {party, #domain_PartyCondition{ - id = ?PARTYID_EXTERNAL + party_ref = ?PARTY_CONFIG_REF_EXTERNAL }}}, then_ = {value, ?eas(2)} }, @@ -9306,7 +9450,7 @@ construct_domain_fixture() -> #domain_TurnoverLimit{ id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY, - domain_revision = hg_domain:head() + domain_revision = BaseLimitsRevision } ]} } @@ -9359,7 +9503,7 @@ construct_domain_fixture() -> #domain_TurnoverLimit{ id = ?LIMIT_ID2, upper_boundary = ?LIMIT_UPPER_BOUNDARY, - domain_revision = hg_domain:head() + domain_revision = BaseLimitsRevision } ]} } @@ -9404,7 +9548,7 @@ construct_domain_fixture() -> #domain_TurnoverLimit{ id = ?LIMIT_ID3, upper_boundary = ?LIMIT_UPPER_BOUNDARY, - domain_revision = hg_domain:head() + domain_revision = BaseLimitsRevision } ]} } diff --git a/apps/hellgate/test/hg_limiter_helper.erl b/apps/hellgate/test/hg_limiter_helper.erl index b0b8b83c..d6953382 100644 --- a/apps/hellgate/test/hg_limiter_helper.erl +++ b/apps/hellgate/test/hg_limiter_helper.erl @@ -48,8 +48,10 @@ get_amount(#limiter_Limit{amount = Amount}) -> -spec assert_payment_limit_amount(_, _, _, _, _) -> _. assert_payment_limit_amount(LimitID, Version, AssertAmount, Payment, Invoice) -> - Limit = maybe_uninitialized_limit(get_payment_limit_amount(LimitID, Version, Payment, Invoice)), - ?assertMatch(#limiter_Limit{amount = AssertAmount}, Limit). + Result = get_payment_limit_amount(LimitID, Version, Payment, Invoice), + Limit = maybe_uninitialized_limit(Result), + #limiter_Limit{amount = CurrentAmount} = Limit, + ?assertEqual(AssertAmount, CurrentAmount, {LimitID, Result}). -spec maybe_uninitialized_limit({ok, _} | {exception, _}) -> _Limit. maybe_uninitialized_limit({ok, Limit}) -> diff --git a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl index 5524a7e1..7ee8eb55 100644 --- a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl +++ b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl @@ -34,8 +34,8 @@ -define(PROVIDER_MIN_ALLOWED, ?cash(1000, <<"RUB">>)). -define(PROVIDER_MIN_ALLOWED_W_EXTRA_CASH(ExtraCash), ?cash(1000 + ExtraCash, <<"RUB">>)). --define(dummy_party_id, <<"dummy_party_id">>). --define(party_id_for_ruleset_w_no_delegates, <<"dummy_party_id_1">>). +-define(dummy_party_config_ref, #domain_PartyConfigRef{id = <<"dummy_party_id">>}). +-define(party_config_ref_for_ruleset_w_no_delegates, #domain_PartyConfigRef{id = <<"dummy_party_id_1">>}). -define(shop_id_for_ruleset_w_priority_distribution_1, <<"dummy_shop_id">>). -define(shop_id_for_ruleset_w_priority_distribution_2, <<"dummy_another_shop_id">>). -define(assert_set_equal(S1, S2), ?assertEqual(lists:sort(S1), lists:sort(S2))). @@ -91,7 +91,7 @@ init_per_suite(C) -> hellgate, {cowboy, CowboySpec} ]), - PartyID = hg_utils:unique_id(), + PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, PartyClient = party_client:create_client(), {ok, SupPid} = hg_mock_helper:start_sup(), FDConfig = genlib_app:env(hellgate, fault_detector), @@ -104,7 +104,7 @@ init_per_suite(C) -> {apps, Apps}, {suite_test_sup, SupPid}, {party_client, PartyClient}, - {party_id, PartyID} + {party_config_ref, PartyConfigRef} | C ]. @@ -224,7 +224,7 @@ mock_party_management(SupPid) -> { ?ruleset(2), ?base_routing_rule_domain_revision, - #payproc_Varset{party_id = ?party_id_for_ruleset_w_no_delegates} + #payproc_Varset{party_ref = ?party_config_ref_for_ruleset_w_no_delegates} } ) -> {ok, #domain_RoutingRuleset{ @@ -457,7 +457,7 @@ no_route_found_for_payment(_C) -> currency => Currency0, cost => ?PROVIDER_MIN_ALLOWED_W_EXTRA_CASH(-1), payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant }, @@ -515,7 +515,7 @@ gather_route_success(_C) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant, risk_score => low }, @@ -556,7 +556,7 @@ rejected_by_table_prohibitions(_C) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant, risk_score => low }, @@ -599,7 +599,7 @@ empty_candidate_ok(_C) -> currency => Currency, cost => ?cash(101010, <<"RUB">>), payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant }, @@ -618,7 +618,7 @@ empty_candidate_ok(_C) -> -spec ruleset_misconfig(config()) -> test_return(). ruleset_misconfig(_C) -> VS = #{ - party_id => ?party_id_for_ruleset_w_no_delegates, + party_config_ref => ?party_config_ref_for_ruleset_w_no_delegates, flow => instant }, @@ -651,7 +651,7 @@ routes_selected_with_risk_score(_C, RiskScore, ProviderRefs) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant, risk_score => RiskScore }, @@ -716,7 +716,7 @@ do_gather_routes(Revision, ExpectedRouteTerminal, ExpectedRejectedRoutes) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant, risk_score => low }, @@ -756,7 +756,7 @@ terminal_priority_for_shop(ShopID, _C) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, shop_id => ShopID, flow => instant }, @@ -781,7 +781,7 @@ gather_pinned_route(_C) -> currency => Currency, cost => ?PROVIDER_MIN_ALLOWED, payment_tool => PaymentTool, - party_id => ?dummy_party_id, + party_config_ref => ?dummy_party_config_ref, flow => instant }, Revision = ?pinned_route_revision, diff --git a/apps/routing/src/hg_route.erl b/apps/routing/src/hg_route.erl index a30a7a69..69fb3d18 100644 --- a/apps/routing/src/hg_route.erl +++ b/apps/routing/src/hg_route.erl @@ -33,7 +33,7 @@ -type t() :: #route{}. -type payment_route() :: dmsl_domain_thrift:'PaymentRoute'(). --type route_rejection_reason() :: {atom(), _DescOrAttrs} | {atom(), _DescOrAttrs1, _DescOrAttrs2}. +-type route_rejection_reason() :: {atom(), term()} | {atom(), term(), term()}. -type rejected_route() :: {provider_ref(), terminal_ref(), route_rejection_reason()}. -type provider_ref() :: dmsl_domain_thrift:'ProviderRef'(). -type terminal_ref() :: dmsl_domain_thrift:'TerminalRef'(). @@ -80,7 +80,7 @@ new(ProviderRef, TerminalRef, undefined, Priority, Pin) -> new(ProviderRef, TerminalRef, Weight, Priority, Pin) -> new(ProviderRef, TerminalRef, Weight, Priority, Pin, #domain_RouteFaultDetectorOverrides{}). --spec new(provider_ref(), terminal_ref(), integer(), integer(), pin(), fd_overrides() | undefined) -> t(). +-spec new(provider_ref(), terminal_ref(), integer(), integer(), pin(), fd_overrides()) -> t(). new(ProviderRef, TerminalRef, Weight, Priority, Pin, FdOverrides) -> #route{ provider_ref = ProviderRef, diff --git a/apps/routing/src/hg_routing_explanation.erl b/apps/routing/src/hg_routing_explanation.erl index 8f6ff7c2..24ee9554 100644 --- a/apps/routing/src/hg_routing_explanation.erl +++ b/apps/routing/src/hg_routing_explanation.erl @@ -278,8 +278,8 @@ gather_varset(Payment, Opts) -> payer = Payer, domain_revision = Revision } = Payment, - PartyID = get_party_id(Opts), - {ShopID, #domain_ShopConfig{ + PartyConfigRef = get_party_config_ref(Opts), + {#domain_ShopConfigRef{id = ShopID}, #domain_ShopConfig{ category = Category }} = get_shop(Opts, Revision), #payproc_Varset{ @@ -288,15 +288,15 @@ gather_varset(Payment, Opts) -> amount = Cost, shop_id = ShopID, payment_tool = hg_invoice_payment:get_payer_payment_tool(Payer), - party_id = PartyID + party_ref = PartyConfigRef }. -get_party_id(#{party_id := PartyID}) -> - PartyID. +get_party_config_ref(#{party_config_ref := PartyConfigRef}) -> + PartyConfigRef. -get_shop(#{party := Party, invoice := Invoice}, Revision) -> - #domain_Invoice{shop_id = ShopID} = Invoice, - hg_party:get_shop(ShopID, Party, Revision). +get_shop(#{invoice := Invoice}, Revision) -> + #domain_Invoice{shop_ref = ShopConfigRef, party_ref = PartyConfigRef} = Invoice, + hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision). format(Format, Data) -> erlang:iolist_to_binary(io_lib:format(Format, Data)). diff --git a/compose.yaml b/compose.yaml index f1eac2c6..e5aff656 100644 --- a/compose.yaml +++ b/compose.yaml @@ -27,7 +27,7 @@ services: command: /sbin/init dmt: - image: ghcr.io/valitydev/dominant-v2:sha-f55c065 + image: ghcr.io/valitydev/dominant-v2:sha-bfed984 command: /opt/dmt/bin/dmt foreground healthcheck: test: "/opt/dmt/bin/dmt ping" @@ -65,7 +65,7 @@ services: retries: 10 limiter: - image: ghcr.io/valitydev/limiter:sha-9eb96a7 + image: ghcr.io/valitydev/limiter:sha-7b27571 command: /opt/limiter/bin/limiter foreground depends_on: machinegun: @@ -100,7 +100,7 @@ services: disable: true liminator: - image: ghcr.io/valitydev/liminator:sha-672e804 + image: ghcr.io/valitydev/liminator:sha-e284ad2 restart: unless-stopped entrypoint: - java @@ -121,7 +121,7 @@ services: retries: 20 party-management: - image: ghcr.io/valitydev/party-management:sha-7649525 + image: ghcr.io/valitydev/party-management:sha-51e92f7 command: /opt/party-management/bin/party-management foreground depends_on: db: diff --git a/erlang_ls.config b/erlang_ls.config new file mode 100644 index 00000000..297076e9 --- /dev/null +++ b/erlang_ls.config @@ -0,0 +1,4 @@ +include_dirs: + - "_build/default/lib" +formatting: + formatter: "erlfmt" diff --git a/rebar.config b/rebar.config index b43d7ab4..07f69d4f 100644 --- a/rebar.config +++ b/rebar.config @@ -31,10 +31,10 @@ {gproc, "0.9.0"}, {genlib, {git, "https://github.com/valitydev/genlib.git", {tag, "v1.1.0"}}}, {woody, {git, "https://github.com/valitydev/woody_erlang.git", {tag, "v1.1.0"}}}, - {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.11"}}}, + {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.12"}}}, {payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}}, {mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}}, - {dmt_client, {git, "https://github.com/valitydev/dmt-client.git", {tag, "v2.0.2"}}}, + {dmt_client, {git, "https://github.com/valitydev/dmt-client.git", {tag, "v2.0.3"}}}, {scoper, {git, "https://github.com/valitydev/scoper.git", {tag, "v1.1.0"}}}, {party_client, {git, "https://github.com/valitydev/party-client-erlang.git", {tag, "v2.0.1"}}}, {bender_client, {git, "https://github.com/valitydev/bender-client-erlang.git", {tag, "v1.1.0"}}}, @@ -42,14 +42,16 @@ {fault_detector_proto, {git, "https://github.com/valitydev/fault-detector-proto.git", {branch, "master"}}}, {limiter_proto, {git, "https://github.com/valitydev/limiter-proto.git", {branch, "master"}}}, {herd, {git, "https://github.com/wgnet/herd.git", {tag, "1.3.4"}}}, - {progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.2"}}}, + {progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.10"}}}, {prometheus, "4.11.0"}, {prometheus_cowboy, "0.1.9"}, %% OpenTelemetry deps {opentelemetry_api, "1.4.0"}, {opentelemetry, "1.5.0"}, - {opentelemetry_exporter, "1.8.0"} + {opentelemetry_exporter, "1.8.0"}, + {eqwalizer_support, + {git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"}, "eqwalizer_support"}} ]}. {xref_checks, [ @@ -108,7 +110,7 @@ {project_plugins, [ {covertool, "2.0.7"}, - {erlfmt, "1.5.0"}, + {erlfmt, "1.6.2"}, {rebar3_lint, "3.2.6"}, {rebar3_lcov, {git, "https://github.com/valitydev/rebar3-lcov.git", {tag, "0.1"}}} ]}. @@ -116,7 +118,9 @@ {erlfmt, [ write, {print_width, 120}, - {files, ["apps/*/{src,include,test}/*.{hrl,erl}", "rebar.config", "elvis.config", "config/sys.config"]} + {files, [ + "apps/*/{src,include,test}/*.{hrl,erl}", "rebar.config", "elvis.config", "config/sys.config" + ]} ]}. {lcov, [ diff --git a/rebar.lock b/rebar.lock index d180dd9e..3ef41c84 100644 --- a/rebar.lock +++ b/rebar.lock @@ -13,7 +13,7 @@ {<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},0}, {<<"canal">>, {git,"https://github.com/valitydev/canal", - {ref,"621d3821cd0a6036fee75d8e3b2d17167f3268e4"}}, + {ref,"89faedce3b054bcca7cc31ca64d2ead8a9402305"}}, 2}, {<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2}, {<<"cg_mon">>, @@ -27,20 +27,25 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"ff9b01f552f922ce4a16710827aa872325dbe5a9"}}, + {ref,"8cab698cd78125ac47489d0ba81169df376757a4"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt-client.git", - {ref,"fff521d3d50b48e3c6b628fe4796b3628aedc6b7"}}, + {ref,"20c18cc9b51d0f273db60c929e8a8a871d6a1866"}}, 0}, {<<"epg_connector">>, {git,"https://github.com/valitydev/epg_connector.git", - {ref,"dd93e27c00d492169e8a7bfc38976b911c6e7d05"}}, + {ref,"2e86da8083908d0d35a4eed3e2168c9ba6a8d04a"}}, 1}, {<<"epgsql">>, {git,"https://github.com/epgsql/epgsql.git", - {ref,"7ba52768cf0ea7d084df24d4275a88eef4db13c2"}}, + {ref,"28e9f84c95065a51e92baeb37d2cf1687fc4b9ce"}}, 2}, + {<<"eqwalizer_support">>, + {git_subdir,"https://github.com/whatsapp/eqwalizer.git", + {ref,"092cf1e1e9854c8d2ef8fa8b9935b1dc45fff070"}, + "eqwalizer_support"}, + 0}, {<<"erl_health">>, {git,"https://github.com/valitydev/erlang-health.git", {ref,"49716470d0e8dab5e37db55d52dea78001735a3d"}},