From ed2b2681281d382a800dde0631dc9e34673c5f63 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Fri, 29 Aug 2025 07:35:24 +0300 Subject: [PATCH 01/10] BG-360: Bump damsel --- apps/hellgate/include/allocation.hrl | 6 +- apps/hellgate/include/hg_invoice.hrl | 2 +- apps/hellgate/src/hg_accounting.erl | 24 +- apps/hellgate/src/hg_allocation.erl | 38 +- apps/hellgate/src/hg_cashflow.erl | 34 +- apps/hellgate/src/hg_cashflow_utils.erl | 44 +- apps/hellgate/src/hg_inspector.erl | 8 +- apps/hellgate/src/hg_invoice.erl | 91 +- apps/hellgate/src/hg_invoice_handler.erl | 71 +- apps/hellgate/src/hg_invoice_mutation.erl | 19 +- apps/hellgate/src/hg_invoice_payment.erl | 458 ++- .../src/hg_invoice_payment_chargeback.erl | 62 +- .../src/hg_invoice_payment_refund.erl | 72 +- .../src/hg_invoice_registered_payment.erl | 59 +- apps/hellgate/src/hg_invoice_template.erl | 55 +- apps/hellgate/src/hg_invoice_utils.erl | 4 +- apps/hellgate/src/hg_limiter.erl | 213 +- apps/hellgate/src/hg_party.erl | 86 +- apps/hellgate/src/hg_varset.erl | 9 +- apps/hellgate/test/hg_allocation_tests.erl | 312 +- apps/hellgate/test/hg_ct_domain.hrl | 32 +- apps/hellgate/test/hg_ct_helper.erl | 248 +- .../test/hg_direct_recurrent_tests_SUITE.erl | 76 +- apps/hellgate/test/hg_invoice_helper.erl | 49 +- .../test/hg_invoice_lite_tests_SUITE.erl | 97 +- .../test/hg_invoice_template_tests_SUITE.erl | 187 +- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 2802 ++++++++++++----- .../test/hg_route_rules_tests_SUITE.erl | 152 +- apps/routing/src/hg_routing_explanation.erl | 31 +- compose.yaml | 8 +- rebar.config | 8 +- rebar.lock | 4 +- 32 files changed, 3678 insertions(+), 1683 deletions(-) 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..7012d5c5 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,17 @@ 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 }. @@ -134,7 +136,9 @@ collect_provider_account_map(Payment, #domain_Provider{accounts = ProviderAccoun -spec collect_system_account_map(payment(), payment_institution(), revision(), map()) -> map(). collect_system_account_map(Payment, PaymentInstitution, Revision, Acc) -> Currency = get_currency(get_payment_cost(Payment)), - SystemAccount = hg_payment_institution:get_system_account(Currency, Revision, PaymentInstitution), + SystemAccount = hg_payment_institution:get_system_account( + Currency, Revision, PaymentInstitution + ), Acc#{ {system, settlement} => SystemAccount#domain_SystemAccount.settlement, {system, subagent} => SystemAccount#domain_SystemAccount.subagent diff --git a/apps/hellgate/src/hg_allocation.erl b/apps/hellgate/src/hg_allocation.erl index da9932b3..a4b55f92 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,18 @@ 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). - --spec calculate(allocation_prototype(), party_id(), shop_id(), cash()) -> allocation(). -calculate(AllocationPrototype, PartyID, ShopID, Cost) -> +construct_target(#{ + party_config_ref := PartyConfigRef, + shop_config_ref := ShopConfigRef +}) -> + ?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef). + +-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). @@ -177,7 +181,9 @@ calculate_trxs([Head | Transactions], FeeTarget, CostLeft, FeeAcc, ID0, Acc0) -> construct_positive_trx(ID, Target, Amount, Details, Body) -> case construct_trx(ID, Target, Amount, Details, Body) of undefined -> - throw({invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount}); + throw( + {invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount} + ); Trx -> Trx end. @@ -215,7 +221,9 @@ add_fee(undefined, FeeAmount) -> add_fee(FeeCost, FeeAmount) -> hg_cash:add(FeeCost, FeeAmount). -calculate_trxs_body(?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP) -> +calculate_trxs_body( + ?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP +) -> {undefined, Amount, ?cash(0, SymCode)}; calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget, TP) -> CalculatedFee = calculate_trxs_fee(Fee, Total), @@ -229,7 +237,9 @@ calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget, calculate_trxs_fee(?allocation_trx_prototype_fee_fixed(Amount), _Total) -> Amount; -calculate_trxs_fee(?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode)) -> +calculate_trxs_fee( + ?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode) +) -> RoundingMethod1 = genlib:define(RoundingMethod0, round_half_away_from_zero), R = genlib_rational:new(P * Total, Q), Amount = ?cash(genlib_rational:round(R, RoundingMethod1), SymCode), diff --git a/apps/hellgate/src/hg_cashflow.erl b/apps/hellgate/src/hg_cashflow.erl index 57cfed83..37ee9e39 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,12 @@ 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, @@ -117,7 +119,9 @@ resolve_account(AccountType, AccountMap) -> #{AccountType := V} -> V; #{} -> - error({misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}}) + error( + {misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}} + ) end. %% @@ -142,7 +146,9 @@ revert_details(Details) -> ). -define(share(P, Q, Of, RoundingMethod), - {share, #domain_CashVolumeShare{'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod}} + {share, #domain_CashVolumeShare{ + 'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod + }} ). -define(product(Fun, CVs), @@ -182,12 +188,16 @@ compute_product(Fun, [CV | CVRest], CV0, Context) -> CVRest ). -compute_product(Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context) -> +compute_product( + Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context +) -> case compute_volume(CV, Context) of #domain_Cash{amount = Amount, currency = Currency} -> CVMin#domain_Cash{amount = compute_product_fun(Fun, AmountMin, Amount)}; _ -> - error({misconfiguration, {'Cash volume product over volumes of different currencies', CV0}}) + error( + {misconfiguration, {'Cash volume product over volumes of different currencies', CV0}} + ) end. compute_product_fun(min_of, V1, V2) -> @@ -232,7 +242,9 @@ increment_remainder(AccountType, Cash, Acc) -> decrement_remainder(AccountType, ?cash(Amount, Currency), Acc) -> modify_remainder(AccountType, ?cash(-Amount, Currency), Acc). -modify_remainder(#domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc) -> +modify_remainder( + #domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc +) -> maps:update_with( AccountType, fun(?cash(A, C)) when C == Currency -> diff --git a/apps/hellgate/src/hg_cashflow_utils.erl b/apps/hellgate/src/hg_cashflow_utils.erl index 119b02c2..272c66b0 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,14 @@ 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 +85,9 @@ 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, [], @@ -110,14 +114,20 @@ construct_transaction_cashflow( end, MerchantCashflowSelector = get_terms_cashflow(OpType, MerchantPaymentsTerms1), MerchantCashflow = get_selector_value(merchant_payment_fees, MerchantCashflowSelector), - AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)), + AccountMap = hg_accounting:collect_account_map( + make_collect_account_context(PaymentInstitution, Context) + ), construct_final_cashflow(MerchantCashflow, #{operation_amount => Amount}, AccountMap). construct_provider_cashflow(PaymentInstitution, Context = #{provision_terms := ProvisionTerms}) -> ProviderCashflowSelector = get_provider_cashflow_selector(ProvisionTerms), ProviderCashflow = get_selector_value(provider_payment_cash_flow, ProviderCashflowSelector), - AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)), - construct_final_cashflow(ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap). + AccountMap = hg_accounting:collect_account_map( + make_collect_account_context(PaymentInstitution, Context) + ), + construct_final_cashflow( + ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap + ). construct_final_cashflow(Cashflow, Context, AccountMap) -> hg_cashflow:finalize(Cashflow, Context, AccountMap). @@ -140,7 +150,9 @@ get_amount(#{payment := #domain_InvoicePayment{cost = Cost}}) -> get_provider_cashflow_selector(#domain_PaymentsProvisionTerms{cash_flow = ProviderCashflowSelector}) -> ProviderCashflowSelector; -get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{cash_flow = ProviderCashflowSelector}) -> +get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{ + cash_flow = ProviderCashflowSelector +}) -> ProviderCashflowSelector. get_terms_cashflow(payment, MerchantPaymentsTerms) -> @@ -161,7 +173,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 +182,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..328a1f5c 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,17 @@ 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; @@ -313,7 +317,9 @@ handle_repair({changes, Changes, RepairAction, Params}, St) -> % Validating that these changes are at least applicable validate => should_validate_transitions(Params) }; -handle_repair({scenario, _}, #st{activity = Activity}) when Activity =:= invoice orelse Activity =:= undefined -> +handle_repair({scenario, _}, #st{activity = Activity}) when + Activity =:= invoice orelse Activity =:= undefined +-> throw({exception, invoice_has_no_active_payment}); handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) -> PaymentSession = get_payment_session(PaymentID, St), @@ -355,7 +361,9 @@ merge_repair_action({remove, #repair_RemoveAction{}}, Action) -> merge_repair_action({_, undefined}, Action) -> Action. -should_validate_transitions(#payproc_InvoiceRepairParams{validate_transitions = V}) when is_boolean(V) -> +should_validate_transitions(#payproc_InvoiceRepairParams{validate_transitions = V}) when + is_boolean(V) +-> V; should_validate_transitions(undefined) -> true. @@ -491,12 +499,18 @@ handle_call({callback, _Tag, _Callback} = Call, St) -> handle_call({session_change, _Tag, _SessionChange} = Call, St) -> dispatch_to_session(Call, St). --spec dispatch_to_session({callback, tag(), callback()} | {session_change, tag(), session_change()}, st()) -> +-spec dispatch_to_session( + {callback, tag(), callback()} | {session_change, tag(), session_change()}, st() +) -> call_result(). -dispatch_to_session({callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}}) -> +dispatch_to_session( + {callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}} +) -> PaymentSession = get_payment_session(PaymentID, St), process_payment_call({callback, Tag, Payload}, PaymentID, PaymentSession, St); -dispatch_to_session({session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}}) -> +dispatch_to_session( + {session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}} +) -> PaymentSession = get_payment_session(PaymentID, St), process_payment_call(Call, PaymentID, PaymentSession, St); dispatch_to_session(_Call, _St) -> @@ -556,7 +570,9 @@ do_register_payment(PaymentID, PaymentParams, St) -> _ = assert_no_pending_payment(St), Opts = #{timestamp := OccurredAt} = get_payment_opts(St), % TODO make timer reset explicit here - {PaymentSession, {Changes, Action}} = hg_invoice_registered_payment:init(PaymentID, PaymentParams, Opts), + {PaymentSession, {Changes, Action}} = hg_invoice_registered_payment:init( + PaymentID, PaymentParams, Opts + ), #{ response => get_payment_state(PaymentSession), changes => wrap_payment_changes(PaymentID, Changes, OccurredAt), @@ -658,7 +674,9 @@ handle_payment_result({done, {Changes, Action}}, PaymentID, PaymentSession, St, end. collapse_payment_changes(Changes, PaymentSession, ChangeOpts) -> - lists:foldl(fun(C, St1) -> merge_payment_change(C, St1, ChangeOpts) end, PaymentSession, Changes). + lists:foldl( + fun(C, St1) -> merge_payment_change(C, St1, ChangeOpts) end, PaymentSession, Changes + ). wrap_payment_changes(PaymentID, Changes, OccurredAt) -> [?payment_ev(PaymentID, C, OccurredAt) || C <- Changes]. @@ -786,7 +804,9 @@ start_chargeback(Params, PaymentID, PaymentSession, PaymentOpts, St) -> case get_chargeback_state(ID, PaymentSession) of undefined -> #payproc_InvoicePaymentChargebackParams{occurred_at = OccurredAt} = Params, - CreateResult = hg_invoice_payment:create_chargeback(PaymentSession, PaymentOpts, Params), + CreateResult = hg_invoice_payment:create_chargeback( + PaymentSession, PaymentOpts, Params + ), wrap_payment_impact(PaymentID, CreateResult, St, OccurredAt); ChargebackState -> #{ @@ -861,7 +881,9 @@ merge_change(?invoice_created(Invoice), St, _Opts) -> St#st{activity = invoice, invoice = Invoice}; merge_change(?invoice_status_changed(Status), St = #st{invoice = I}, _Opts) -> St#st{invoice = I#domain_Invoice{status = Status}}; -merge_change(?payment_ev(PaymentID, Change), St = #st{invoice = #domain_Invoice{id = InvoiceID}}, Opts) -> +merge_change( + ?payment_ev(PaymentID, Change), St = #st{invoice = #domain_Invoice{id = InvoiceID}}, Opts +) -> PaymentSession = try_get_payment_session(PaymentID, St), PaymentSession1 = merge_payment_change(Change, PaymentSession, Opts#{invoice_id => InvoiceID}), St1 = set_payment_session(PaymentID, PaymentSession1, St), @@ -898,14 +920,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 +992,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..fc113840 100644 --- a/apps/hellgate/src/hg_invoice_handler.erl +++ b/apps/hellgate/src/hg_invoice_handler.erl @@ -21,7 +21,8 @@ %% API --spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). +-spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> + term() | no_return(). handle_function(Func, Args, Opts) -> scoper:scope( invoicing, @@ -30,21 +31,25 @@ handle_function(Func, Args, Opts) -> end ). --spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). +-spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> + term() | no_return(). 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 +60,14 @@ 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 +107,15 @@ 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) }, @@ -139,11 +148,15 @@ handle_function_('RepairWithScenario', {InvoiceID, Scenario}, _Opts) -> handle_function_('GetPaymentRoutesLimitValues', {InvoiceID, PaymentID}, _Opts) -> _ = set_invoicing_meta(InvoiceID, PaymentID), St = get_state(InvoiceID), - hg_invoice_payment:get_limit_values(get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St)); + hg_invoice_payment:get_limit_values( + get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St) + ); handle_function_('ExplainRoute', {InvoiceID, PaymentID}, _Opts) -> _ = set_invoicing_meta(InvoiceID, PaymentID), St = get_state(InvoiceID), - hg_routing_explanation:get_explanation(get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St)). + hg_routing_explanation:get_explanation( + get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St) + ). ensure_started(ID, TemplateID, Params, Allocation, Mutations, DomainRevision) -> Invoice = hg_invoice:create(ID, TemplateID, Params, Allocation, Mutations, DomainRevision), @@ -248,11 +261,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 +297,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 +307,10 @@ 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 +323,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 +332,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), @@ -333,7 +348,9 @@ validate_invoice_cost(Cost, Shop, #domain_TermSet{payments = PaymentTerms}) -> maybe_make_mutations(InvoiceParams) -> Cost = InvoiceParams#payproc_InvoiceParams.cost, - Mutations = hg_invoice_mutation:make_mutations(InvoiceParams#payproc_InvoiceParams.mutations, #{cost => Cost}), + Mutations = hg_invoice_mutation:make_mutations( + InvoiceParams#payproc_InvoiceParams.mutations, #{cost => Cost} + ), NewCost = hg_invoice_mutation:get_mutated_cost(Mutations, Cost), {NewCost, Mutations}. diff --git a/apps/hellgate/src/hg_invoice_mutation.erl b/apps/hellgate/src/hg_invoice_mutation.erl index 7c66d49d..3d1c3181 100644 --- a/apps/hellgate/src/hg_invoice_mutation.erl +++ b/apps/hellgate/src/hg_invoice_mutation.erl @@ -47,7 +47,9 @@ validate_mutations_w_cart(Mutations, #domain_InvoiceCart{lines = Lines}) -> Mutations1 = genlib:define(Mutations, []), amount_mutation_is_present(Mutations1) andalso cart_is_not_valid_for_mutation(Lines) andalso throw(#base_InvalidRequest{ - errors = [<<"Amount mutation with multiline cart or multiple items in a line is not allowed">>] + errors = [ + <<"Amount mutation with multiline cart or multiple items in a line is not allowed">> + ] }), ok. @@ -63,7 +65,8 @@ amount_mutation_is_present(Mutations) -> cart_is_not_valid_for_mutation(Lines) -> length(Lines) > 1 orelse (hd(Lines))#domain_InvoiceLine.quantity =/= 1. --spec apply_mutations([mutation()] | undefined, Invoice) -> Invoice when Invoice :: hg_invoice:invoice(). +-spec apply_mutations([mutation()] | undefined, Invoice) -> Invoice when + Invoice :: hg_invoice:invoice(). apply_mutations(Mutations, Invoice) -> lists:foldl(fun apply_mutation/2, Invoice, genlib:define(Mutations, [])). @@ -94,7 +97,9 @@ update_invoice_line_price(NewAmount, Line = #domain_InvoiceLine{price = Price}) -spec make_mutations([mutation_params()], mutation_context()) -> [mutation()]. make_mutations(MutationsParams, Context) -> - {Mutations, _} = lists:foldl(fun make_mutation/2, {[], Context}, genlib:define(MutationsParams, [])), + {Mutations, _} = lists:foldl( + fun make_mutation/2, {[], Context}, genlib:define(MutationsParams, []) + ), lists:reverse(Mutations). -define(SATISFY_RANDOMIZATION_CONDITION(P, Amount), @@ -114,7 +119,9 @@ make_mutation( {Mutations, Context = #{cost := #domain_Cash{amount = Amount}}} ) when ?SATISFY_RANDOMIZATION_CONDITION(Params, Amount) -> NewMutation = - {amount, #domain_InvoiceAmountMutation{original = Amount, mutated = calc_new_amount(Amount, Params)}}, + {amount, #domain_InvoiceAmountMutation{ + original = Amount, mutated = calc_new_amount(Amount, Params) + }}, {[NewMutation | Mutations], Context}; make_mutation(_, {Mutations, Context}) -> {Mutations, Context}. @@ -164,8 +171,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..9633390b 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'(). @@ -180,7 +180,8 @@ -type payment() :: dmsl_domain_thrift:'InvoicePayment'(). -type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'(). -type payment_status() :: dmsl_domain_thrift:'InvoicePaymentStatus'(). --type payment_status_type() :: pending | processed | captured | cancelled | refunded | failed | charged_back. +-type payment_status_type() :: + pending | processed | captured | cancelled | refunded | failed | charged_back. -type domain_refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'(). -type payment_refund() :: dmsl_payproc_thrift:'InvoicePaymentRefund'(). -type refund_id() :: dmsl_domain_thrift:'InvoicePaymentRefundID'(). @@ -209,7 +210,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 +219,7 @@ -type opts() :: #{ party => party(), - party_id => party_id(), + party_config_ref => party_config_ref(), invoice => invoice(), timestamp => hg_datetime:timestamp() }. @@ -244,7 +245,9 @@ %% --define(LOG_MD(Level, Format, Args), logger:log(Level, Format, Args, logger:get_process_metadata())). +-define(LOG_MD(Level, Format, Args), + logger:log(Level, Format, Args, logger:get_process_metadata()) +). -spec get_payment(st()) -> payment(). get_payment(#st{payment = Payment}) -> @@ -416,19 +419,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, @@ -489,7 +492,9 @@ construct_payer( end, #domain_InvoicePayment{payer = ParentPayer} = get_payment(ParentPayment), ParentPaymentTool = get_payer_payment_tool(ParentPayer), - {ok, ?recurrent_payer(ParentPaymentTool, Parent, ContactInfo), #{parent_payment => ParentPayment}}. + {ok, ?recurrent_payer(ParentPaymentTool, Parent, ContactInfo), #{ + parent_payment => ParentPayment + }}. construct_payment( PaymentID, @@ -497,8 +502,8 @@ construct_payment( Cost, Payer, FlowParams, - PartyID, - {ShopID, Shop} = ShopObj, + PartyConfigRef, + {ShopConfigRef, Shop} = ShopObj, VS0, Revision, MakeRecurrent @@ -525,12 +530,14 @@ construct_payment( PaymentTool ), ParentPayment = maps:get(parent_payment, VS1, undefined), - ok = validate_recurrent_intention(Payer, RecurrentTerms, PaymentTool, ShopObj, ParentPayment, MakeRecurrent), + ok = validate_recurrent_intention( + Payer, RecurrentTerms, PaymentTool, ShopObj, ParentPayment, MakeRecurrent + ), #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 +595,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(). @@ -603,13 +610,18 @@ validate_recurrent_intention( ok = validate_recurrent_terms(RecurrentTerms, PaymentTool), ok = validate_recurrent_payer(Payer, MakeRecurrent), ok = validate_recurrent_parent(ShopObj, ParentPayment); -validate_recurrent_intention(Payer, RecurrentTerms, PaymentTool, _Shop, _ParentPayment, true = MakeRecurrent) -> +validate_recurrent_intention( + Payer, RecurrentTerms, PaymentTool, _Shop, _ParentPayment, true = MakeRecurrent +) -> ok = validate_recurrent_terms(RecurrentTerms, PaymentTool), ok = validate_recurrent_payer(Payer, MakeRecurrent); -validate_recurrent_intention(_Payer, _RecurrentTerms, _PaymentTool, _Shop, _ParentPayment, false = _MakeRecurrent) -> +validate_recurrent_intention( + _Payer, _RecurrentTerms, _PaymentTool, _Shop, _ParentPayment, false = _MakeRecurrent +) -> ok. --spec validate_recurrent_terms(recurrent_paytool_service_terms(), payment_tool()) -> ok | no_return(). +-spec validate_recurrent_terms(recurrent_paytool_service_terms(), payment_tool()) -> + ok | no_return(). validate_recurrent_terms(undefined, _PaymentTool) -> throw(#payproc_OperationNotPermitted{}); validate_recurrent_terms(RecurrentTerms, PaymentTool) -> @@ -631,7 +643,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 +658,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 -> @@ -755,7 +767,9 @@ log_rejected_routes(in_blacklist, Routes, _VS) -> log_rejected_routes(adapter_unavailable, Routes, _VS) -> ?LOG_MD(notice, "Adapter unavailability caused route candidates to be rejected: ~p", [Routes]); log_rejected_routes(provider_conversion_is_too_low, Routes, _VS) -> - ?LOG_MD(notice, "Lacking conversion of provider caused route candidates to be rejected: ~p", [Routes]); + ?LOG_MD(notice, "Lacking conversion of provider caused route candidates to be rejected: ~p", [ + Routes + ]); log_rejected_routes(forbidden, Routes, VS) -> ?LOG_MD(notice, "Rejected routes found for varset: ~p", [VS]), ?LOG_MD(notice, "Rejected routes found, rejected routes: ~p", [Routes]); @@ -815,23 +829,27 @@ 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 }. @@ -966,13 +984,17 @@ assert_capture_cost_currency(undefined, _) -> ok; assert_capture_cost_currency(?cash(_, SymCode), #domain_InvoicePayment{cost = ?cash(_, SymCode)}) -> ok; -assert_capture_cost_currency(?cash(_, PassedSymCode), #domain_InvoicePayment{cost = ?cash(_, SymCode)}) -> +assert_capture_cost_currency(?cash(_, PassedSymCode), #domain_InvoicePayment{ + cost = ?cash(_, SymCode) +}) -> throw(#payproc_InconsistentCaptureCurrency{ payment_currency = SymCode, passed_currency = PassedSymCode }). -validate_processing_deadline(#domain_InvoicePayment{processing_deadline = Deadline}, _TargetType = processed) -> +validate_processing_deadline( + #domain_InvoicePayment{processing_deadline = Deadline}, _TargetType = processed +) -> case hg_invoice_utils:check_deadline(Deadline) of ok -> ok; @@ -998,15 +1020,21 @@ assert_capture_cart(Cost, Cart) -> check_equal_capture_cost_amount(undefined, _) -> true; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) when +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ + cost = ?cash(Amount, _) +}) when PassedAmount =:= Amount -> true; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) when +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ + cost = ?cash(Amount, _) +}) when PassedAmount < Amount -> false; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) -> +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ + cost = ?cash(Amount, _) +}) -> throw(#payproc_AmountExceededCaptureBalance{ payment_amount = Amount, passed_amount = PassedAmount @@ -1024,7 +1052,9 @@ validate_merchant_hold_terms(#domain_PaymentsServiceTerms{holds = Terms}) when T validate_merchant_hold_terms(#domain_PaymentsServiceTerms{holds = undefined}) -> ok. -validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) when Terms /= undefined -> +validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) when + Terms /= undefined +-> case Terms of %% Чтобы упростить интеграцию, по умолчанию разрешили частичные подтверждения #domain_PaymentHoldsProvisionTerms{partial_captures = undefined} -> @@ -1036,7 +1066,8 @@ validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) whe validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = undefined}) -> ok. --spec create_chargeback(st(), opts(), hg_invoice_payment_chargeback:create_params()) -> {chargeback(), result()}. +-spec create_chargeback(st(), opts(), hg_invoice_payment_chargeback:create_params()) -> + {chargeback(), result()}. create_chargeback(St, Opts, Params) -> _ = assert_no_pending_chargebacks(St), _ = validate_payment_status(captured, get_payment(St)), @@ -1045,25 +1076,29 @@ create_chargeback(St, Opts, Params) -> {Chargeback, {Changes, Action}} = hg_invoice_payment_chargeback:create(CBOpts, Params), {Chargeback, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec cancel_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:cancel_params()) -> {ok, result()}. +-spec cancel_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:cancel_params()) -> + {ok, result()}. cancel_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:cancel(ChargebackState, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec reject_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reject_params()) -> {ok, result()}. +-spec reject_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reject_params()) -> + {ok, result()}. reject_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:reject(ChargebackState, St, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec accept_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:accept_params()) -> {ok, result()}. +-spec accept_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:accept_params()) -> + {ok, result()}. accept_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:accept(ChargebackState, St, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec reopen_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reopen_params()) -> {ok, result()}. +-spec reopen_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reopen_params()) -> + {ok, result()}. reopen_chargeback(ChargebackID, St, Params) -> _ = assert_no_pending_chargebacks(St), ChargebackState = get_chargeback_state(ChargebackID, St), @@ -1086,7 +1121,9 @@ refund(Params, St0, Opts = #{timestamp := CreatedAt}) -> VS = collect_validation_varset(St, Opts), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS), Refund = make_refund(Params, Payment, Revision, CreatedAt, St, Opts), - FinalCashflow = make_refund_cashflow(Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt), + FinalCashflow = make_refund_cashflow( + Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt + ), Changes = hg_invoice_payment_refund:create(#{ refund => Refund, cash_flow => FinalCashflow @@ -1101,7 +1138,9 @@ manual_refund(Params, St0, Opts = #{timestamp := CreatedAt}) -> VS = collect_validation_varset(St, Opts), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS), Refund = make_refund(Params, Payment, Revision, CreatedAt, St, Opts), - FinalCashflow = make_refund_cashflow(Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt), + FinalCashflow = make_refund_cashflow( + Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt + ), TransactionInfo = Params#payproc_InvoicePaymentRefundParams.transaction_info, Changes = hg_invoice_payment_refund:create(#{ refund => Refund, @@ -1321,7 +1360,8 @@ validate_common_refund_terms(Terms, Refund, Payment) -> %% --spec create_adjustment(hg_datetime:timestamp(), adjustment_params(), st(), opts()) -> {adjustment(), result()}. +-spec create_adjustment(hg_datetime:timestamp(), adjustment_params(), st(), opts()) -> + {adjustment(), result()}. create_adjustment(Timestamp, Params, St, Opts) -> _ = assert_no_adjustment_pending(St), case Params#payproc_InvoicePaymentAdjustmentParams.scenario of @@ -1449,7 +1489,9 @@ assert_no_refunds(St) -> throw_invalid_request(<<"Cannot change status of payment with refunds.">>) end. --spec assert_adjustment_payment_statuses(TargetStatus :: payment_status(), Status :: payment_status()) -> +-spec assert_adjustment_payment_statuses( + TargetStatus :: payment_status(), Status :: payment_status() +) -> ok | no_return(). assert_adjustment_payment_statuses(Status, Status) -> erlang:throw(#payproc_InvoicePaymentAlreadyHasStatus{status = Status}); @@ -1526,7 +1568,8 @@ calculate_cashflow(Context = #{route := Route, revision := Revision}, Opts) -> }), hg_cashflow_utils:collect_cashflow(CollectCashflowContext). --spec calculate_cashflow(hg_payment_institution:t(), cashflow_context(), opts()) -> final_cash_flow(). +-spec calculate_cashflow(hg_payment_institution:t(), cashflow_context(), opts()) -> + final_cash_flow(). calculate_cashflow(PaymentInstitution, Context = #{route := Route, revision := Revision}, Opts) -> CollectCashflowContext = genlib_map:compact(Context#{ operation => payment, @@ -1591,7 +1634,10 @@ assert_payment_status(_, #domain_InvoicePayment{status = Status}) -> throw(#payproc_InvalidPaymentStatus{status = Status}). assert_no_pending_chargebacks(PaymentState) -> - Chargebacks = [CB#payproc_InvoicePaymentChargeback.chargeback || CB <- get_chargebacks(PaymentState)], + Chargebacks = [ + CB#payproc_InvoicePaymentChargeback.chargeback + || CB <- get_chargebacks(PaymentState) + ], case lists:any(fun hg_invoice_payment_chargeback:is_pending/1, Chargebacks) of true -> throw(#payproc_InvoicePaymentChargebackPending{}); @@ -1885,7 +1931,9 @@ process_risk_score(Action, St) -> Payment = get_payment(St), VS1 = get_varset(St, #{}), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), - PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), + PaymentInstitution = hg_payment_institution:compute_payment_institution( + PaymentInstitutionRef, VS1, Revision + ), RiskScore = repair_inspect(Payment, PaymentInstitution, Opts, St), Events = [?risk_score_changed(RiskScore)], case check_risk_score(RiskScore) of @@ -1951,12 +1999,18 @@ produce_routing_events(Ctx = #{error := Error}, _Revision, St) when Error =/= un %% skipped. And all limit's 'hold' operations will be rolled back. %% For same purpose in cascade routing we use route from unfiltered list of %% originally resolved candidates. - [?route_changed(Route, Candidates, RouteScores, RouteLimits), ?payment_rollback_started(Failure)]; + [ + ?route_changed(Route, Candidates, RouteScores, RouteLimits), + ?payment_rollback_started(Failure) + ]; produce_routing_events(Ctx, Revision, _St) -> ok = log_route_choice_meta(Ctx, Revision), Route = hg_route:to_payment_route(hg_routing_ctx:choosen_route(Ctx)), Candidates = - ordsets:from_list([hg_route:to_payment_route(R) || R <- hg_routing_ctx:considered_candidates(Ctx)]), + ordsets:from_list([ + hg_route:to_payment_route(R) + || R <- hg_routing_ctx:considered_candidates(Ctx) + ]), RouteScores = hg_routing_ctx:route_scores(Ctx), RouteLimits = hg_routing_ctx:route_limits(Ctx), [?route_changed(Route, Candidates, RouteScores, RouteLimits)]. @@ -1969,9 +2023,13 @@ route_args(St) -> CreatedAt = get_payment_created_at(Payment), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS1), - VS2 = collect_refund_varset(MerchantTerms#domain_PaymentsServiceTerms.refunds, PaymentTool, VS1), + VS2 = collect_refund_varset( + MerchantTerms#domain_PaymentsServiceTerms.refunds, PaymentTool, VS1 + ), VS3 = collect_chargeback_varset(MerchantTerms#domain_PaymentsServiceTerms.chargebacks, VS2), - PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), + PaymentInstitution = hg_payment_institution:compute_payment_institution( + PaymentInstitutionRef, VS1, Revision + ), {PaymentInstitution, VS3, Revision}. build_routing_context(PaymentInstitution, VS, Revision, St) -> @@ -1996,8 +2054,12 @@ build_blacklist_context(St) -> Opts = get_opts(St), VS1 = get_varset(St, #{}), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), - PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), - InspectorRef = get_selector_value(inspector, PaymentInstitution#domain_PaymentInstitution.inspector), + PaymentInstitution = hg_payment_institution:compute_payment_institution( + PaymentInstitutionRef, VS1, Revision + ), + InspectorRef = get_selector_value( + inspector, PaymentInstitution#domain_PaymentInstitution.inspector + ), Inspector = hg_domain:get(Revision, {inspector, InspectorRef}), #{ revision => Revision, @@ -2032,16 +2094,22 @@ construct_routing_failure({rejected_routes, {SubCode, RejectedRoutes}}) when construct_routing_failure({rejected_routes, {_SubCode, RejectedRoutes}}) -> construct_routing_failure([forbidden], genlib:format(RejectedRoutes)); construct_routing_failure({misconfiguration = Code, Details}) -> - construct_routing_failure([unknown, {unknown_error, atom_to_binary(Code)}], genlib:format(Details)); + construct_routing_failure( + [unknown, {unknown_error, atom_to_binary(Code)}], genlib:format(Details) + ); construct_routing_failure(Code = risk_score_is_too_high) -> construct_routing_failure([Code], undefined); construct_routing_failure(Error) when is_atom(Error) -> construct_routing_failure([{unknown_error, Error}], undefined). construct_routing_failure(Codes, Reason) -> - {failure, payproc_errors:construct('PaymentFailure', mk_static_error([no_route_found | Codes]), Reason)}. + {failure, + payproc_errors:construct( + 'PaymentFailure', mk_static_error([no_route_found | Codes]), Reason + )}. -mk_static_error([_ | _] = Codes) -> mk_static_error_(#payproc_error_GeneralFailure{}, lists:reverse(Codes)). +mk_static_error([_ | _] = Codes) -> + mk_static_error_(#payproc_error_GeneralFailure{}, lists:reverse(Codes)). mk_static_error_(T, []) -> T; mk_static_error_(Sub, [Code | Codes]) -> mk_static_error_({Code, Sub}, Codes). @@ -2053,7 +2121,9 @@ 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 = #{ @@ -2076,19 +2146,24 @@ process_cash_flow_building(Action, St) -> %% --spec process_chargeback(chargeback_activity_type(), chargeback_id(), action(), st()) -> machine_result(). +-spec process_chargeback(chargeback_activity_type(), chargeback_id(), action(), st()) -> + machine_result(). process_chargeback(Type = finalising_accounter, ID, Action0, St) -> ChargebackState = get_chargeback_state(ID, St), ChargebackOpts = get_chargeback_opts(St), ChargebackBody = hg_invoice_payment_chargeback:get_body(ChargebackState), ChargebackTarget = hg_invoice_payment_chargeback:get_target_status(ChargebackState), MaybeChargedback = maybe_set_charged_back_status(ChargebackTarget, ChargebackBody, St), - {Changes, Action1} = hg_invoice_payment_chargeback:process_timeout(Type, ChargebackState, Action0, ChargebackOpts), + {Changes, Action1} = hg_invoice_payment_chargeback:process_timeout( + Type, ChargebackState, Action0, ChargebackOpts + ), {done, {[?chargeback_ev(ID, C) || C <- Changes] ++ MaybeChargedback, Action1}}; process_chargeback(Type, ID, Action0, St) -> ChargebackState = get_chargeback_state(ID, St), ChargebackOpts = get_chargeback_opts(St), - {Changes0, Action1} = hg_invoice_payment_chargeback:process_timeout(Type, ChargebackState, Action0, ChargebackOpts), + {Changes0, Action1} = hg_invoice_payment_chargeback:process_timeout( + Type, ChargebackState, Action0, ChargebackOpts + ), Changes1 = [?chargeback_ev(ID, C) || C <- Changes0], case Type of %% NOTE In case if payment is already charged back and we want @@ -2131,7 +2206,9 @@ process_adjustment_cashflow(ID, _Action, St) -> Events = [?adjustment_ev(ID, ?adjustment_status_changed(?adjustment_processed()))], {next, {Events, hg_machine_action:instant()}}. -process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, capture_data = CaptureData}) -> +process_accounter_update( + Action, St = #st{partial_cash_flow = FinalCashflow, capture_data = CaptureData} +) -> #payproc_InvoicePaymentCaptureData{ reason = Reason, cash = Cost, @@ -2150,11 +2227,14 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap %% --spec handle_callback(activity(), callback(), hg_session:t(), st()) -> {callback_response(), machine_result()}. +-spec handle_callback(activity(), callback(), hg_session:t(), st()) -> + {callback_response(), machine_result()}. handle_callback({refund, ID}, Payload, _Session0, St) -> PaymentInfo = construct_payment_info(St, get_opts(St)), Refund = try_get_refund_state(ID, St), - {Resp, {Step, {Events0, Action}}} = hg_invoice_payment_refund:process_callback(Payload, PaymentInfo, Refund), + {Resp, {Step, {Events0, Action}}} = hg_invoice_payment_refund:process_callback( + Payload, PaymentInfo, Refund + ), Events1 = hg_invoice_payment_refund:wrap_events(Events0, Refund), {Resp, {Step, {Events1, Action}}}; handle_callback(Activity, Payload, Session0, St) -> @@ -2330,7 +2410,9 @@ process_result({payment, finalizing_accounter}, Action, St) -> process_failure(Activity, Events, Action, Failure, St) -> process_failure(Activity, Events, Action, Failure, St, undefined). -process_failure({payment, processing_failure}, Events, Action, _Failure, #st{failure = Failure}, _RefundSt) when +process_failure( + {payment, processing_failure}, Events, Action, _Failure, #st{failure = Failure}, _RefundSt +) when Failure =/= undefined -> %% In case of cascade attempt we may catch and handle routing failure during 'processing_failure' activity @@ -2374,7 +2456,9 @@ check_recurrent_token(_) -> ok. choose_fd_operation_status_for_failure({failure, Failure}) -> - payproc_errors:match('PaymentFailure', Failure, fun do_choose_fd_operation_status_for_failure/1); + payproc_errors:match( + 'PaymentFailure', Failure, fun do_choose_fd_operation_status_for_failure/1 + ); choose_fd_operation_status_for_failure(_Failure) -> finish. @@ -2483,7 +2567,9 @@ 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) -> @@ -2492,7 +2578,9 @@ filter_routes_with_limit_hold(Ctx0, VS, Iter, St) -> hg_routing_ctx:stash_current_candidates(Ctx1). filter_routes_by_limit_overflow(Ctx0, VS, Iter, St) -> - {_Routes, RejectedRoutes, Limits} = get_limit_overflow_routes(hg_routing_ctx:candidates(Ctx0), VS, Iter, St), + {_Routes, RejectedRoutes, Limits} = get_limit_overflow_routes( + hg_routing_ctx:candidates(Ctx0), VS, Iter, St + ), Ctx1 = hg_routing_ctx:stash_route_limits(Limits, Ctx0), reject_routes(limit_overflow, RejectedRoutes, Ctx1). @@ -2518,7 +2606,9 @@ get_limit_overflow_routes(Routes, VS, Iter, St) -> {[Route | RoutesNoOverflowIn], RejectedIn, LimitsIn#{PaymentRoute => Limits}}; {error, {limit_overflow, IDs, Limits}} -> RejectedRoute = hg_route:to_rejected_route(Route, {'LimitOverflow', IDs}), - {RoutesNoOverflowIn, [RejectedRoute | RejectedIn], LimitsIn#{PaymentRoute => Limits}} + {RoutesNoOverflowIn, [RejectedRoute | RejectedIn], LimitsIn#{ + PaymentRoute => Limits + }} end end, {[], [], #{}}, @@ -2531,40 +2621,44 @@ 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 @@ -2590,7 +2684,9 @@ hold_limit_routes(Routes0, VS, Iter, St) -> ProviderTerms = hg_routing:get_payment_terms(PaymentRoute, VS, Revision), TurnoverLimits = get_turnover_limits(ProviderTerms), try - ok = hg_limiter:hold_payment_limits(TurnoverLimits, Invoice, Payment, PaymentRoute, Iter), + ok = hg_limiter:hold_payment_limits( + TurnoverLimits, Invoice, Payment, PaymentRoute, Iter + ), {[Route | LimitHeldRoutes], RejectedRoutes} catch error:(#limiter_LimitNotFound{} = LimiterError) -> @@ -2623,7 +2719,9 @@ rollback_payment_limits(Routes, Iter, St, Flags) -> fun(Route) -> ProviderTerms = hg_routing:get_payment_terms(Route, VS, Revision), TurnoverLimits = get_turnover_limits(ProviderTerms), - ok = hg_limiter:rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, Flags) + ok = hg_limiter:rollback_payment_limits( + TurnoverLimits, Invoice, Payment, Route, Iter, Flags + ) end, Routes ). @@ -2647,9 +2745,11 @@ rollback_broken_payment_limits(St) -> [], Values ), - ok = hg_limiter:rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, [ - ignore_business_error - ]) + ok = hg_limiter:rollback_payment_limits( + TurnoverLimits, Invoice, Payment, Route, Iter, [ + ignore_business_error + ] + ) end, ok, LimitValues @@ -2659,7 +2759,9 @@ rollback_unused_payment_limits(St) -> Route = get_route(St), Routes = get_candidate_routes(St), UnUsedRoutes = Routes -- [Route], - rollback_payment_limits(UnUsedRoutes, get_iter(St), St, [ignore_business_error, ignore_not_found]). + rollback_payment_limits(UnUsedRoutes, get_iter(St), St, [ + ignore_business_error, ignore_not_found + ]). get_turnover_limits(ProviderTerms) -> TurnoverLimitSelector = ProviderTerms#domain_PaymentsProvisionTerms.turnover_limits, @@ -2709,7 +2811,9 @@ do_try_with_ids([ID | OtherIDs], Func) when is_function(Func, 1) -> Func(ID) catch %% Very specific error to crutch around - error:{accounting, #base_InvalidRequest{errors = [<<"Posting plan not found: ", ID/binary>>]}} -> + error:{accounting, #base_InvalidRequest{ + errors = [<<"Posting plan not found: ", ID/binary>>] + }} -> do_try_with_ids(OtherIDs, Func) end. @@ -2733,7 +2837,9 @@ get_cashflow_plan(St = #st{new_cash_provided = true, new_cash_flow = NewCashFlow {2, hg_cashflow:revert(get_cashflow(St))}, {3, NewCashFlow} ]; -get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when PartialCashFlow =/= undefined -> +get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when + PartialCashFlow =/= undefined +-> [ {1, get_cashflow(St)}, {2, hg_cashflow:revert(get_cashflow(St))}, @@ -2811,7 +2917,9 @@ construct_proxy_payment( construct_payment_resource(?payment_resource_payer(Resource, _)) -> {disposable_payment_resource, Resource}; -construct_payment_resource(?recurrent_payer(PaymentTool, ?recurrent_parent(InvoiceID, PaymentID), _)) -> +construct_payment_resource( + ?recurrent_payer(PaymentTool, ?recurrent_parent(InvoiceID, PaymentID), _) +) -> PreviousPayment = get_payment_state(InvoiceID, PaymentID), RecToken = get_recurrent_token(PreviousPayment), {recurrent_payment_resource, #proxy_provider_RecurrentPaymentResource{ @@ -2842,15 +2950,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 +2983,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 +3013,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 +3027,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 +3074,9 @@ 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. %% @@ -3041,7 +3153,9 @@ merge_change( routes = [Route | Routes], candidate_routes = ordsets:to_list(Candidates), activity = {payment, cash_flow_building}, - route_scores = hg_maybe:apply(fun(S) -> maps:merge(RouteScores, S) end, Scores, RouteScores), + route_scores = hg_maybe:apply( + fun(S) -> maps:merge(RouteScores, S) end, Scores, RouteScores + ), route_limits = hg_maybe:apply(fun(L) -> maps:merge(RouteLimits, L) end, Limits, RouteLimits) }; merge_change(Change = ?payment_capture_started(Data), #st{} = St, Opts) -> @@ -3085,7 +3199,9 @@ merge_change(Change = ?cash_flow_changed(CashFlow), #st{activity = Activity} = S St end; merge_change(Change = ?rec_token_acquired(Token), #st{} = St, Opts) -> - _ = validate_transition([{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts), + _ = validate_transition( + [{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts + ), St#st{recurrent_token = Token}; merge_change(Change = ?cash_changed(_OldCash, NewCash), #st{} = St, Opts) -> _ = validate_transition( @@ -3122,7 +3238,9 @@ merge_change(Change = ?payment_rollback_started(Failure), St, Opts) -> activity = Activity, timings = accrue_status_timing(failed, Opts, St) }; -merge_change(Change = ?payment_status_changed({failed, _} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({failed, _} = Status), #st{payment = Payment} = St, Opts +) -> _ = validate_transition( [ {payment, S} @@ -3145,14 +3263,20 @@ merge_change(Change = ?payment_status_changed({failed, _} = Status), #st{payment failure = undefined, timings = accrue_status_timing(failed, Opts, St) }; -merge_change(Change = ?payment_status_changed({cancelled, _} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({cancelled, _} = Status), #st{payment = Payment} = St, Opts +) -> _ = validate_transition({payment, finalizing_accounter}, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status}, activity = idle, timings = accrue_status_timing(cancelled, Opts, St) }; -merge_change(Change = ?payment_status_changed({captured, Captured} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({captured, Captured} = Status), + #st{payment = Payment} = St, + Opts +) -> _ = validate_transition([idle, {payment, finalizing_accounter}], Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{ @@ -3163,19 +3287,25 @@ merge_change(Change = ?payment_status_changed({captured, Captured} = Status), #s timings = accrue_status_timing(captured, Opts, St), allocation = get_captured_allocation(Captured) }; -merge_change(Change = ?payment_status_changed({processed, _} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({processed, _} = Status), #st{payment = Payment} = St, Opts +) -> _ = validate_transition({payment, processing_accounter}, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status}, activity = {payment, flow_waiting}, timings = accrue_status_timing(processed, Opts, St) }; -merge_change(Change = ?payment_status_changed({refunded, _} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({refunded, _} = Status), #st{payment = Payment} = St, Opts +) -> _ = validate_transition(idle, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status} }; -merge_change(Change = ?payment_status_changed({charged_back, _} = Status), #st{payment = Payment} = St, Opts) -> +merge_change( + Change = ?payment_status_changed({charged_back, _} = Status), #st{payment = Payment} = St, Opts +) -> _ = validate_transition(idle, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status} @@ -3190,13 +3320,20 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> _ = validate_transition(idle, Change, St, Opts), St; ?chargeback_levy_changed(_) -> - _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), + _ = validate_transition( + [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts + ), St#st{activity = {chargeback, ID, updating_chargeback}}; ?chargeback_body_changed(_) -> - _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), + _ = validate_transition( + [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts + ), St#st{activity = {chargeback, ID, updating_chargeback}}; ?chargeback_cash_flow_changed(_) -> - Valid = [{chargeback, ID, Activity} || Activity <- [preparing_initial_cash_flow, updating_cash_flow]], + Valid = [ + {chargeback, ID, Activity} + || Activity <- [preparing_initial_cash_flow, updating_cash_flow] + ], _ = validate_transition(Valid, Change, St, Opts), case St of #st{activity = {chargeback, ID, preparing_initial_cash_flow}} -> @@ -3205,7 +3342,9 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> St#st{activity = {chargeback, ID, finalising_accounter}} end; ?chargeback_target_status_changed(?chargeback_status_accepted()) -> - _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), + _ = validate_transition( + [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts + ), case St of #st{activity = idle} -> St#st{activity = {chargeback, ID, finalising_accounter}}; @@ -3213,10 +3352,14 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> St#st{activity = {chargeback, ID, updating_cash_flow}} end; ?chargeback_target_status_changed(_) -> - _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), + _ = validate_transition( + [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts + ), St#st{activity = {chargeback, ID, updating_cash_flow}}; ?chargeback_status_changed(_) -> - _ = validate_transition([idle, {chargeback, ID, finalising_accounter}], Change, St, Opts), + _ = validate_transition( + [idle, {chargeback, ID, finalising_accounter}], Change, St, Opts + ), St#st{activity = idle} end, ChargebackSt = merge_chargeback_change(Event, try_get_chargeback_state(ID, St1)), @@ -3243,7 +3386,9 @@ merge_change(?refund_ev(ID, Event), St, Opts) -> _ -> St end, - RefundSt1 = hg_invoice_payment_refund:apply_event(Event, try_get_refund_state(ID, St1), EventContext), + RefundSt1 = hg_invoice_payment_refund:apply_event( + Event, try_get_refund_state(ID, St1), EventContext + ), St2 = set_refund_state(ID, RefundSt1, St1), case hg_invoice_payment_refund:status(RefundSt1) of S when S == succeeded; S == failed -> @@ -3294,7 +3439,9 @@ merge_change( Opts ), % FIXME why the hell dedicated handling - Session0 = hg_session:apply_event(Event, undefined, create_session_event_context(Target, St, Opts)), + Session0 = hg_session:apply_event( + Event, undefined, create_session_event_context(Target, St, Opts) + ), %% We need to pass processed trx_info to captured/cancelled session due to provider requirements Session1 = hg_session:set_trx_info(get_trx(St), Session0), St1 = add_session(Target, Session1, St#st{target = Target}), @@ -3303,7 +3450,9 @@ merge_change( {payment, processing_session} -> %% session retrying St2#st{activity = {payment, processing_session}}; - {payment, PaymentActivity} when PaymentActivity == flow_waiting; PaymentActivity == processing_capture -> + {payment, PaymentActivity} when + PaymentActivity == flow_waiting; PaymentActivity == processing_capture + -> %% session flow St2#st{ activity = {payment, finalizing_session}, @@ -3319,7 +3468,9 @@ merge_change( St2 end; merge_change(Change = ?session_ev(Target, Event), St = #st{activity = Activity}, Opts) -> - _ = validate_transition([{payment, S} || S <- [processing_session, finalizing_session]], Change, St, Opts), + _ = validate_transition( + [{payment, S} || S <- [processing_session, finalizing_session]], Change, St, Opts + ), Session = hg_session:apply_event( Event, get_session(Target, St), @@ -3356,15 +3507,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), @@ -3374,19 +3525,27 @@ log_cascade_attempt_context( #domain_PaymentsServiceTerms{attempt_limit = AttemptLimit}, #st{routes = AttemptedRoutes} ) -> - ?LOG_MD(notice, "Cascade context: merchant payment terms' attempt limit '~p', attempted routes: ~p", [ - AttemptLimit, AttemptedRoutes - ]). + ?LOG_MD( + notice, + "Cascade context: merchant payment terms' attempt limit '~p', attempted routes: ~p", + [ + AttemptLimit, AttemptedRoutes + ] + ). get_routing_attempt_limit_value(undefined) -> 1; get_routing_attempt_limit_value({decisions, _}) -> get_routing_attempt_limit_value(undefined); -get_routing_attempt_limit_value({value, #domain_AttemptLimit{attempts = Value}}) when is_integer(Value) -> +get_routing_attempt_limit_value({value, #domain_AttemptLimit{attempts = Value}}) when + is_integer(Value) +-> Value. save_retry_attempt(Target, #st{retry_attempts = Attempts} = St) -> - St#st{retry_attempts = maps:update_with(get_target_type(Target), fun(N) -> N + 1 end, 0, Attempts)}. + St#st{ + retry_attempts = maps:update_with(get_target_type(Target), fun(N) -> N + 1 end, 0, Attempts) + }. merge_chargeback_change(Change, ChargebackState) -> hg_invoice_payment_chargeback:merge_change(Change, ChargebackState). @@ -3424,7 +3583,8 @@ apply_adjustment_effect(status, #domain_InvoicePaymentAdjustment{}, St) -> apply_adjustment_effect(cashflow, Adjustment, St) -> set_cashflow(get_adjustment_cashflow(Adjustment), St). --spec validate_transition(activity() | [activity()], change(), st(), change_opts()) -> ok | no_return(). +-spec validate_transition(activity() | [activity()], change(), st(), change_opts()) -> + ok | no_return(). validate_transition(Allowed, Change, St, Opts) -> case {Opts, is_transition_valid(Allowed, St)} of {#{}, true} -> @@ -3533,7 +3693,8 @@ try_get_chargeback_state(ID, #st{chargebacks = CBs}) -> set_refund_state(ID, RefundSt, St = #st{refunds = Rs}) -> St#st{refunds = Rs#{ID => RefundSt}}. --spec get_origin(st() | undefined) -> dmsl_domain_thrift:'InvoicePaymentRegistrationOrigin'() | undefined. +-spec get_origin(st() | undefined) -> + dmsl_domain_thrift:'InvoicePaymentRegistrationOrigin'() | undefined. get_origin(#st{payment = #domain_InvoicePayment{registration_origin = Origin}}) -> Origin. @@ -3568,7 +3729,9 @@ get_refund_status(#domain_InvoicePaymentRefund{status = Status}) -> define_refund_cash(undefined, St) -> get_remaining_payment_balance(St); -define_refund_cash(?cash(_, SymCode) = Cash, #st{payment = #domain_InvoicePayment{cost = ?cash(_, SymCode)}}) -> +define_refund_cash(?cash(_, SymCode) = Cash, #st{ + payment = #domain_InvoicePayment{cost = ?cash(_, SymCode)} +}) -> Cash; define_refund_cash(?cash(_, SymCode), _St) -> throw(#payproc_InconsistentRefundCurrency{currency = SymCode}). @@ -3631,7 +3794,9 @@ update_session(Target, Session, St = #st{sessions = Sessions}) -> get_target(#st{target = Target}) -> Target. -get_target_type({Type, _}) when Type == 'processed'; Type == 'captured'; Type == 'cancelled'; Type == 'refunded' -> +get_target_type({Type, _}) when + Type == 'processed'; Type == 'captured'; Type == 'cancelled'; Type == 'refunded' +-> Type. get_recurrent_token(#st{recurrent_token = Token}) -> @@ -3674,7 +3839,9 @@ get_route_provider(Route, Revision) -> hg_domain:get(Revision, {provider, get_route_provider_ref(Route)}). inspect(Payment = #domain_InvoicePayment{domain_revision = Revision}, PaymentInstitution, Opts) -> - InspectorRef = get_selector_value(inspector, PaymentInstitution#domain_PaymentInstitution.inspector), + InspectorRef = get_selector_value( + inspector, PaymentInstitution#domain_PaymentInstitution.inspector + ), Inspector = hg_domain:get(Revision, {inspector, InspectorRef}), hg_inspector:inspect(get_shop(Opts, Revision), get_invoice(Opts), Payment, Inspector). @@ -3870,7 +4037,9 @@ is_route_cascade_available( get_route_cascade_behaviour(Route, Revision) -> ProviderRef = get_route_provider(Route), - #domain_Provider{cascade_behaviour = Behaviour} = hg_domain:get(Revision, {provider, ProviderRef}), + #domain_Provider{cascade_behaviour = Behaviour} = hg_domain:get( + Revision, {provider, ProviderRef} + ), Behaviour. -ifdef(TEST). @@ -3921,11 +4090,14 @@ filter_attempted_routes_test_() -> ) ), ?_assertMatch( - #{candidates := []}, filter_attempted_routes(hg_routing_ctx:new([]), #st{activity = idle, routes = []}) + #{candidates := []}, + filter_attempted_routes(hg_routing_ctx:new([]), #st{activity = idle, routes = []}) ), ?_assertMatch( #{candidates := [R1, R2, R3]}, - filter_attempted_routes(hg_routing_ctx:new([R1, R2, R3]), #st{activity = idle, routes = []}) + filter_attempted_routes(hg_routing_ctx:new([R1, R2, R3]), #st{ + activity = idle, routes = [] + }) ), ?_assertMatch( #{candidates := [R1, R2]}, diff --git a/apps/hellgate/src/hg_invoice_payment_chargeback.erl b/apps/hellgate/src/hg_invoice_payment_chargeback.erl index 203bca34..4195579e 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), @@ -361,7 +361,8 @@ finalise(State = #chargeback_st{target_status = Status}, Action, Opts) when _ = commit_cash_flow(State, Opts), {[?chargeback_status_changed(Status)], Action}. --spec build_chargeback(opts(), create_params(), revision(), timestamp()) -> chargeback() | no_return(). +-spec build_chargeback(opts(), create_params(), revision(), timestamp()) -> + chargeback() | no_return(). build_chargeback(Opts, Params = ?chargeback_params(Levy, Body, Reason), Revision, CreatedAt) -> Revision = hg_domain:head(), #domain_InvoicePaymentChargeback{ @@ -412,7 +413,9 @@ build_reopen_result(State, ?reopen_params(ParamsLevy, ParamsBody) = Params) -> {Changes, Action}. -spec build_chargeback_final_cash_flow(state(), opts()) -> final_cash_flow() | no_return(). -build_chargeback_final_cash_flow(#chargeback_st{target_status = ?chargeback_status_cancelled()}, _Opts) -> +build_chargeback_final_cash_flow( + #chargeback_st{target_status = ?chargeback_status_cancelled()}, _Opts +) -> []; build_chargeback_final_cash_flow(State, Opts) -> CreatedAt = get_created_at(State), @@ -422,10 +425,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), @@ -433,11 +436,13 @@ build_chargeback_final_cash_flow(State, Opts) -> ProviderCashFlow = get_chargeback_provider_cash_flow(ProviderTerms), ProviderFees = collect_chargeback_provider_fees(ProviderTerms), PaymentInstitutionRef = Shop#domain_ShopConfig.payment_institution, - PaymentInst = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS, Revision), + PaymentInst = hg_payment_institution:compute_payment_institution( + PaymentInstitutionRef, VS, Revision + ), 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 +524,16 @@ 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, @@ -537,7 +544,9 @@ collect_validation_varset(PartyID, {ShopID, Shop}, Payment, Body) -> validate_eligibility_time(#domain_PaymentChargebackServiceTerms{eligibility_time = undefined}) -> ok; -validate_eligibility_time(#domain_PaymentChargebackServiceTerms{eligibility_time = {value, EligibilityTime}}) -> +validate_eligibility_time(#domain_PaymentChargebackServiceTerms{ + eligibility_time = {value, EligibilityTime} +}) -> Now = hg_datetime:format_now(), EligibleUntil = hg_datetime:add_time_span(EligibilityTime, Now), case hg_datetime:compare(Now, EligibleUntil) of @@ -582,7 +591,9 @@ validate_not_arbitration(#domain_InvoicePaymentChargeback{}) -> validate_chargeback_is_pending(#chargeback_st{chargeback = Chargeback}) -> validate_chargeback_is_pending(Chargeback); -validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{status = ?chargeback_status_pending()}) -> +validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{ + status = ?chargeback_status_pending() +}) -> ok; validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{status = Status}) -> throw(#payproc_InvoicePaymentChargebackInvalidStatus{status = Status}). @@ -649,7 +660,8 @@ get_reopen_stage(#domain_InvoicePaymentChargeback{stage = CurrentStage} = Charge throw(#payproc_InvoicePaymentChargebackInvalidStage{stage = CurrentStage}) end. --spec get_next_stage(chargeback()) -> ?chargeback_stage_pre_arbitration() | ?chargeback_stage_arbitration(). +-spec get_next_stage(chargeback()) -> + ?chargeback_stage_pre_arbitration() | ?chargeback_stage_arbitration(). get_next_stage(#domain_InvoicePaymentChargeback{stage = ?chargeback_stage_chargeback()}) -> ?chargeback_stage_pre_arbitration(); get_next_stage(#domain_InvoicePaymentChargeback{stage = ?chargeback_stage_pre_arbitration()}) -> @@ -721,8 +733,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 +771,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..3258f4e5 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(), @@ -251,7 +251,9 @@ do_deduce_activity(#{status := pending, failure := _Failure}) -> failure; do_deduce_activity(#{status := pending, sessions := []}) -> new; -do_deduce_activity(#{status := pending, session_status := finished, session_result := {succeeded, _}}) -> +do_deduce_activity(#{ + status := pending, session_status := finished, session_result := {succeeded, _} +}) -> accounter; do_deduce_activity(#{status := pending, session_status := finished, session_result := {failed, _}}) -> failure; @@ -275,13 +277,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 +373,19 @@ 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 +401,9 @@ 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 +412,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 +500,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,16 +519,17 @@ 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). -get_injected_payment_info(#{injected_context := Context}) -> maps:get(payment_info, Context, undefined). +get_injected_repair_scenario(#{injected_context := Context}) -> + maps:get(repair_scenario, Context, undefined). +get_injected_payment_info(#{injected_context := Context}) -> + maps:get(payment_info, Context, undefined). %% Event utils @@ -555,10 +563,14 @@ apply_event(?refund_created(Refund, Cashflow, TransactionInfo), undefined, Conte }); apply_event(?refund_status_changed(Status = {StatusTag, _}), Refund, _Context) -> DomainRefund = refund(Refund), - Refund#{status := StatusTag, refund := DomainRefund#domain_InvoicePaymentRefund{status = Status}}; + Refund#{ + status := StatusTag, refund := DomainRefund#domain_InvoicePaymentRefund{status = Status} + }; apply_event(?refund_rollback_started(Failure), Refund, _Context) -> Refund#{failure => Failure}; -apply_event(?session_ev(?refunded(), Event = ?session_started()), Refund = #{session_context := Context}, _) -> +apply_event( + ?session_ev(?refunded(), Event = ?session_started()), Refund = #{session_context := Context}, _ +) -> Session = hg_session:apply_event(Event, undefined, Context), add_refund_session(Session, Refund); apply_event(?session_ev(?refunded(), Event), Refund = #{session_context := Context}, _) -> diff --git a/apps/hellgate/src/hg_invoice_registered_payment.erl b/apps/hellgate/src/hg_invoice_registered_payment.erl index 98f42377..321a3c80 100644 --- a/apps/hellgate/src/hg_invoice_registered_payment.erl +++ b/apps/hellgate/src/hg_invoice_registered_payment.erl @@ -45,24 +45,26 @@ 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), + PaymentInstitution = hg_payment_institution:compute_payment_institution( + PaymentInstitutionRef, VS, Revision + ), Payment = construct_payment( PaymentID, CreatedAt1, Cost1, Payer, - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, PayerSessionInfo, Context, ExternalID, @@ -81,7 +83,9 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt0}) -> varset => VS, revision => Revision }, - FinalCashflow = hg_invoice_payment:calculate_cashflow(PaymentInstitution, CashflowContext, Opts), + FinalCashflow = hg_invoice_payment:calculate_cashflow( + PaymentInstitution, CashflowContext, Opts + ), Events = [ @@ -166,7 +170,9 @@ process_processing_capture(Action, St) -> ok = hold_payment_cashflow(St), Events = [ hg_session:wrap_event(?captured(?CAPTURE_REASON, Cost), hg_session:create()), - hg_session:wrap_event(?captured(?CAPTURE_REASON, Cost), ?session_finished(?session_succeeded())) + hg_session:wrap_event( + ?captured(?CAPTURE_REASON, Cost), ?session_finished(?session_succeeded()) + ) ], {next, {Events, hg_machine_action:set_timeout(0, Action)}}. @@ -195,7 +201,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 +210,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 +220,8 @@ construct_payment( CreatedAt, Cost, Payer, - PartyID, - ShopID, + PartyConfigRef, + ShopConfigRef, PayerSessionInfo, Context, ExternalID, @@ -224,8 +230,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 +244,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 +267,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 +283,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..7d28f9b1 100644 --- a/apps/hellgate/src/hg_invoice_template.erl +++ b/apps/hellgate/src/hg_invoice_template.erl @@ -47,7 +47,8 @@ get_invoice_template(ID) -> %% Woody handler --spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). +-spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> + term() | no_return(). handle_function(Func, Args, Opts) -> scoper:scope( invoice_templating, @@ -56,12 +57,16 @@ handle_function(Func, Args, Opts) -> end ). --spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). +-spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> + term() | no_return(). 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 +76,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 +97,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 +122,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. @@ -128,12 +137,16 @@ get_shop(ShopID, Party) -> set_meta(ID) -> scoper:add_meta(#{invoice_template_id => ID}). -validate_create_params(#payproc_InvoiceTemplateCreateParams{details = Details, mutations = Mutations}, Shop) -> +validate_create_params( + #payproc_InvoiceTemplateCreateParams{details = Details, mutations = Mutations}, Shop +) -> ok = validate_details(Details, Mutations, Shop). validate_update_params(#payproc_InvoiceTemplateUpdateParams{details = undefined}, _) -> ok; -validate_update_params(#payproc_InvoiceTemplateUpdateParams{details = Details, mutations = Mutations}, Shop) -> +validate_update_params( + #payproc_InvoiceTemplateUpdateParams{details = Details, mutations = Mutations}, Shop +) -> ok = validate_details(Details, Mutations, Shop). validate_details({cart, #domain_InvoiceCart{}} = Details, Mutations, _) -> @@ -227,8 +240,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..04e0eeb7 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()]. @@ -50,10 +50,13 @@ get_turnover_limits({value, Limits}) -> get_turnover_limits(Ambiguous) -> error({misconfiguration, {'Could not reduce selector to a value', Ambiguous}}). --spec get_limit_values([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> [turnover_limit_value()]. +-spec get_limit_values([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> + [turnover_limit_value()]. get_limit_values(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - get_limit_values(Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)). + get_limit_values( + Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) + ). make_route_operation_segments(Invoice, Payment, ?route(ProviderRef, TerminalRef), Iter) -> [ @@ -65,7 +68,9 @@ make_route_operation_segments(Invoice, Payment, ?route(ProviderRef, TerminalRef) ]. get_limit_values(Context, TurnoverLimits, OperationIdSegments) -> - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), get_legacy_limit_values(Context, LegacyTurnoverLimits) ++ get_batch_limit_values(Context, BatchTurnoverLimits, OperationIdSegments). @@ -98,7 +103,9 @@ get_batch_limit_values(Context, TurnoverLimits, OperationIdSegments) -> | {error, {limit_overflow, [binary()], [turnover_limit_value()]}}. check_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - Limits = get_limit_values(Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)), + Limits = get_limit_values( + Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) + ), try ok = check_limits_(Limits, Context), {ok, Limits} @@ -108,12 +115,18 @@ 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 +135,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) ]. @@ -155,9 +168,13 @@ check_limits_([TurnoverLimitValue | TLVs], Context) -> -spec hold_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> ok. hold_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), ok = legacy_hold_payment_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter), - ok = batch_hold_limits(Context, BatchTurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)). + ok = batch_hold_limits( + Context, BatchTurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) + ). legacy_hold_payment_limits(Context, TurnoverLimits, Invoice, Payment, Route, Iter) -> ChangeIDs = [construct_payment_change_id(Route, Iter, Invoice, Payment)], @@ -171,26 +188,38 @@ 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), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), + 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). -spec hold_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. hold_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), ok = legacy_hold_refund_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Refund), - ok = batch_hold_limits(Context, BatchTurnoverLimits, make_refund_operation_segments(Invoice, Payment, Refund)). + ok = batch_hold_limits( + Context, BatchTurnoverLimits, make_refund_operation_segments(Invoice, Payment, Refund) + ). make_refund_operation_segments(Invoice, Payment, Refund) -> [ @@ -204,12 +233,18 @@ legacy_hold_refund_limits(Context, TurnoverLimits, Invoice, Payment, Refund) -> LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), hold(LimitChanges, get_latest_clock(), Context). --spec commit_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), cash() | undefined) -> ok. +-spec commit_payment_limits( + [turnover_limit()], invoice(), payment(), route(), pos_integer(), cash() | undefined +) -> ok. commit_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, CapturedCash) -> Context = gen_limit_context(Invoice, Payment, Route, CapturedCash), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), Clock = get_latest_clock(), - ok = legacy_commit_payment_limits(Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter), + ok = legacy_commit_payment_limits( + Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter + ), OperationIdSegments = make_route_operation_segments(Invoice, Payment, Route, Iter), ok = batch_commit_limits(Context, BatchTurnoverLimits, OperationIdSegments), ok = log_limit_changes(TurnoverLimits, Clock, Context). @@ -228,27 +263,41 @@ 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), + {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). -spec commit_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. commit_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), Clock = get_latest_clock(), - ok = legacy_commit_refund_limits(Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Refund), + ok = legacy_commit_refund_limits( + Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Refund + ), OperationIdSegments = make_refund_operation_segments(Invoice, Payment, Refund), ok = batch_commit_limits(Context, BatchTurnoverLimits, OperationIdSegments), ok = log_limit_changes(TurnoverLimits, Clock, Context). @@ -266,12 +315,18 @@ legacy_commit_refund_limits(Clock, Context, TurnoverLimits, Invoice, Payment, Re %% %% - `ignore_not_found` -- does not raise error if limiter won't be able to %% find according posting plan in accountant service --spec rollback_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), [handling_flag()]) -> +-spec rollback_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), [ + handling_flag() +]) -> ok. rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, Flags) -> Context = gen_limit_context(Invoice, Payment, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), - ok = legacy_rollback_payment_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter, Flags), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), + ok = legacy_rollback_payment_limits( + Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter, Flags + ), OperationIdSegments = make_route_operation_segments(Invoice, Payment, Route, Iter), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). @@ -289,24 +344,38 @@ 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()]) -> +-spec rollback_shop_limits( + [turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment(), [ + handling_flag() + ] +) -> ok. -rollback_shop_limits(TurnoverLimits, PartyID, ShopID, Invoice, Payment, Flags) -> +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), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), + 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). -spec rollback_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. rollback_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( + TurnoverLimits + ), ok = legacy_rollback_refund_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Refund), OperationIdSegments = make_refund_operation_segments(Invoice, Payment, Refund), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). @@ -324,7 +393,9 @@ hold(LimitChanges, Clock, Context) -> commit(LimitChanges, Clock, Context) -> process_changes(LimitChanges, fun hg_limiter_client:commit/3, Clock, Context, []). --spec rollback([change_queue()], hg_limiter_client:clock(), hg_limiter_client:context(), [handling_flag()]) -> ok. +-spec rollback([change_queue()], hg_limiter_client:clock(), hg_limiter_client:context(), [ + handling_flag() +]) -> ok. rollback(LimitChanges, Clock, Context, Flags) -> process_changes(LimitChanges, fun hg_limiter_client:rollback/3, Clock, Context, Flags). @@ -337,7 +408,9 @@ process_changes(LimitChangesQueues, WithFun, Clock, Context, Flags) -> ). %% Very specific error to crutch around --define(POSTING_PLAN_NOT_FOUND(ID), #base_InvalidRequest{errors = [<<"Posting plan not found: ", ID/binary>>]}). +-define(POSTING_PLAN_NOT_FOUND(ID), #base_InvalidRequest{ + errors = [<<"Posting plan not found: ", ID/binary>>] +}). process_changes_try_wrap([LimitChange], WithFun, Clock, Context, Flags) -> IgnoreNotFound = lists:member(ignore_not_found, Flags), @@ -361,11 +434,16 @@ process_changes_try_wrap([LimitChange | OtherLimitChanges], WithFun, Clock, Cont handle_caught_exception(Class, Reason, Stacktrace, IgnoreBusinessError) end. -handle_caught_exception(error, #limiter_LimitNotFound{}, _Stacktrace, true) -> ok; -handle_caught_exception(error, #limiter_InvalidOperationCurrency{}, _Stacktrace, true) -> ok; -handle_caught_exception(error, #limiter_OperationContextNotSupported{}, _Stacktrace, true) -> ok; -handle_caught_exception(error, #limiter_PaymentToolNotSupported{}, _Stacktrace, true) -> ok; -handle_caught_exception(Class, Reason, Stacktrace, _IgnoreBusinessError) -> erlang:raise(Class, Reason, Stacktrace). +handle_caught_exception(error, #limiter_LimitNotFound{}, _Stacktrace, true) -> + ok; +handle_caught_exception(error, #limiter_InvalidOperationCurrency{}, _Stacktrace, true) -> + ok; +handle_caught_exception(error, #limiter_OperationContextNotSupported{}, _Stacktrace, true) -> + ok; +handle_caught_exception(error, #limiter_PaymentToolNotSupported{}, _Stacktrace, true) -> + ok; +handle_caught_exception(Class, Reason, Stacktrace, _IgnoreBusinessError) -> + erlang:raise(Class, Reason, Stacktrace). gen_limit_context(Invoice, Payment, Route) -> gen_limit_context(Invoice, Payment, Route, undefined). @@ -452,10 +530,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) ]). @@ -494,8 +572,14 @@ convert_to_limit_route(#domain_PaymentRoute{provider = Provider, terminal = Term log_limit_changes(TurnoverLimits, Clock, Context) -> Attrs = mk_limit_log_attributes(Context), lists:foreach( - fun(#domain_TurnoverLimit{id = ID, upper_boundary = UpperBoundary, domain_revision = DomainRevision}) -> - #limiter_Limit{amount = LimitAmount} = hg_limiter_client:get(ID, DomainRevision, Clock, Context), + fun( + #domain_TurnoverLimit{ + id = ID, upper_boundary = UpperBoundary, domain_revision = DomainRevision + } + ) -> + #limiter_Limit{amount = LimitAmount} = hg_limiter_client:get( + ID, DomainRevision, Clock, Context + ), ok = logger:log(notice, "Limit change commited", [], #{ limit => Attrs#{config_id => ID, boundary => UpperBoundary, amount => LimitAmount} }) @@ -507,7 +591,10 @@ 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 +615,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 @@ -545,7 +632,9 @@ maybe_route_context(#base_Route{provider = Provider, terminal = Terminal}) -> }. split_turnover_limits_by_available_limiter_api(TurnoverLimits) -> - lists:partition(fun(#domain_TurnoverLimit{domain_revision = V}) -> V =:= undefined end, TurnoverLimits). + lists:partition( + fun(#domain_TurnoverLimit{domain_revision = V}) -> V =:= undefined end, TurnoverLimits + ). prepare_limit_request(TurnoverLimits, IdSegments) -> {TurnoverLimitsIdList, LimitChanges} = lists:unzip( 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..a7976d48 100644 --- a/apps/hellgate/test/hg_allocation_tests.erl +++ b/apps/hellgate/test/hg_allocation_tests.erl @@ -8,16 +8,23 @@ -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 +32,9 @@ 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 +49,46 @@ 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 +96,9 @@ 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 +110,56 @@ 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 +172,9 @@ 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 +182,9 @@ 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 +192,9 @@ 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 +204,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 +217,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 +231,22 @@ 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 +254,30 @@ 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 +285,9 @@ 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 +300,9 @@ 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 +310,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 +327,23 @@ 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 +351,9 @@ 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 +366,9 @@ 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 +376,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 +393,32 @@ 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 +434,16 @@ 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 +451,9 @@ 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 +463,25 @@ 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 +489,38 @@ 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 +528,9 @@ 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 +546,16 @@ 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 +563,9 @@ 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 +575,36 @@ 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 +613,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 +622,30 @@ 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 +653,9 @@ 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..6e8911c2 100644 --- a/apps/hellgate/test/hg_ct_domain.hrl +++ b/apps/hellgate/test/hg_ct_domain.hrl @@ -34,7 +34,9 @@ -define(crypta(ID), #domain_CryptoCurrencyRef{id = ID}). -define(token_srv(ID), #domain_BankCardTokenServiceRef{id = ID}). -define(bank_card(ID), #domain_BankCardPaymentMethod{payment_system = ?pmt_sys(ID)}). --define(bank_card_no_cvv(ID), #domain_BankCardPaymentMethod{payment_system = ?pmt_sys(ID), is_cvv_empty = true}). +-define(bank_card_no_cvv(ID), #domain_BankCardPaymentMethod{ + payment_system = ?pmt_sys(ID), is_cvv_empty = true +}). -define(token_bank_card(ID, Prv), ?token_bank_card(ID, Prv, dpan)). -define(token_bank_card(ID, Prv, Method), #domain_BankCardPaymentMethod{ payment_system = ?pmt_sys(ID), @@ -46,7 +48,9 @@ -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{ @@ -84,12 +88,32 @@ -define(contact_info(EMail, Phone), ?contact_info( - EMail, Phone, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined + EMail, + Phone, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined ) ). -define(contact_info( - EMail, Phone, FirstName, LastName, Country, State, City, Address, PostalCode, DateOfBirth, DocumentId + EMail, + Phone, + FirstName, + LastName, + Country, + State, + City, + Address, + PostalCode, + DateOfBirth, + DocumentId ), #domain_ContactInfo{ email = EMail, 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..72fa075c 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,9 @@ 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), @@ -201,7 +207,9 @@ another_shop_test(C) -> Invoice2ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(Invoice1ID, Payment1ID), Payment2Params = make_recurrent_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment refer to another shop">>}, + ExpectedError = #payproc_InvalidRecurrentParentPayment{ + details = <<"Parent payment refer to another shop">> + }, {error, ExpectedError} = start_payment(Invoice2ID, Payment2Params, Client). -spec not_recurring_first_test(config()) -> test_result(). @@ -216,7 +224,9 @@ not_recurring_first_test(C) -> Invoice2ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(Invoice1ID, Payment1ID), Payment2Params = make_recurrent_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment has no recurrent token">>}, + ExpectedError = #payproc_InvalidRecurrentParentPayment{ + details = <<"Parent payment has no recurrent token">> + }, {error, ExpectedError} = start_payment(Invoice2ID, Payment2Params, Client). -spec cancelled_first_payment_test(config()) -> test_result(). @@ -253,7 +263,9 @@ not_exists_invoice_test(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(<<"not_exists">>, <<"not_exists">>), PaymentParams = make_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent invoice not found">>}, + ExpectedError = #payproc_InvalidRecurrentParentPayment{ + details = <<"Parent invoice not found">> + }, {error, ExpectedError} = start_payment(InvoiceID, PaymentParams, Client). -spec not_exists_payment_test(config()) -> test_result(). @@ -262,7 +274,9 @@ not_exists_payment_test(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(InvoiceID, <<"not_exists">>), PaymentParams = make_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment not found">>}, + ExpectedError = #payproc_InvalidRecurrentParentPayment{ + details = <<"Parent payment not found">> + }, {error, ExpectedError} = start_payment(InvoiceID, PaymentParams, Client). %% Internal functions @@ -323,7 +337,9 @@ make_payment_params(FlowType, MakeRecurrent, RecurrentParent, PmtSys) -> make_payment_params(PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent). make_payment_params(PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent) -> - make_payment_params(#domain_ClientInfo{}, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent). + make_payment_params( + #domain_ClientInfo{}, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent + ). make_payment_params(ClientInfo, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent) -> Flow = @@ -360,21 +376,27 @@ make_recurrent_payment_params(MakeRecurrent, RecurrentParent, PmtSys) -> make_recurrent_payment_params(FlowType, MakeRecurrent, RecurrentParent, PmtSys) -> {PaymentTool, _Session} = hg_dummy_provider:make_payment_tool(no_preauth, PmtSys), - make_payment_params(undefined, PaymentTool, undefined, FlowType, MakeRecurrent, RecurrentParent). + make_payment_params( + undefined, PaymentTool, undefined, FlowType, MakeRecurrent, RecurrentParent + ). 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), + _Events = await_events( + InvoiceID, [?evp(?invoice_created(?invoice_w_status(?invoice_unpaid())))], Client + ), InvoiceID. start_payment(InvoiceID, PaymentParams, Client) -> @@ -428,7 +450,9 @@ do_await_events(_InvoiceID, Filters, _Timeout, _Client, timeout, MatchedEvents) do_await_events(InvoiceID, Filters, Timeout, Client, [], MatchedEvents) -> NewEvents = next_event(InvoiceID, Timeout, Client), do_await_events(InvoiceID, Filters, Timeout, Client, NewEvents, MatchedEvents); -do_await_events(InvoiceID, [FilterFn | FTail] = Filters, Timeout, Client, [Ev | EvTail], MatchedEvents) -> +do_await_events( + InvoiceID, [FilterFn | FTail] = Filters, Timeout, Client, [Ev | EvTail], MatchedEvents +) -> case FilterFn(Ev) of true -> do_await_events(InvoiceID, FTail, Timeout, Client, EvTail, [Ev | MatchedEvents]); @@ -527,7 +551,9 @@ construct_domain_fixture(TermSet) -> hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"low">>}), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ + <<"risk_score">> => <<"low">> + }), hg_ct_fixture:construct_system_account_set(?sas(1)), hg_ct_fixture:construct_external_account_set(?eas(1)), @@ -629,7 +655,9 @@ construct_domain_fixture(TermSet) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -659,5 +687,7 @@ construct_domain_fixture(TermSet) -> }}, hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), - hg_ct_fixture:construct_payment_system(?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">>) + hg_ct_fixture:construct_payment_system( + ?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">> + ) ]. diff --git a/apps/hellgate/test/hg_invoice_helper.erl b/apps/hellgate/test/hg_invoice_helper.erl index de387926..ac707522 100644 --- a/apps/hellgate/test/hg_invoice_helper.erl +++ b/apps/hellgate/test/hg_invoice_helper.erl @@ -125,28 +125,30 @@ 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. @@ -250,7 +252,9 @@ register_payment(InvoiceID, RegisterPaymentParams, WithRiskScoring, Client) -> -spec start_payment(_, _, _) -> _. start_payment(InvoiceID, PaymentParams, Client) -> - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), _ = start_payment_ev(InvoiceID, Client), ?payment_ev(PaymentID, ?cash_flow_changed(_)) = next_change(InvoiceID, Client), @@ -299,7 +303,9 @@ await_payment_capture(InvoiceID, PaymentID, Reason, TrxID, Client) -> ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), TrxID =/= undefined andalso - (?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, _Cart, _), ?trx_bound(?trx_info(TrxID)))) = + (?payment_ev( + PaymentID, ?session_ev(?captured(Reason, Cost, _Cart, _), ?trx_bound(?trx_info(TrxID))) + ) = next_change(InvoiceID, Client)), await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client). @@ -322,7 +328,10 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client) -> -spec await_payment_capture_finish(_, _, _, _, _, _) -> _. await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client) -> [ - ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, Cart, _), ?session_finished(?session_succeeded()))), + ?payment_ev( + PaymentID, + ?session_ev(?captured(Reason, Cost, Cart, _), ?session_finished(?session_succeeded())) + ), ?payment_ev(PaymentID, ?payment_status_changed(?captured(Reason, Cost, Cart, _))), ?invoice_status_changed(?invoice_paid()) ] = next_changes(InvoiceID, 3, Client), @@ -340,10 +349,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 +381,14 @@ 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..6771601e 100644 --- a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl @@ -99,23 +99,27 @@ 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} | C ], - ok = hg_invoice_helper:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]), + ok = hg_invoice_helper:start_proxies([ + {hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC} + ]), NewC. -spec end_per_suite(config()) -> _. @@ -255,7 +259,9 @@ payment_success(C) -> payment_w_first_blacklisted_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(inspector_fail_first, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + inspector_fail_first, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = process_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), @@ -278,16 +284,21 @@ payment_w_first_blacklisted_success(C) -> ] } = hg_client_invoicing:explain_route(InvoiceID, PaymentID, Client), ?assertEqual( - <<"Route was blacklisted {domain_PaymentRoute,{domain_ProviderRef,1},{domain_TerminalRef,1}}.">>, Desc + <<"Route was blacklisted {domain_PaymentRoute,{domain_ProviderRef,1},{domain_TerminalRef,1}}.">>, + Desc ). -spec payment_w_all_blacklisted(config()) -> test_return(). payment_w_all_blacklisted(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(inspector_fail_all, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + inspector_fail_all, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -310,7 +321,9 @@ register_payment_success(C) -> data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) }, PayerSessionInfo = #domain_PayerSessionInfo{}, - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), Route = ?route(?prv(1), ?trm(1)), Cost = ?cash(41999, <<"RUB">>), ID = hg_utils:unique_id(), @@ -365,7 +378,9 @@ register_payment_success(C) -> payment_success_additional_info(C) -> Client = hg_ct_helper:cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + empty_cvv, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -398,7 +413,9 @@ payment_w_mobile_commerce(C, Expectation) -> Client = cfg(client, C), PayCash = 1001, InvoiceID = start_invoice(<<"oatmeal">>, make_due_date(10), PayCash, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool({mobile_commerce, Expectation}, ?mob(<<"mts-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + {mobile_commerce, Expectation}, ?mob(<<"mts-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = @@ -408,7 +425,9 @@ payment_w_mobile_commerce(C, Expectation) -> case Expectation of success -> [ - ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), + ?payment_ev( + PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) + ), ?payment_ev(PaymentID, ?payment_status_changed(?processed())) ] = next_changes(InvoiceID, 2, Client); @@ -416,7 +435,9 @@ payment_w_mobile_commerce(C, Expectation) -> [ ?payment_ev( PaymentID, - ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) + ?session_ev( + ?processed(), ?session_finished(?session_failed({failure, Failure})) + ) ), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) @@ -429,20 +450,28 @@ payment_w_crypto_currency_success(C) -> Client = cfg(client, C), PayCash = 2000, InvoiceID = start_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(crypto_currency, ?crypta(<<"bitcoin-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + crypto_currency, ?crypta(<<"bitcoin-ref">>) + ), 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), - ?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). + 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 + ). -spec payment_w_wallet_success(config()) -> _ | no_return(). payment_w_wallet_success(C) -> @@ -459,7 +488,9 @@ payment_w_wallet_success(C) -> payment_success_empty_cvv(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + empty_cvv, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -478,9 +509,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 +600,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). @@ -722,7 +753,9 @@ construct_domain_fixture() -> hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"trusted">>}), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ + <<"risk_score">> => <<"trusted">> + }), hg_ct_fixture:construct_system_account_set(?sas(1)), hg_ct_fixture:construct_external_account_set(?eas(1)), @@ -851,7 +884,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -917,7 +952,9 @@ construct_domain_fixture() -> }}, hg_ct_fixture:construct_mobile_operator(?mob(<<"mts-ref">>), <<"mts mobile operator">>), - hg_ct_fixture:construct_payment_service(?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">>), + hg_ct_fixture:construct_payment_service( + ?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">> + ), hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), hg_ct_fixture:construct_crypto_currency(?crypta(<<"bitcoin-ref">>), <<"bitcoin currency">>) ]. diff --git a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl index 425dfddb..c8331011 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,17 @@ 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 +131,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) -> @@ -209,7 +211,9 @@ create_invoice_template_with_mutations(C) -> Lifetime = make_lifetime(0, 0, 2), #domain_InvoiceTemplate{id = TplID, mutations = Mutations} = create_invoice_tpl_w_mutations(C, Product, Lifetime, Cost, Mutations), - #domain_InvoiceTemplate{mutations = Mutations} = hg_client_invoice_templating:get(TplID, Client). + #domain_InvoiceTemplate{mutations = Mutations} = hg_client_invoice_templating:get( + TplID, Client + ). create_cost(Cost, C) -> Product = <<"rubberduck">>, @@ -240,68 +244,76 @@ 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">>))} + #{ + 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">>))} + #{ + 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 +352,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,19 +367,24 @@ 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 } = hg_client_invoice_templating:update(TplID, Diff1, Client), Tpl2 = update_cost(make_cost(fixed, 42, <<"RUB">>), Tpl1, Client), - Tpl3 = update_cost(make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 42, <<"RUB">>}), Tpl2, Client), - _ = update_cost(make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 100, <<"RUB">>}), Tpl3, Client). + Tpl3 = update_cost( + make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 42, <<"RUB">>}), Tpl2, Client + ), + _ = update_cost( + make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 100, <<"RUB">>}), Tpl3, Client + ). update_cost(Cost, Tpl, Client) -> - {product, #domain_InvoiceTemplateProduct{product = Product}} = Tpl#domain_InvoiceTemplate.details, + {product, #domain_InvoiceTemplateProduct{product = Product}} = + Tpl#domain_InvoiceTemplate.details, NewDetails = hg_ct_helper:make_invoice_tpl_details(Product, Cost), TplNext = Tpl#domain_InvoiceTemplate{details = NewDetails}, TplNext = hg_client_invoice_templating:update( @@ -379,8 +396,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 +421,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,50 +451,56 @@ 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) -> Client = cfg(client, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), ok = hg_client_invoice_templating:delete(TplID, Client), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:get(TplID, Client), + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:get( + TplID, Client + ), Diff = make_invoice_tpl_update_params(#{}), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:update(TplID, Diff, Client), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:delete(TplID, Client). + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:update( + TplID, Diff, Client + ), + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:delete( + TplID, Client + ). -spec terms_retrieval(config()) -> _. terms_retrieval(C) -> @@ -519,28 +542,30 @@ 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, @@ -556,7 +581,9 @@ update_invalid_cost(Cost, currency, TplID, Client) -> update_invalid_cost(Cost, Error, TplID, Client) -> Details = hg_ct_helper:make_invoice_tpl_details(<<"RNGName">>, Cost), Diff = make_invoice_tpl_update_params(#{details => Details}), - {exception, #base_InvalidRequest{errors = [Error]}} = hg_client_invoice_templating:update(TplID, Diff, Client), + {exception, #base_InvalidRequest{errors = [Error]}} = hg_client_invoice_templating:update( + TplID, Diff, Client + ), ok. create_invalid_cost(Cost, amount, Config) -> @@ -566,14 +593,16 @@ create_invalid_cost(Cost, currency, Config) -> create_invalid_cost(Cost, Error, Config) -> Product = <<"rubberduck">>, Lifetime = make_lifetime(0, 0, 2), - {exception, #base_InvalidRequest{errors = [Error]}} = create_invoice_tpl(Config, Product, Lifetime, Cost), + {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..0a32036c 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,34 @@ init_per_suite(C) -> ]), BaseLimitsRevision = hg_limiter_helper:init_per_suite(C), - _BaseRevision = 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()}, 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()), 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 +550,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}, @@ -685,7 +701,9 @@ init_per_testcase(Name = payments_w_bank_conditions, C) -> init_per_testcase(Name = payment_w_misconfigured_routing_failed, C) -> override_domain_fixture(fun payment_w_misconfigured_routing_failed_fixture/2, Name, C); init_per_testcase(Name = ineligible_payment_partial_refund, C) -> - override_domain_fixture(fun(_, _) -> construct_term_set_for_refund_eligibility_time(1) end, Name, C); + override_domain_fixture( + fun(_, _) -> construct_term_set_for_refund_eligibility_time(1) end, Name, C + ); init_per_testcase(Name = invalid_permit_partial_capture_in_service, C) -> override_domain_fixture(fun construct_term_set_for_partial_capture_service_permit/2, Name, C); init_per_testcase(Name = invalid_permit_partial_capture_in_provider, C) -> @@ -748,7 +766,9 @@ init_per_testcase_(Name, C) -> trace_testcase(Name, C) -> SpanName = iolist_to_binary([atom_to_binary(?MODULE), ":", atom_to_binary(Name), "/1"]), - SpanCtx = otel_tracer:start_span(opentelemetry:get_application_tracer(?MODULE), SpanName, #{kind => internal}), + SpanCtx = otel_tracer:start_span(opentelemetry:get_application_tracer(?MODULE), SpanName, #{ + kind => internal + }), %% NOTE This also puts otel context to process dictionary _ = otel_tracer:set_current_span(SpanCtx), [{span_ctx, SpanCtx} | C]. @@ -783,11 +803,13 @@ 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 +826,43 @@ 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 +870,60 @@ 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) -> @@ -939,12 +975,16 @@ invalid_invoice_template_id(C) -> TplID1 = <<"Watsthat">>, Params1 = hg_ct_helper:make_invoice_params_tpl(TplID1), - {exception, #payproc_InvoiceTemplateNotFound{}} = hg_client_invoicing:create_with_tpl(Params1, Client), + {exception, #payproc_InvoiceTemplateNotFound{}} = hg_client_invoicing:create_with_tpl( + Params1, Client + ), TplID2 = create_invoice_tpl(C), _ = delete_invoice_tpl(TplID2, C), Params2 = hg_ct_helper:make_invoice_params_tpl(TplID2), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoicing:create_with_tpl(Params2, Client). + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoicing:create_with_tpl( + Params2, Client + ). -spec invoice_w_template_idempotency(config()) -> _ | no_return(). invoice_w_template_idempotency(C) -> @@ -953,8 +993,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 +1008,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 +1022,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 +1037,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, @@ -1024,8 +1064,12 @@ invoice_w_template_amount_randomization(C) -> }, #domain_InvoiceTemplate{id = TplID} = hg_client_invoice_templating:create(TplParams, TplClient), InvoiceID = hg_utils:unique_id(), - Params = hg_ct_helper:make_invoice_params_tpl(InvoiceID, TplID, FixedCost, hg_ct_helper:make_invoice_context()), - ?invoice_state(#domain_Invoice{mutations = Mutations}) = hg_client_invoicing:create_with_tpl(Params, Client), + Params = hg_ct_helper:make_invoice_params_tpl( + InvoiceID, TplID, FixedCost, hg_ct_helper:make_invoice_context() + ), + ?invoice_state(#domain_Invoice{mutations = Mutations}) = hg_client_invoicing:create_with_tpl( + Params, Client + ), ?assertMatch( [{amount, #domain_InvoiceAmountMutation{original = OriginalAmount, mutated = Mutated}}] when Mutated =< OriginalAmount, @@ -1039,8 +1083,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 +1092,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 +1101,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 +1111,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 +1121,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 +1131,11 @@ 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). @@ -1129,7 +1175,9 @@ register_invoice_payment(ShopID, Client, C) -> register_invoice_payment(Route, ShopID, Client, C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = #payproc_RegisterInvoicePaymentParams{ payer_params = {payment_resource, #payproc_PaymentResourcePayerParams{ @@ -1154,17 +1202,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 +1218,22 @@ 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 +1241,24 @@ 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 +1266,15 @@ 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 +1285,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 +1293,22 @@ 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 +1319,10 @@ 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,12 +1330,14 @@ 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 := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, + limit = #domain_TurnoverLimit{ + id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY + }, value = 10000 } ] @@ -1282,11 +1347,13 @@ 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,41 +1364,49 @@ 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), 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 = payproc_errors:match('PaymentFailure', Failure, fun( + {no_route_found, {rejected, {limit_overflow, _}}} + ) -> ok end). @@ -1347,7 +1422,9 @@ limit_hold_operation_not_supported(C) -> -spec limit_hold_payment_tool_not_supported(config()) -> test_return(). limit_hold_payment_tool_not_supported(C) -> - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(crypto_currency, ?crypta(<<"bitcoin-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + crypto_currency, ?crypta(<<"bitcoin-ref">>) + ), Failure = payment_route_not_found(PaymentTool, Session, C), ?assertRouteNotFound(Failure, {rejected, {limit_misconfiguration, _}}, <<"[{">>). @@ -1364,17 +1441,23 @@ 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), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), _ = start_payment_ev(InvoiceID, Client), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) = next_change(InvoiceID, Client), @@ -1386,22 +1469,26 @@ 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 +1505,17 @@ 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,24 +1524,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, _}}}) -> + 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 @@ -1467,7 +1560,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 +1570,15 @@ 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 +1599,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,21 +1619,29 @@ 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), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), 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), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), await_payment_shop_limit_rollback(InvoiceID, PaymentID, Client). @@ -1540,12 +1649,16 @@ 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), @@ -1580,9 +1693,13 @@ payment_w_misconfigured_routing_failed(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -1604,7 +1721,10 @@ 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( @@ -1639,7 +1759,9 @@ mk_provider_w_term(TerminalRef, TerminalName, ProviderRef, ProviderName, Provide }} ]. -new_merchant_terms_attempt_limit(TermSetHierarchyRef, TargetTermSetHierarchyRef, Attempts, Revision) -> +new_merchant_terms_attempt_limit( + TermSetHierarchyRef, TargetTermSetHierarchyRef, Attempts, Revision +) -> #domain_TermSetHierarchy{term_set = TermsSet} = hg_domain:get(Revision, {term_set_hierarchy, TermSetHierarchyRef}), #domain_TermSet{payments = PaymentsTerms0} = TermsSet, @@ -1649,12 +1771,16 @@ new_merchant_terms_attempt_limit(TermSetHierarchyRef, TargetTermSetHierarchyRef, [ {term_set_hierarchy, #domain_TermSetHierarchyObject{ ref = TargetTermSetHierarchyRef, - data = #domain_TermSetHierarchy{term_set = TermsSet#domain_TermSet{payments = PaymentsTerms1}} + data = #domain_TermSetHierarchy{ + term_set = TermsSet#domain_TermSet{payments = PaymentsTerms1} + } }} ]. patch_limit_config_w_invalid_currency(Revision, _C) -> - NewRevision = hg_domain:update({limit_config, hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"KEK">>)}), + NewRevision = hg_domain:update( + {limit_config, hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"KEK">>)} + ), [ change_terms_limit_config_version(Revision, NewRevision) ]. @@ -1662,7 +1788,9 @@ patch_limit_config_w_invalid_currency(Revision, _C) -> patch_limit_config_for_withdrawal(Revision, _C) -> NewRevision = hg_domain:update( {limit_config, - hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal))} + hg_limiter_helper:mk_config_object( + ?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal) + )} ), [ change_terms_limit_config_version(Revision, NewRevision) @@ -1705,7 +1833,9 @@ patch_providers_limits_to_fail_and_overflow(Revision, _C) -> %% 4. Second must get rejected due limit overflow. NewRevision = hg_domain:update([ {limit_config, - hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal))} + hg_limiter_helper:mk_config_object( + ?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal) + )} ]), [ hg_ct_fixture:construct_payment_routing_ruleset( @@ -1736,7 +1866,10 @@ patch_providers_limits_to_fail_and_overflow(Revision, _C) -> ]. unset_providers_chargebacks_terms(Revision, _C) -> - lists:flatten([unset_provider_chargebacks_terms(Revision, ProviderRef) || ProviderRef <- [?prv(2)]]). + lists:flatten([ + unset_provider_chargebacks_terms(Revision, ProviderRef) + || ProviderRef <- [?prv(2)] + ]). unset_provider_chargebacks_terms(Revision, ProviderRef) -> Provider = @@ -1748,7 +1881,9 @@ unset_provider_chargebacks_terms(Revision, ProviderRef) -> ref = ProviderRef, data = Provider#domain_Provider{ terms = Terms#domain_ProvisionTermSet{ - payments = PaymentsTermSet#domain_PaymentsProvisionTerms{chargebacks = undefined} + payments = PaymentsTermSet#domain_PaymentsProvisionTerms{ + chargebacks = undefined + } } } }} @@ -1765,10 +1900,14 @@ change_terms_limit_config_version(Revision, LimitConfigRevision) -> change_terms_limit_config_version(Revision, ProviderRef, TurnoverLimits) -> change_provider_payments_provision_terms(ProviderRef, Revision, fun(PaymentsProvisionTerms) -> - PaymentsProvisionTerms#domain_PaymentsProvisionTerms{turnover_limits = {value, TurnoverLimits}} + PaymentsProvisionTerms#domain_PaymentsProvisionTerms{ + turnover_limits = {value, TurnoverLimits} + } end). -change_provider_payments_provision_terms(ProviderID, Revision, Changer) when is_function(Changer, 1) -> +change_provider_payments_provision_terms(ProviderID, Revision, Changer) when + is_function(Changer, 1) +-> Provider = #domain_Provider{terms = Terms} = hg_domain:get(Revision, {provider, ProviderID}), Terms1 = Terms#domain_ProvisionTermSet{ @@ -1805,7 +1944,9 @@ payment_capture_retries_exceeded(C) -> Amount = 42000, Cost = ?cash(Amount, <<"RUB">>), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - PaymentParams = make_scenario_payment_params([good, temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), + PaymentParams = make_scenario_payment_params( + [good, temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>) + ), PaymentID = process_payment(InvoiceID, PaymentParams, Client), Reason = ?timeout_reason(), Target = ?captured(Reason, Cost), @@ -1845,7 +1986,9 @@ payment_partial_capture_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). @@ -1853,21 +1996,28 @@ 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), - PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}, ?pmt_sys(<<"visa-ref">>)), + 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)), ok = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"cancel">>, Client), ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_started())) = next_change(InvoiceID, Client), timeout = next_change(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting:get_balance(SettlementID) + ), ?assertException( error, {{woody_error, _}, _}, @@ -1878,25 +2028,35 @@ 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), - PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}, ?pmt_sys(<<"visa-ref">>)), + 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)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting:get_balance(SettlementID) + ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _, _Allocation)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), timeout = next_change(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting:get_balance(SettlementID) + ), ?assertException( error, {{woody_error, _}, _}, @@ -1919,7 +2079,10 @@ repair_failed_cancel(InvoiceID, PaymentID, Reason, Client) -> ], ok = repair_invoice(InvoiceID, Changes, Client), [ - ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))), + ?payment_ev( + PaymentID, + ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded())) + ), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_changes(InvoiceID, 2, Client), PaymentID. @@ -1929,15 +2092,21 @@ 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), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client + ), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state( ?invoice_w_status(?invoice_paid()), @@ -1962,17 +2131,23 @@ 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), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client + ), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state(?invoice_w_status(?invoice_paid()), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -1982,12 +2157,16 @@ 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), @@ -2019,7 +2198,9 @@ payment_w_terminal_w_payment_service_success(C) -> BadForm = #{<<"tag">> => <<"666">>}, _ = assert_invalid_post_request({URL, BadForm}), _ = assert_success_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID, UserInteraction, Client + ), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state( @@ -2043,18 +2224,24 @@ payment_bank_card_category_condition(C) -> Client = cfg(client, C), PayCash = 2000, InvoiceID = start_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C), - {{bank_card, BC}, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), + {{bank_card, BC}, Session} = hg_dummy_provider:make_payment_tool( + empty_cvv, ?pmt_sys(<<"visa-ref">>) + ), BankCard = BC#domain_BankCard{ category = <<"CORPORATE CARD">> }, PaymentTool = {bank_card, BankCard}, PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = 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(cfg(party_id, C), cfg(shop_id, C), Route), - ?cash(200, <<"RUB">>) = get_cashflow_volume({merchant, settlement}, {system, settlement}, CF, CFContext). + 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(). payment_success_on_second_try(C) -> @@ -2073,7 +2260,9 @@ payment_success_on_second_try(C) -> _ = assert_success_post_request({URL, GoodForm}), %% ensure that callback is now invalid̋ _ = assert_invalid_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID, UserInteraction, Client + ), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client). @@ -2081,7 +2270,9 @@ payment_success_on_second_try(C) -> payment_success_with_increased_cost(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_increase, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + change_cash_increase, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_cash_changed_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -2098,19 +2289,25 @@ 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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_increase, ?pmt_sys(<<"visa-ref">>)), + 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), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2124,7 +2321,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), @@ -2154,16 +2351,25 @@ refund_payment_with_increased_cost(C) -> PrvAccount2 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), 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), + #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( + 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) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_decrease, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + change_cash_decrease, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_cash_changed_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -2180,19 +2386,25 @@ 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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_decrease, ?pmt_sys(<<"visa-ref">>)), + 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), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2206,7 +2418,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), @@ -2236,14 +2448,23 @@ refund_payment_with_decreased_cost(C) -> PrvAccount2 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), 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), + #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( + 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), - PaymentID = hg_invoice_helper:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), + PaymentID = hg_invoice_helper:await_payment_session_started( + InvoiceID, PaymentID, Client, ?processed() + ), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(_)))), ?payment_ev(PaymentID, ?cash_changed(_, _)), @@ -2258,7 +2479,9 @@ execute_cash_changed_payment(InvoiceID, PaymentParams, Client) -> payment_fail_after_silent_callback(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberdick">>, make_due_date(20), 42000, C), - PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), + PaymentID = start_payment( + InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client + ), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), {URL, Form} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, hg_dummy_provider:construct_silent_callback(Form)}), @@ -2269,7 +2492,9 @@ payment_session_changed_to_fail(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberdick">>, make_due_date(20), 42000, C), %% Payment w/ preauth for suspend w/ user interaction occurrence. - PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), + PaymentID = start_payment( + InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client + ), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), Failure = payproc_errors:construct( @@ -2289,7 +2514,9 @@ payment_session_changed_to_fail(C) -> %% from request parameter. Tag = user_interaction_callback_tag(UserInteraction), ok = hg_dummy_provider:change_payment_session(Tag, Change), - {failed, PaymentID, {failure, Failure}} = await_payment_process_failure(InvoiceID, PaymentID, Client), + {failed, PaymentID, {failure, Failure}} = await_payment_process_failure( + InvoiceID, PaymentID, Client + ), %% Bad session callback tag must not be found again ?assertMatch( @@ -2303,7 +2530,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), @@ -2322,7 +2549,9 @@ payments_w_bank_card_issuer_conditions(C) -> %kaz fail SecondInvoice = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 1001, C), ?assertEqual( - {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, + {exception, #base_InvalidRequest{ + errors = [<<"Invalid amount, more than allowed maximum">>] + }}, hg_client_invoicing:start_payment(SecondInvoice, KazPaymentParams, Client) ), %rus success @@ -2351,7 +2580,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), @@ -2369,7 +2598,9 @@ payments_w_bank_conditions(C) -> %bank 1 fail SecondInvoice = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 1001, C), ?assertEqual( - {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, + {exception, #base_InvalidRequest{ + errors = [<<"Invalid amount, more than allowed maximum">>] + }}, hg_client_invoicing:start_payment(SecondInvoice, TestPaymentParams, Client) ), %bank 1 /w different wildcard fail @@ -2380,7 +2611,9 @@ payments_w_bank_conditions(C) -> }, WildPaymentParams = make_payment_params({bank_card, WildBankCard}, Session1, instant), ?assertEqual( - {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, + {exception, #base_InvalidRequest{ + errors = [<<"Invalid amount, more than allowed maximum">>] + }}, hg_client_invoicing:start_payment(ThirdInvoice, WildPaymentParams, Client) ), %some other bank success @@ -2399,7 +2632,9 @@ payments_w_bank_conditions(C) -> }, FallbackPaymentParams = make_payment_params({bank_card, FallbackBankCard}, Session3, instant), ?assertEqual( - {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, + {exception, #base_InvalidRequest{ + errors = [<<"Invalid amount, more than allowed maximum">>] + }}, hg_client_invoicing:start_payment(FifthInvoice, FallbackPaymentParams, Client) ). @@ -2421,7 +2656,9 @@ invoice_success_on_third_payment(C) -> GoodPost = get_post_request(UserInteraction), %% simulate user interaction FTW! _ = assert_success_post_request(GoodPost), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID3, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID3, UserInteraction, Client + ), PaymentID3 = await_payment_process_finish(InvoiceID, PaymentID3, Client), PaymentID3 = await_payment_capture(InvoiceID, PaymentID3, Client). @@ -2432,7 +2669,9 @@ payment_risk_score_check(C) -> % Invoice w/ cost < 500000 InvoiceID1 = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment(InvoiceID1, PaymentParams, Client), + ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment( + InvoiceID1, PaymentParams, Client + ), ?payment_ev(PaymentID1, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID1, Client), % low risk score... @@ -2444,7 +2683,9 @@ payment_risk_score_check(C) -> PaymentID1 = await_payment_capture(InvoiceID1, PaymentID1, Client), % Invoice w/ 500000 < cost < 100000000 InvoiceID2 = start_invoice(<<"rubberbucks">>, make_due_date(10), 31337000, C), - ?payment_state(?payment(PaymentID2)) = hg_client_invoicing:start_payment(InvoiceID2, PaymentParams, Client), + ?payment_state(?payment(PaymentID2)) = hg_client_invoicing:start_payment( + InvoiceID2, PaymentParams, Client + ), ?payment_ev(PaymentID2, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID2, Client), % high risk score... @@ -2456,7 +2697,9 @@ payment_risk_score_check(C) -> PaymentID2 = await_payment_capture(InvoiceID2, PaymentID2, Client), % Invoice w/ 100000000 =< cost InvoiceID3 = start_invoice(<<"rubbersocks">>, make_due_date(10), 100000000, C), - ?payment_state(?payment(PaymentID3)) = hg_client_invoicing:start_payment(InvoiceID3, PaymentParams, Client), + ?payment_state(?payment(PaymentID3)) = hg_client_invoicing:start_payment( + InvoiceID3, PaymentParams, Client + ), [ ?payment_ev(PaymentID3, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -2488,13 +2731,17 @@ invalid_payment_adjustment(C) -> PaymentID = start_payment(InvoiceID, PaymentParams, Client), %% no way to create adjustment for a payment not yet finished ?invalid_payment_status(?pending()) = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, make_adjustment_params(), Client + ), _UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), PaymentID = await_payment_process_timeout(InvoiceID, PaymentID, Client), %% no way to create adjustment for a failed payment %% Correction. It was changed to failed payment not being in the way of adjustment ?adjustment(_AdjustmentID, ?adjustment_pending()) = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client). + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, make_adjustment_params(), Client + ). -spec payment_adjustment_success(config()) -> test_return(). payment_adjustment_success(C) -> @@ -2512,7 +2759,9 @@ payment_adjustment_success(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2520,7 +2769,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), @@ -2538,8 +2787,14 @@ payment_adjustment_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 2, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -2582,7 +2837,9 @@ payment_adjustment_w_amount_success(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2590,7 +2847,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), @@ -2613,9 +2870,17 @@ payment_adjustment_w_amount_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 3, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -2629,11 +2894,23 @@ payment_adjustment_w_amount_success(C) -> OriginalAmount, ?merchant_to_system_share_1, ?system_to_provider_share_initial, ZeroShare ), {NewOpDiffMrc, NewOpDiffSys, NewOpDiffPrv} = compute_operation_amount_diffs( - NewAmount, ?merchant_to_system_share_1, ?system_to_provider_share_actual, ?system_to_external_fixed + 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,13 +2920,19 @@ 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), + ShopID = hg_ct_helper:create_shop( + cfg(party_config_ref, C), ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient + ), InvoiceID = start_invoice(ShopID, <<"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), + _RefundID = execute_payment_refund( + InvoiceID, PaymentID, make_refund_params(1000, <<"RUB">>), Client + ), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), - _AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), + _AdjustmentID = execute_payment_adjustment( + InvoiceID, PaymentID, make_adjustment_params(), Client + ), NewCashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), ?assertEqual( [ @@ -2679,18 +2962,22 @@ 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">>)), _ChargebackID = execute_payment_chargeback(InvoiceID, PaymentID, Params, Client), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), - _AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), + _AdjustmentID = execute_payment_adjustment( + InvoiceID, PaymentID, make_adjustment_params(), Client + ), NewCashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), ?assertEqual( [ @@ -2722,9 +3009,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 +3026,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), @@ -2757,28 +3044,40 @@ payment_adjustment_captured_partial(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF2, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF2, CFContext), Context = #{operation_amount => Cash}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), - #domain_Cash{amount = MrcAmount2} = hg_cashflow:compute_volume(?merchant_to_system_share_3, Context), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( + ?merchant_to_system_share_1, Context + ), + #domain_Cash{amount = MrcAmount2} = hg_cashflow:compute_volume( + ?merchant_to_system_share_3, Context + ), % fees after adjustment are less than before, so own amount is greater MrcDiff = MrcAmount1 - MrcAmount2, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), - #domain_Cash{amount = PrvAmount2} = hg_cashflow:compute_volume(?system_to_provider_share_actual, Context), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( + ?system_to_provider_share_initial, Context + ), + #domain_Cash{amount = PrvAmount2} = hg_cashflow:compute_volume( + ?system_to_provider_share_actual, Context + ), % inversed in opposite of merchant fees PrvDiff = PrvAmount2 - PrvAmount1, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), - #domain_Cash{amount = SysAmount2} = hg_cashflow:compute_volume(?system_to_external_fixed, Context), + #domain_Cash{amount = SysAmount2} = hg_cashflow:compute_volume( + ?system_to_external_fixed, Context + ), SysDiff = MrcDiff + PrvDiff - SysAmount2, ?assertEqual(SysDiff, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)). -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), - PaymentParams = make_scenario_payment_params([temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), + 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">>), Captured = {captured, #domain_InvoicePaymentCaptured{cost = CaptureCost}}, @@ -2787,7 +3086,9 @@ payment_adjustment_captured_from_failed(C) -> ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?invalid_payment_status(?pending()) = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, AdjustmentParams, Client + ), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -2795,22 +3096,28 @@ 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{}}), + InvalidAdjustmentParams1 = make_status_adjustment_params( + {processed, #domain_InvoicePaymentProcessed{}} + ), ?invalid_payment_target_status(?processed()) = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, InvalidAdjustmentParams1, Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, InvalidAdjustmentParams1, Client + ), FailedTargetStatus = ?failed({failure, #domain_Failure{code = <<"404">>}}), FailedAdjustmentParams = make_status_adjustment_params(FailedTargetStatus), - _FailedAdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client), + _FailedAdjustmentID = execute_payment_adjustment( + InvoiceID, PaymentID, FailedAdjustmentParams, Client + ), ?assertMatch( ?payment_state(?payment_w_status(PaymentID, FailedTargetStatus)), @@ -2818,7 +3125,9 @@ payment_adjustment_captured_from_failed(C) -> ), ?payment_already_has_status(FailedTargetStatus) = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, FailedAdjustmentParams, Client + ), AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client), ?payment_state(Payment) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -2833,10 +3142,14 @@ payment_adjustment_captured_from_failed(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, DCF2, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, DCF2, CFContext), Context = #{operation_amount => CaptureCost}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( + ?merchant_to_system_share_1, Context + ), MrcDiff = CaptureAmount - MrcAmount1, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( + ?system_to_provider_share_initial, Context + ), PrvDiff = PrvAmount1 - CaptureAmount, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), SysDiff = MrcAmount1 - PrvAmount1, @@ -2845,27 +3158,29 @@ 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), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), {CF1, 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), 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">>), @@ -2882,10 +3197,14 @@ payment_adjustment_failed_from_captured(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), Context = #{operation_amount => ?cash(Amount, <<"RUB">>)}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( + ?merchant_to_system_share_1, Context + ), MrcDiff = Amount - MrcAmount1, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount1) - maps:get(own_amount, MrcAccount2)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( + ?system_to_provider_share_initial, Context + ), PrvDiff = PrvAmount1 - Amount, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount1) - maps:get(own_amount, PrvAccount2)), SysDiff = MrcAmount1 - PrvAmount1, @@ -2905,12 +3224,14 @@ 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()), % reinit terminal cashflow - ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(initial)), + ok = update_payment_terms_cashflow( + ?prv(100), get_payment_adjustment_provider_cashflow(initial) + ), OriginalAmount = 100000, NewAmount = 200000, @@ -2918,7 +3239,9 @@ payment_adjustment_change_amount_and_captured(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2927,7 +3250,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), @@ -2967,8 +3290,12 @@ payment_adjustment_change_amount_and_captured(C) -> MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), Context0 = #{operation_amount => ?cash(OriginalAmount, <<"RUB">>)}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context0), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context0), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( + ?merchant_to_system_share_1, Context0 + ), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( + ?system_to_provider_share_initial, Context0 + ), MrcDiff0 = OriginalAmount - MrcAmount1, PrvDiff0 = PrvAmount1 - OriginalAmount, SysDiff0 = MrcAmount1 - PrvAmount1, @@ -2980,15 +3307,25 @@ payment_adjustment_change_amount_and_captured(C) -> AdjustmentParams1 = make_adjustment_params(AdjReason1 = <<"imdrunk">>, undefined, NewAmount), ?adjustment(AdjustmentID1, ?adjustment_pending()) = Adjustment1 = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams1, Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, AdjustmentParams1, Client + ), #domain_InvoicePaymentAdjustment{id = AdjustmentID1, reason = AdjReason1} = hg_client_invoicing:get_payment_adjustment(InvoiceID, PaymentID, AdjustmentID1, Client), ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_created(Adjustment1))) = next_change(InvoiceID, Client), [ - ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 3, Client), ?payment_state(Payment1) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -3027,8 +3364,12 @@ payment_adjustment_change_amount_and_captured(C) -> ), Context2 = #{operation_amount => ChangedCost}, - #domain_Cash{amount = MrcAmount3} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context2), - #domain_Cash{amount = PrvAmount3} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context2), + #domain_Cash{amount = MrcAmount3} = hg_cashflow:compute_volume( + ?merchant_to_system_share_1, Context2 + ), + #domain_Cash{amount = PrvAmount3} = hg_cashflow:compute_volume( + ?system_to_provider_share_initial, Context2 + ), MrcDiff2 = NewAmount - MrcAmount3, PrvDiff2 = PrvAmount3 - NewAmount, SysDiff2 = MrcAmount3 - PrvAmount3, @@ -3050,27 +3391,33 @@ 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)), + ok = update_payment_terms_cashflow( + ?prv(100), get_payment_adjustment_provider_cashflow(initial) + ), OriginalAmount = 100000, NewAmount = 200000, % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), NewAmount, C), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?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), @@ -3095,15 +3442,25 @@ payment_adjustment_change_amount_and_refund_all(C) -> AdjustmentParams1 = make_adjustment_params(AdjReason1 = <<"imdrunk">>, undefined, NewAmount), ?adjustment(AdjustmentID1, ?adjustment_pending()) = Adjustment1 = - hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams1, Client), + hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, AdjustmentParams1, Client + ), #domain_InvoicePaymentAdjustment{id = AdjustmentID1, reason = AdjReason1} = hg_client_invoicing:get_payment_adjustment(InvoiceID, PaymentID, AdjustmentID1, Client), ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_created(Adjustment1))) = next_change(InvoiceID, Client), [ - ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 3, Client), ?payment_state(Payment1) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -3144,17 +3501,24 @@ 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), + #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( + 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), @@ -3169,7 +3533,9 @@ status_adjustment_of_partial_refunded_payment(C) -> FailedAdjustmentParams = make_status_adjustment_params(FailedTargetStatus), {exception, #base_InvalidRequest{ errors = [<<"Cannot change status of payment with refunds.">>] - }} = hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client). + }} = hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, FailedAdjustmentParams, Client + ). -spec registered_payment_adjustment_success(config()) -> _. registered_payment_adjustment_success(C) -> @@ -3186,7 +3552,9 @@ registered_payment_adjustment_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), Route = ?route(?prv(100), ?trm(1)), String = <<"STRING">>, PaymentParams = #payproc_RegisterInvoicePaymentParams{ @@ -3198,7 +3566,17 @@ registered_payment_adjustment_success(C) -> client_info = #domain_ClientInfo{} }, contact_info = ?contact_info( - String, String, String, String, String, String, String, String, String, String, String + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String ) }}, route = Route, @@ -3213,7 +3591,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), @@ -3231,8 +3609,14 @@ registered_payment_adjustment_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 2, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -3250,7 +3634,9 @@ payment_temporary_unavailability_retry_success(C) -> Amount = 42000, Cost = make_cash(Amount), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - PaymentParams = make_scenario_payment_params([temp, temp, good, temp, temp], ?pmt_sys(<<"visa-ref">>)), + PaymentParams = make_scenario_payment_params( + [temp, temp, good, temp, temp], ?pmt_sys(<<"visa-ref">>) + ), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_sessions_restarts(PaymentID, ?processed(), InvoiceID, Client, 2), @@ -3259,7 +3645,9 @@ payment_temporary_unavailability_retry_success(C) -> ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _, _)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), - PaymentID = await_sessions_restarts(PaymentID, ?captured(Reason, Cost, undefined), InvoiceID, Client, 2), + PaymentID = await_sessions_restarts( + PaymentID, ?captured(Reason, Cost, undefined), InvoiceID, Client, 2 + ), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client), ?invoice_state( ?invoice_w_status(?invoice_paid()), @@ -3270,7 +3658,9 @@ payment_temporary_unavailability_retry_success(C) -> payment_temporary_unavailability_too_many_retries(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentParams = make_scenario_payment_params([temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), + PaymentParams = make_scenario_payment_params( + [temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>) + ), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), {failed, PaymentID, {failure, Failure}} = @@ -3311,8 +3701,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,14 +3726,20 @@ 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), + ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change( + InvoiceID, InvoicingClient + ), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), Exception = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, InvoicingClient), {exception, #base_InvalidRequest{}} = Exception. @@ -3351,17 +3747,25 @@ 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), + ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change( + InvoiceID, InvoicingClient + ), ?payment_state( ?payment(PaymentID) - ) = hg_client_invoicing:start_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), InvoicingClient), + ) = hg_client_invoicing:start_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), InvoicingClient + ), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, InvoicingClient), {CF, Route} = await_payment_cash_flow(InvoiceID, PaymentID, InvoicingClient), @@ -3379,7 +3783,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 +3792,16 @@ 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 +3824,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 +3837,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 +3857,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), @@ -3496,7 +3904,9 @@ create_chargeback_idempotency(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3504,14 +3914,21 @@ create_chargeback_idempotency(C) -> ] = next_changes(IID, 2, Client), ?assertMatch(CB, hg_client_invoicing:create_chargeback(IID, PID, CBParams, Client)), NewCBParams = make_chargeback_params(Levy), - ?assertMatch(?chargeback_pending(), hg_client_invoicing:create_chargeback(IID, PID, NewCBParams, Client)), + ?assertMatch( + ?chargeback_pending(), hg_client_invoicing:create_chargeback(IID, PID, NewCBParams, Client) + ), Settlement0 = hg_accounting:get_balance(SID), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3528,7 +3945,9 @@ cancel_payment_chargeback(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3538,9 +3957,14 @@ cancel_payment_chargeback(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3558,7 +3982,9 @@ cancel_partial_payment_chargeback(C) -> Paid = Partial - Fee, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback_partial_capture(C, Cost, Partial, CBParams, ?pmt_sys(<<"mastercard-ref">>)), + {IID, PID, SID, CB} = start_chargeback_partial_capture( + C, Cost, Partial, CBParams, ?pmt_sys(<<"mastercard-ref">>) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3568,9 +3994,14 @@ cancel_partial_payment_chargeback(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Partial - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3598,7 +4029,9 @@ cancel_payment_chargeback_refund(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3609,9 +4042,14 @@ cancel_payment_chargeback_refund(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), RefundOk = hg_client_invoicing:refund_payment(IID, PID, RefundParams, Client), ?assertMatch(?chargeback_pending(), RefundError), @@ -3624,20 +4062,29 @@ reject_payment_chargeback_inconsistent(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))) ] = next_changes(IID, 2, Client), InconsistentParams = make_chargeback_reject_params(?cash(10, <<"USD">>)), - Inconsistent = hg_client_invoicing:reject_chargeback(IID, PID, CBID, InconsistentParams, Client), + Inconsistent = hg_client_invoicing:reject_chargeback( + IID, PID, CBID, InconsistentParams, Client + ), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), ?assertMatch(?inconsistent_chargeback_currency(_), Inconsistent). @@ -3650,7 +4097,9 @@ reject_payment_chargeback(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3660,9 +4109,14 @@ reject_payment_chargeback(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3679,7 +4133,9 @@ reject_payment_chargeback_no_fees(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3689,9 +4145,14 @@ reject_payment_chargeback_no_fees(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3708,7 +4169,9 @@ reject_payment_chargeback_new_levy(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3721,9 +4184,14 @@ reject_payment_chargeback_new_levy(C) -> ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(RejectLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(CF1))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 4, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertNotEqual(CF0, CF1), @@ -3739,7 +4207,9 @@ accept_payment_chargeback_inconsistent(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3747,14 +4217,23 @@ accept_payment_chargeback_inconsistent(C) -> ] = next_changes(IID, 2, Client), InconsistentLevyParams = make_chargeback_accept_params(?cash(10, <<"USD">>), undefined), InconsistentBodyParams = make_chargeback_accept_params(undefined, ?cash(10, <<"USD">>)), - InconsistentLevy = hg_client_invoicing:accept_chargeback(IID, PID, CBID, InconsistentLevyParams, Client), - InconsistentBody = hg_client_invoicing:accept_chargeback(IID, PID, CBID, InconsistentBodyParams, Client), + InconsistentLevy = hg_client_invoicing:accept_chargeback( + IID, PID, CBID, InconsistentLevyParams, Client + ), + InconsistentBody = hg_client_invoicing:accept_chargeback( + IID, PID, CBID, InconsistentBodyParams, Client + ), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentLevy), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentBody). @@ -3766,21 +4245,30 @@ accept_payment_chargeback_exceeded(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))) ] = next_changes(IID, 2, Client), ExceedBody = 200000, - ExceedParams = make_chargeback_accept_params(?cash(LevyAmount, <<"RUB">>), ?cash(ExceedBody, <<"RUB">>)), + ExceedParams = make_chargeback_accept_params( + ?cash(LevyAmount, <<"RUB">>), ?cash(ExceedBody, <<"RUB">>) + ), Exceeded = hg_client_invoicing:accept_chargeback(IID, PID, CBID, ExceedParams, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), ?assertMatch(?invoice_payment_amount_exceeded(_), Exceeded). @@ -3793,7 +4281,9 @@ accept_payment_chargeback_empty_params(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3803,8 +4293,13 @@ accept_payment_chargeback_empty_params(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), @@ -3824,7 +4319,9 @@ accept_payment_chargeback_twice(C) -> Body = ?cash(BodyAmount, <<"RUB">>), Levy = ?cash(LevyAmount, <<"RUB">>), CBParams1 = make_chargeback_params(Levy, Body), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams1, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams1, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3834,8 +4331,13 @@ accept_payment_chargeback_twice(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))) + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ) ] = next_changes(IID, 2, Client), Settlement1 = hg_accounting:get_balance(SID), CBParams2 = make_chargeback_params(Levy), @@ -3849,8 +4351,13 @@ accept_payment_chargeback_twice(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID2, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID2, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID2, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID2, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID2, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -3872,7 +4379,9 @@ accept_payment_chargeback_new_body(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3884,9 +4393,14 @@ accept_payment_chargeback_new_body(C) -> ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_body_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ) ] = next_changes(IID, 4, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3904,7 +4418,9 @@ accept_payment_chargeback_new_levy(C) -> NewLevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3914,10 +4430,17 @@ accept_payment_chargeback_new_levy(C) -> AcceptParams = make_chargeback_accept_params(?cash(NewLevyAmount, <<"RUB">>), undefined), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(?cash(NewLevyAmount, <<"RUB">>)))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(?cash(NewLevyAmount, <<"RUB">>))) + ), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 5, Client), Settlement1 = hg_accounting:get_balance(SID), @@ -3933,7 +4456,9 @@ reopen_accepted_payment_chargeback_and_cancel_ok(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3942,24 +4467,42 @@ reopen_accepted_payment_chargeback_and_cancel_ok(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), ReopenParams = make_chargeback_reopen_params(Levy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) + ), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(CBCF))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 4, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed([]))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?payment_status_changed(?captured())) ] = next_changes(IID, 4, Client), ok. @@ -3971,7 +4514,9 @@ reopen_payment_chargeback_inconsistent(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3980,14 +4525,23 @@ reopen_payment_chargeback_inconsistent(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), InconsistentLevyParams = make_chargeback_reopen_params(?cash(10, <<"USD">>), undefined), InconsistentBodyParams = make_chargeback_reopen_params(Levy, ?cash(10, <<"USD">>)), - InconsistentLevy = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, InconsistentLevyParams, Client), - InconsistentBody = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, InconsistentBodyParams, Client), + InconsistentLevy = hg_client_invoicing:reopen_chargeback( + IID, PID, CBID, InconsistentLevyParams, Client + ), + InconsistentBody = hg_client_invoicing:reopen_chargeback( + IID, PID, CBID, InconsistentBodyParams, Client + ), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentLevy), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentBody). @@ -3998,7 +4552,9 @@ reopen_payment_chargeback_exceeded(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, _SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4007,9 +4563,14 @@ reopen_payment_chargeback_exceeded(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), ExceededParams = make_chargeback_reopen_params(Levy, ?cash(50000, <<"RUB">>)), Exceeded = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ExceededParams, Client), @@ -4026,7 +4587,9 @@ reopen_payment_chargeback_cancel(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4036,27 +4599,45 @@ reopen_payment_chargeback_cancel(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) + ) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -4079,7 +4660,9 @@ reopen_payment_chargeback_reject(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4089,27 +4672,45 @@ reopen_payment_chargeback_reject(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(Levy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -4132,7 +4733,9 @@ reopen_payment_chargeback_accept(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4142,9 +4745,14 @@ reopen_payment_chargeback_accept(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4152,16 +4760,26 @@ reopen_payment_chargeback_accept(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4185,7 +4803,9 @@ reopen_payment_chargeback_skip_stage_accept(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4195,9 +4815,14 @@ reopen_payment_chargeback_skip_stage_accept(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), NextStage = ?chargeback_stage_arbitration(), @@ -4206,16 +4831,26 @@ reopen_payment_chargeback_skip_stage_accept(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(NextStage))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4242,7 +4877,9 @@ reopen_payment_chargeback_accept_new_levy(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), AcceptLevy = ?cash(AcceptLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4252,9 +4889,14 @@ reopen_payment_chargeback_accept_new_levy(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4262,18 +4904,28 @@ reopen_payment_chargeback_accept_new_levy(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(AcceptLevy, Body), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 5, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4299,7 +4951,9 @@ reopen_payment_chargeback_arbitration(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), ReopenArbLevy = ?cash(ReopenArbAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4309,9 +4963,14 @@ reopen_payment_chargeback_arbitration(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4319,17 +4978,27 @@ reopen_payment_chargeback_arbitration(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ReopenArbParams = make_chargeback_reopen_params(ReopenArbLevy), @@ -4337,16 +5006,26 @@ reopen_payment_chargeback_arbitration(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement4 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ), + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) + ), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement5 = hg_accounting:get_balance(SID), @@ -4376,7 +5055,9 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), ReopenArbLevy = ?cash(ReopenArbAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), + {IID, PID, SID, CB} = start_chargeback( + C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) + ), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4386,9 +5067,14 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4396,17 +5082,27 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ReopenArbParams = make_chargeback_reopen_params(ReopenArbLevy), @@ -4414,17 +5110,27 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) + ) ] = next_changes(IID, 5, Client), Settlement4 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), + ?payment_ev( + PID, + ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) + ), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) + ?payment_ev( + PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) + ) ] = next_changes(IID, 4, Client), Settlement5 = hg_accounting:get_balance(SID), Error = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenArbParams, Client), @@ -4446,17 +5152,19 @@ 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 +5173,19 @@ 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 +5209,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) -> @@ -4537,7 +5247,9 @@ payment_refund_idempotency(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), InvoiceID2 = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + _PaymentID2 = execute_payment( + InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client + ), RefundID = <<"1">>, ExternalID = <<"42">>, RefundParams1 = RefundParams0#payproc_InvoicePaymentRefundParams{ @@ -4575,16 +5287,18 @@ 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), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, capture}), Client), + 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 ?invalid_payment_status(?processed()) = @@ -4602,11 +5316,15 @@ payment_refund_success(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(Failure))), - ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(Failure)))) + ?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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), #domain_InvoicePaymentRefund{status = ?refund_succeeded()} = @@ -4619,16 +5337,18 @@ 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), - PaymentParams = make_scenario_payment_params([good, good, fail], {hold, capture}, ?pmt_sys(<<"visa-ref">>)), + 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(), % not finished yet @@ -4647,19 +5367,28 @@ payment_refund_failure(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) + ?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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID, Client), [ - ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?trx_bound(?trx_info(_TrxID))))), - ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure))))), + ?payment_ev( + PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?trx_bound(?trx_info(_TrxID)))) + ), + ?payment_ev( + PaymentID, + ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure)))) + ), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_rollback_started(Failure))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 4, Client), @@ -4670,8 +5399,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,21 +5408,29 @@ payment_refund_success_after_callback(C) -> PartyClient ), % top up merchant account - InvoiceID2 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), - PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), + 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 {URL, GoodForm} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID, UserInteraction, Client + ), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), % create a refund finally RefundParams = make_refund_params(), - ?refund_id(RefundID) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), + ?refund_id(RefundID) = hg_client_invoicing:refund_payment( + InvoiceID, PaymentID, RefundParams, Client + ), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID, Client), ?payment_ev( @@ -4726,15 +5463,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( @@ -4759,11 +5496,15 @@ deadline_doesnt_affect_payment_refund(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) + ?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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), #domain_InvoicePaymentRefund{status = ?refund_succeeded()} = @@ -4773,15 +5514,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{ @@ -4802,11 +5543,15 @@ payment_manual_refund(C) -> [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_created(Refund0, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) + ?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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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(), Fixture = payment_manual_refund_fixture(OriginalRevision), @@ -4824,20 +5569,22 @@ 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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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(_) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams0, Client), @@ -4908,15 +5655,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 +5674,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,18 +5733,20 @@ 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), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( + InvoiceID, PaymentID, RefundParams, Client + ), ?operation_not_permitted() = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), @@ -5026,15 +5775,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,19 +5793,23 @@ 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), - PaymentParams = make_scenario_payment_params([good, good, temp, temp], ?pmt_sys(<<"visa-ref">>)), + 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">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( + InvoiceID, PaymentID, RefundParams1, Client + ), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_payment_process_finish(InvoiceID, PaymentID, Client, 2), @@ -5081,30 +5834,38 @@ 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), - _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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{ reason = <<"42">>, cash = ?cash(5000, <<"RUB">>) }, % 0 - ManualRefundParams = RefundParams#payproc_InvoicePaymentRefundParams{transaction_info = TrxInfo}, - ?refund_id(RefundID0) = hg_client_invoicing:refund_payment_manual(InvoiceID, PaymentID, ManualRefundParams, Client), - PaymentID = await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID0, TrxInfo, Client), + ManualRefundParams = RefundParams#payproc_InvoicePaymentRefundParams{ + transaction_info = TrxInfo + }, + ?refund_id(RefundID0) = hg_client_invoicing:refund_payment_manual( + InvoiceID, PaymentID, ManualRefundParams, Client + ), + PaymentID = await_partial_manual_refund_succeeded( + InvoiceID, PaymentID, RefundID0, TrxInfo, Client + ), % 1 RefundID1 = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), % 2 @@ -5115,7 +5876,9 @@ payment_refund_id_types(C) -> CustomIdManualParams, Client ), - PaymentID = await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID2, TrxInfo, Client), + PaymentID = await_partial_manual_refund_succeeded( + InvoiceID, PaymentID, RefundID2, TrxInfo, Client + ), % 3 CustomIdParams = RefundParams#payproc_InvoicePaymentRefundParams{id = <<"m3">>}, {exception, #base_InvalidRequest{}} = @@ -5130,8 +5893,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 +5903,13 @@ registered_payment_manual_refund_success(C) -> ), %% create balance - InvoiceID1 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 50000, C), - _PaymentID1 = execute_payment(InvoiceID1, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), + 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), @@ -5173,7 +5938,9 @@ payment_hold_double_cancellation(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 10000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertEqual(ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client)), + ?assertEqual( + ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client) + ), Result = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5181,7 +5948,9 @@ payment_hold_double_cancellation(C) -> payment_hold_cancellation_captured(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client + ), ?assertEqual(ok, hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client)), Result = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5203,7 +5972,9 @@ payment_hold_auto_cancellation(C) -> payment_hold_capturing(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client + ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, <<"ok">>, Client). @@ -5211,7 +5982,9 @@ payment_hold_capturing(C) -> payment_hold_double_capturing(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client + ), ?assertEqual(ok, hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client)), Result = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5220,8 +5993,12 @@ payment_hold_double_capturing(C) -> payment_hold_capturing_cancelled(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), - ?assertEqual(ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client)), + PaymentID = process_payment( + InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client + ), + ?assertEqual( + ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client) + ), Result = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5316,7 +6093,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), @@ -5328,7 +6105,9 @@ invalid_permit_partial_capture_in_service(C) -> PaymentID = process_payment(InvoiceID, PaymentParams, Client), Cash = ?cash(10000, <<"RUB">>), Reason = <<"ok">>, - ?operation_not_permitted() = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, Reason, Cash, Client). + ?operation_not_permitted() = hg_client_invoicing:capture_payment( + InvoiceID, PaymentID, Reason, Cash, Client + ). -spec invalid_permit_partial_capture_in_provider(config()) -> _ | no_return(). invalid_permit_partial_capture_in_provider(C) -> @@ -5338,7 +6117,9 @@ invalid_permit_partial_capture_in_provider(C) -> PaymentID = process_payment(InvoiceID, PaymentParams, Client), Cash = ?cash(10000, <<"RUB">>), Reason = <<"ok">>, - ?operation_not_permitted() = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, Reason, Cash, Client). + ?operation_not_permitted() = hg_client_invoicing:capture_payment( + InvoiceID, PaymentID, Reason, Cash, Client + ). -spec payment_hold_auto_capturing(config()) -> _ | no_return(). payment_hold_auto_capturing(C) -> @@ -5348,7 +6129,9 @@ payment_hold_auto_capturing(C) -> PaymentID = start_payment(InvoiceID, PaymentParams, Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), _ = assert_success_post_request(get_post_request(UserInteraction)), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID, UserInteraction, Client + ), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), _ = assert_invalid_post_request(get_post_request(UserInteraction)), PaymentID = await_payment_capture(InvoiceID, PaymentID, ?timeout_reason(), Client). @@ -5358,17 +6141,27 @@ rounding_cashflow_volume(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = 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), 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), - ?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), - ?cash(1, <<"RUB">>) = get_cashflow_volume({system, settlement}, {external, outcome}, CF, CFContext), + 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 + ), + ?cash(1, <<"RUB">>) = get_cashflow_volume( + {system, settlement}, {external, outcome}, CF, CFContext + ), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client). get_cashflow_volume(Source, Destination, CF, CFContext) -> @@ -5379,7 +6172,9 @@ convert_transaction_account(Entity, Context) -> %% --define(repair_set_timer(T), #repair_ComplexAction{timer = {set_timer, #repair_SetTimerAction{timer = T}}}). +-define(repair_set_timer(T), #repair_ComplexAction{ + timer = {set_timer, #repair_SetTimerAction{timer = T}} +}). -define(repair_mark_removal(), #repair_ComplexAction{remove = #repair_RemoveAction{}}). -spec adhoc_repair_working_failed(config()) -> _ | no_return(). @@ -5397,7 +6192,9 @@ adhoc_repair_working_failed(C) -> adhoc_repair_failed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -5407,7 +6204,9 @@ adhoc_repair_failed_succeeded(C) -> ] = next_changes(InvoiceID, 2, Client), % assume no more events here since machine is FUBAR already timeout = next_change(InvoiceID, 2000, Client), - Change = ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), + Change = ?payment_ev( + PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) + ), ok = repair_invoice(InvoiceID, [Change], ?repair_set_timer({timeout, 0}), undefined, Client), Change = next_change(InvoiceID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?processed())) = @@ -5434,7 +6233,9 @@ adhoc_repair_force_removal(C) -> adhoc_repair_invalid_changes_failed(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -5460,7 +6261,9 @@ adhoc_repair_invalid_changes_failed(C) -> {{woody_error, {external, result_unexpected, _}}, _}, repair_invoice(InvoiceID, InvalidChanges2, Client) ), - Change = ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), + Change = ?payment_ev( + PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) + ), ?assertEqual( ok, repair_invoice(InvoiceID, [Change], Client) @@ -5504,7 +6307,9 @@ adhoc_repair_force_invalid_transition(C) -> payment_with_offsite_preauth_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), @@ -5532,7 +6337,9 @@ payment_with_offsite_preauth_success(C) -> payment_with_offsite_preauth_failed(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(3), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), _UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), @@ -5568,17 +6375,23 @@ 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), %% Payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -5593,7 +6406,9 @@ repair_fail_routing_succeeded(C) -> #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, + limit = #domain_TurnoverLimit{ + id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY + }, value = 10000 } ] @@ -5603,13 +6418,17 @@ repair_fail_routing_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, fail_pre_processing, Client), %% Check final status - ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change(InvoiceID, Client), + ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change( + InvoiceID, Client + ), %% Check limits rolled back #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, + limit = #domain_TurnoverLimit{ + id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY + }, value = 0 } ] @@ -5626,17 +6445,23 @@ 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), %% Payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -5651,7 +6476,9 @@ repair_fail_cash_flow_building_succeeded(C) -> #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, + limit = #domain_TurnoverLimit{ + id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY + }, value = 10000 } ] @@ -5661,13 +6488,17 @@ repair_fail_cash_flow_building_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, fail_pre_processing, Client), %% Check final status - ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change(InvoiceID, Client), + ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change( + InvoiceID, Client + ), %% Check limits rolled back #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, + limit = #domain_TurnoverLimit{ + id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY + }, value = 0 } ] @@ -5677,7 +6508,9 @@ repair_fail_cash_flow_building_succeeded(C) -> repair_fail_session_on_processed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -5696,7 +6529,10 @@ repair_fail_session_on_processed_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, {fail_session, Failure}, Client), [ - ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), + ?payment_ev( + PaymentID, + ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) + ), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -5719,7 +6555,10 @@ repair_fail_suspended_session_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, {fail_session, Failure}, Client), [ - ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), + ?payment_ev( + PaymentID, + ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) + ), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -5728,7 +6567,9 @@ repair_fail_suspended_session_succeeded(C) -> repair_complex_second_scenario_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -5745,7 +6586,10 @@ repair_complex_second_scenario_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, Scenarios, Client), [ - ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), + ?payment_ev( + PaymentID, + ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) + ), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -5757,11 +6601,15 @@ repair_fulfill_session_on_refund_succeeded(C) -> PaymentParams = make_scenario_payment_params([good, good, error], ?pmt_sys(<<"visa-ref">>)), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), RefundParams1 = make_refund_params(1000, <<"RUB">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( + InvoiceID, PaymentID, RefundParams1, Client + ), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), timeout = next_change(InvoiceID, 2000, Client), - ok = repair_invoice_with_scenario(InvoiceID, {fulfill_session, ?trx_info(PaymentID, #{})}, Client), + ok = repair_invoice_with_scenario( + InvoiceID, {fulfill_session, ?trx_info(PaymentID, #{})}, Client + ), PaymentID = await_refund_payment_process_finish(InvoiceID, PaymentID, Client), ?payment_state( ?payment_w_status(?captured()), @@ -5775,13 +6623,20 @@ repair_fail_session_on_refund_succeeded(C) -> PaymentParams = make_scenario_payment_params([good, good, error], ?pmt_sys(<<"visa-ref">>)), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), RefundParams1 = make_refund_params(1000, <<"RUB">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( + InvoiceID, PaymentID, RefundParams1, Client + ), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), timeout = next_change(InvoiceID, 2000, Client), - ok = repair_invoice_with_scenario(InvoiceID, {fail_session, construct_authorization_failure()}, Client), + ok = repair_invoice_with_scenario( + InvoiceID, {fail_session, construct_authorization_failure()}, Client + ), [ - ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure))))), + ?payment_ev( + PaymentID, + ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure)))) + ), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_rollback_started(Failure))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 3, Client), @@ -5794,7 +6649,9 @@ repair_fail_session_on_refund_succeeded(C) -> repair_fulfill_session_on_processed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) = @@ -5853,7 +6710,9 @@ repair_fulfill_session_on_captured_succeeded(C) -> repair_fulfill_session_with_trx_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) = @@ -5890,14 +6749,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 +6795,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 +6808,109 @@ 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 +6928,22 @@ 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 +6952,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 +6963,15 @@ 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 +6980,21 @@ 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 +7003,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 +7014,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 +7031,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. @@ -6190,8 +7122,12 @@ payment_cascade_success_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 2))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))) + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 2)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1)) + ) ]} ) ]. @@ -6201,14 +7137,18 @@ 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) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( + InvoiceParams, Client + ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -6220,7 +7160,9 @@ payment_cascade_success(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -6236,7 +7178,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), @@ -6247,7 +7193,10 @@ payment_cascade_success(C) -> ?payment_ev(PaymentID, ?cash_flow_changed(_CashFlow2)) ] = next_changes(InvoiceID, 2, Client), - ?assertMatch(#domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))}, Route2), + ?assertMatch( + #domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))}, + Route2 + ), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(TrxID2)))), @@ -6277,7 +7226,11 @@ payment_cascade_success(C) -> ), %% At the end of this scenario limit must be accounted only once. _ = hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount + Amount, PaymentFinal, Invoice + ?LIMIT_ID4, + configured_limit_version(?LIMIT_ID4, C), + InitialAccountedAmount + Amount, + PaymentFinal, + Invoice ), #payproc_InvoicePaymentExplanation{ explained_routes = [ @@ -6351,8 +7304,13 @@ payment_cascade_success_w_refund_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID + 1))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID))) + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID + 1)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID)) + ) ]} ) ]. @@ -6361,10 +7319,16 @@ 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), - {PaymentID, [_FailedRoute, _UsedRoute]} = execute_payment_w_cascade(InvoiceID, PaymentParams, Client, 1), + 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()} = @@ -6493,13 +7457,27 @@ payment_big_cascade_success_fixture(Revision, _C) -> <<"Big Main with cascading">>, %% 7 route candidates, 6 to fail {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 2))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 3))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 4))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 5))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 6))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 7))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1))) + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 2)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 3)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 4)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 5)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 6)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 7)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1)) + ) ]} ) ]). @@ -6574,8 +7552,14 @@ payment_cascade_limit_overflow_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 2))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 1))) + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 2)) + ), + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 1)) + ) ]} ) ]. @@ -6585,14 +7569,18 @@ 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) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( + InvoiceParams, Client + ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -6604,7 +7592,9 @@ payment_cascade_limit_overflow(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -6620,7 +7610,9 @@ payment_cascade_limit_overflow(C) -> ] = next_changes(InvoiceID, 4, Client), {Route1, _CashFlow1, _TrxID1, Failure1} = await_cascade_triggering(InvoiceID, PaymentID, Client), - ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> + ok + end), %% And again but no route found [ ?payment_ev(PaymentID, ?route_changed(Route2, Candidates2)), @@ -6631,7 +7623,9 @@ payment_cascade_limit_overflow(C) -> ?assertNotEqual(Route1, Route2), ?assertNot(lists:member(Route1, Candidates2)), %% No route found and so we pass original failure from previous attempt - ok = payproc_errors:match('PaymentFailure', Failure2, fun({authorization_failed, {unknown, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun({authorization_failed, {unknown, _}}) -> + ok + end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(FinalPayment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -6639,7 +7633,11 @@ payment_cascade_limit_overflow(C) -> ?invoice_status_changed(?invoice_cancelled(<<"overdue">>)) = next_change(InvoiceID, Client), %% At the end of this scenario limit must not be changed. hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount, FinalPayment, Invoice + ?LIMIT_ID4, + configured_limit_version(?LIMIT_ID4, C), + InitialAccountedAmount, + FinalPayment, + Invoice ). -spec payment_big_cascade_success(config()) -> test_return(). @@ -6647,14 +7645,18 @@ 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) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( + InvoiceParams, Client + ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -6666,7 +7668,9 @@ payment_big_cascade_success(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( + InvoiceID, PaymentParams, Client + ), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -6703,7 +7707,10 @@ 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), @@ -6729,7 +7736,11 @@ payment_big_cascade_success(C) -> ), %% At the end of this scenario limit must be accounted only once. hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount + Amount, PaymentFinal, Invoice + ?LIMIT_ID4, + configured_limit_version(?LIMIT_ID4, C), + InitialAccountedAmount + Amount, + PaymentFinal, + Invoice ). payment_cascade_fail_provider_error_fixture_pre(Revision, _C) -> @@ -6828,7 +7839,9 @@ payment_cascade_fail_provider_error(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -6917,7 +7930,9 @@ payment_cascade_fail_ui_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID)), <<"1 fail, 2 with UI, 3 never reached">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID + I))) + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID + I)) + ) || I <- lists:reverse(lists:seq(1, 3)) ]} ) @@ -6928,7 +7943,9 @@ payment_cascade_fail_ui(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + preauth_3ds, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -6939,7 +7956,9 @@ payment_cascade_fail_ui(C) -> ] = next_changes(InvoiceID, 4, Client), {_Route1, _CashFlow1, _TrxID1, Failure1} = await_cascade_triggering(InvoiceID, PaymentID, Client), - ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> + ok + end), %% And again with UI [ ?payment_ev(PaymentID, ?route_changed(_Route2)), @@ -6948,7 +7967,9 @@ payment_cascade_fail_ui(C) -> UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), {URL, Form} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, Form}), - ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), + ok = await_payment_process_interaction_completion( + InvoiceID, PaymentID, UserInteraction, Client + ), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(_TrxID2)))), ?payment_ev( @@ -6960,7 +7981,11 @@ payment_cascade_fail_ui(C) -> next_changes(InvoiceID, 3, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure2}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure2, fun({preauthorization_failed, {unknown, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun( + {preauthorization_failed, {unknown, _}} + ) -> + ok + end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -7037,8 +8062,14 @@ payment_cascade_fail_wo_route_candidates_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID)), <<"2 routes with failing providers">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 1))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 2))) + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 1)) + ), + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 2)) + ) ]} ) ]). @@ -7101,7 +8132,9 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> data = #domain_Terminal{ name = <<"Brominal 1">>, description = <<"Brominal 1">>, - provider_ref = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) + provider_ref = ?prv( + ?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1) + ) } }}, {terminal, #domain_TerminalObject{ @@ -7109,7 +8142,9 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> data = #domain_Terminal{ name = <<"Not-Brominal">>, description = <<"Not-Brominal">>, - provider_ref = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) + provider_ref = ?prv( + ?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2) + ) } }}, hg_ct_fixture:construct_payment_routing_ruleset( @@ -7117,10 +8152,12 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> <<"Main with cascading">>, {candidates, [ ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) ), ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) ) ]} ) @@ -7131,7 +8168,9 @@ payment_cascade_fail_wo_available_attempt_limit(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7144,7 +8183,11 @@ payment_cascade_fail_wo_available_attempt_limit(C) -> await_cascade_triggering(InvoiceID, PaymentID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure, fun({preauthorization_failed, {card_blocked, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure, fun( + {preauthorization_failed, {card_blocked, _}} + ) -> + ok + end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -7210,8 +8253,12 @@ payment_cascade_failures_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 1))), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 2))) + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 1)) + ), + ?candidate( + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 2)) + ) ]} ) ]. @@ -7221,7 +8268,9 @@ payment_cascade_failures(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7232,13 +8281,21 @@ payment_cascade_failures(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), %% And again {_Route2, _CashFlow2, _TrxID2, Failure2} = await_cascade_triggering(InvoiceID, PaymentID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure2}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure2, fun({preauthorization_failed, {card_blocked, _}}) -> ok end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun( + {preauthorization_failed, {card_blocked, _}} + ) -> + ok + end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -7310,7 +8367,10 @@ payment_cascade_deadline_failures_fixture(Revision, _C) -> ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 1)), 2000 ), - ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 2))) + ?candidate( + {constant, true}, + ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 2)) + ) ]} ) ]. @@ -7320,9 +8380,13 @@ payment_cascade_deadline_failures(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + no_preauth, ?pmt_sys(<<"visa-ref">>) + ), PaymentParams = (make_payment_params(PaymentTool, Session, instant))#payproc_InvoicePaymentParams{ - processing_deadline = hg_datetime:add_time_span(#base_TimeSpan{seconds = 2}, hg_datetime:format_now()) + processing_deadline = hg_datetime:add_time_span( + #base_TimeSpan{seconds = 2}, hg_datetime:format_now() + ) }, hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7333,7 +8397,11 @@ payment_cascade_deadline_failures(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), %% And again ?payment_ev(PaymentID, ?route_changed(_Route2)) = next_change(InvoiceID, Client), @@ -7359,12 +8427,16 @@ 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( @@ -7379,8 +8451,12 @@ payment_tool_contact_info_passed_to_provider(C) -> make_payment_params_with_contact_info_assertion(PmtSys) -> String = <<"STRING">>, - ContactInfo = ?contact_info(String, String, String, String, String, String, String, String, String, String, String), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool({assert_contact_info, ContactInfo}, PmtSys), + ContactInfo = ?contact_info( + String, String, String, String, String, String, String, String, String, String, String + ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( + {assert_contact_info, ContactInfo}, PmtSys + ), #payproc_InvoicePaymentParams{ payer = {payment_resource, #payproc_PaymentResourcePayerParams{ @@ -7450,12 +8526,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. @@ -7622,7 +8700,9 @@ repair_invoice(InvoiceID, Changes, Action, Params, Client) -> hg_client_invoicing:repair(InvoiceID, Changes, Action, Params, Client). create_repair_scenario(fail_pre_processing) -> - Failure = payproc_errors:construct('PaymentFailure', {no_route_found, {unknown, ?err_gen_failure()}}), + Failure = payproc_errors:construct( + 'PaymentFailure', {no_route_found, {unknown, ?err_gen_failure()}} + ), {'fail_pre_processing', #'payproc_InvoiceRepairFailPreProcessing'{failure = Failure}}; create_repair_scenario(skip_inspector) -> {'skip_inspector', #'payproc_InvoiceRepairSkipInspector'{risk_score = low}}; @@ -7633,7 +8713,9 @@ create_repair_scenario(fulfill_session) -> create_repair_scenario({fulfill_session, Trx}) -> {'fulfill_session', #'payproc_InvoiceRepairFulfillSession'{trx = Trx}}; create_repair_scenario(Scenarios) when is_list(Scenarios) -> - {'complex', #'payproc_InvoiceRepairComplex'{scenarios = [create_repair_scenario(S) || S <- Scenarios]}}. + {'complex', #'payproc_InvoiceRepairComplex'{ + scenarios = [create_repair_scenario(S) || S <- Scenarios] + }}. repair_invoice_with_scenario(InvoiceID, Scenario, Client) -> hg_client_invoicing:repair_scenario(InvoiceID, create_repair_scenario(Scenario), Client). @@ -7641,11 +8723,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). @@ -7747,18 +8829,25 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client) -> hg_invoice_helper:await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client). await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client) -> - hg_invoice_helper:await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client). + hg_invoice_helper:await_payment_capture_finish( + InvoiceID, PaymentID, Reason, Cost, Cart, Client + ). await_payment_cancel(InvoiceID, PaymentID, Reason, Client) -> [ ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_started())), - ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))), + ?payment_ev( + PaymentID, + ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded())) + ), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_changes(InvoiceID, 3, Client), PaymentID. await_payment_process_timeout(InvoiceID, PaymentID, Client) -> - {failed, PaymentID, ?operation_timeout()} = await_payment_process_failure(InvoiceID, PaymentID, Client), + {failed, PaymentID, ?operation_timeout()} = await_payment_process_failure( + InvoiceID, PaymentID, Client + ), PaymentID. await_payment_process_failure(InvoiceID, PaymentID, Client) -> @@ -7786,7 +8875,10 @@ await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID, TrxInfo, C ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_created(_Refund, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_started()))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?trx_bound(TrxInfo)))), - ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), + ?payment_ev( + PaymentID, + ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) + ), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_status_changed(?refund_succeeded()))) ] = next_changes(InvoiceID, 5, Client), PaymentID. @@ -7810,7 +8902,10 @@ await_refund_payment_process_finish(InvoiceID, PaymentID, Client, Restarts) -> PaymentID = await_sessions_restarts(PaymentID, ?refunded(), InvoiceID, Client, Restarts), [ ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?trx_bound(_)))), - ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), + ?payment_ev( + PaymentID, + ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) + ), ?payment_ev(PaymentID, ?refund_ev(_, ?refund_status_changed(?refund_succeeded()))) ] = next_changes(InvoiceID, 3, Client), PaymentID. @@ -7819,7 +8914,10 @@ await_refund_payment_complete(InvoiceID, PaymentID, Client) -> PaymentID = await_sessions_restarts(PaymentID, ?refunded(), InvoiceID, Client, 0), [ ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?trx_bound(_)))), - ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), + ?payment_ev( + PaymentID, + ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) + ), ?payment_ev(PaymentID, ?refund_ev(_, ?refund_status_changed(?refund_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?refunded())) ] = next_changes(InvoiceID, 4, Client), @@ -7827,9 +8925,13 @@ await_refund_payment_complete(InvoiceID, PaymentID, Client) -> await_sessions_restarts(PaymentID, _Target, _InvoiceID, _Client, 0) -> PaymentID; -await_sessions_restarts(PaymentID, ?refunded() = Target, InvoiceID, Client, Restarts) when Restarts > 0 -> +await_sessions_restarts(PaymentID, ?refunded() = Target, InvoiceID, Client, Restarts) when + Restarts > 0 +-> [ - ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_finished(?session_failed(_))))), + ?payment_ev( + PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_finished(?session_failed(_)))) + ), ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_started()))) ] = next_changes(InvoiceID, 2, Client), await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts - 1); @@ -7897,7 +8999,9 @@ execute_payment(InvoiceID, Params, Client) -> hg_invoice_helper:execute_payment(InvoiceID, Params, Client). execute_payment_w_cascade(InvoiceID, Params, Client, CascadeCount) when CascadeCount > 0 -> - #payproc_InvoicePayment{payment = _Payment} = hg_client_invoicing:start_payment(InvoiceID, Params, Client), + #payproc_InvoicePayment{payment = _Payment} = hg_client_invoicing:start_payment( + InvoiceID, Params, Client + ), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -7925,17 +9029,25 @@ execute_payment_w_cascade(InvoiceID, Params, Client, CascadeCount) when CascadeC execute_payment_adjustment(InvoiceID, PaymentID, Params, Client) -> ?adjustment(AdjustmentID, ?adjustment_pending()) = - Adjustment = hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, Params, Client), + Adjustment = hg_client_invoicing:create_payment_adjustment( + InvoiceID, PaymentID, Params, Client + ), [ ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), ?payment_ev( - PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) + ), + ?payment_ev( + PaymentID, + ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) ) ] = next_changes(InvoiceID, 3, Client), AdjustmentID. -execute_payment_refund(InvoiceID, PaymentID, #payproc_InvoicePaymentRefundParams{cash = undefined} = Params, Client) -> +execute_payment_refund( + InvoiceID, PaymentID, #payproc_InvoicePaymentRefundParams{cash = undefined} = Params, Client +) -> execute_payment_refund_complete(InvoiceID, PaymentID, Params, Client); execute_payment_refund(InvoiceID, PaymentID, Params, Client) -> ?refund_id(RefundID) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, Params, Client), @@ -7945,12 +9057,17 @@ execute_payment_refund(InvoiceID, PaymentID, Params, Client) -> RefundID. execute_payment_manual_refund(InvoiceID, PaymentID, Params, Client) -> - ?refund_id(RefundID) = hg_client_invoicing:refund_payment_manual(InvoiceID, PaymentID, Params, Client), + ?refund_id(RefundID) = hg_client_invoicing:refund_payment_manual( + InvoiceID, PaymentID, Params, Client + ), [ ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_created(_Refund, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_started()))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?trx_bound(TrxInfo)))), - ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))) + ?payment_ev( + PaymentID, + ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) + ) ] = next_changes(InvoiceID, 4, Client), _ = await_refund_succeeded(InvoiceID, PaymentID, Client), RefundID. @@ -7971,13 +9088,20 @@ execute_payment_chargeback(InvoiceID, PaymentID, Params, Client) -> ?payment_ev(PaymentID, ?chargeback_ev(ChargebackID, ?chargeback_cash_flow_changed(_))) ] = next_changes(InvoiceID, 2, Client), AcceptParams = make_chargeback_accept_params(), - ok = hg_client_invoicing:accept_chargeback(InvoiceID, PaymentID, ChargebackID, AcceptParams, Client), + ok = hg_client_invoicing:accept_chargeback( + InvoiceID, PaymentID, ChargebackID, AcceptParams, Client + ), [ ?payment_ev( PaymentID, - ?chargeback_ev(ChargebackID, ?chargeback_target_status_changed(?chargeback_status_accepted())) + ?chargeback_ev( + ChargebackID, ?chargeback_target_status_changed(?chargeback_status_accepted()) + ) + ), + ?payment_ev( + PaymentID, + ?chargeback_ev(ChargebackID, ?chargeback_status_changed(?chargeback_status_accepted())) ), - ?payment_ev(PaymentID, ?chargeback_ev(ChargebackID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PaymentID, ?payment_status_changed(?charged_back())) ] = next_changes(InvoiceID, 3, Client), ChargebackID. @@ -7986,7 +9110,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), @@ -7996,7 +9120,9 @@ payment_risk_score_check(Cat, C, PmtSys) -> InvoiceID1 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), % Invoice PaymentParams = make_payment_params(PmtSys), - ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment(InvoiceID1, PaymentParams, Client), + ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment( + InvoiceID1, PaymentParams, Client + ), ?payment_ev(PaymentID1, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID1, Client), % default low risk score... @@ -8038,11 +9164,15 @@ 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{ @@ -8056,7 +9186,10 @@ construct_domain_fixture() -> ?pmt(payment_terminal, ?pmt_srv(<<"euroset-ref">>)), ?pmt(digital_wallet, ?pmt_srv(<<"qiwi-ref">>)), ?pmt(bank_card, ?bank_card_no_cvv(<<"visa-ref">>)), - ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)), + ?pmt( + bank_card, + ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>) + ), ?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>)), ?pmt(mobile, ?mob(<<"mts-ref">>)) ])} @@ -8069,7 +9202,8 @@ construct_domain_fixture() -> {condition, {payment_tool, {crypto_currency, #domain_CryptoCurrencyCondition{ - definition = {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} + definition = + {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} }}}}, then_ = {value, @@ -8280,7 +9414,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"mastercard-ref">>) + payment_system_is = ?pmt_sys( + <<"mastercard-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(120)} @@ -8352,14 +9488,22 @@ construct_domain_fixture() -> hg_ct_fixture:construct_payment_method(?pmt(digital_wallet, ?pmt_srv(<<"qiwi-ref">>))), hg_ct_fixture:construct_payment_method(?pmt(payment_terminal, ?pmt_srv(<<"euroset-ref">>))), hg_ct_fixture:construct_payment_method(?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>))), - hg_ct_fixture:construct_payment_method(?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>))), + hg_ct_fixture:construct_payment_method( + ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)) + ), hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"low">>}), - hg_ct_fixture:construct_inspector(?insp(2), <<"Skipper">>, ?prx(2), #{<<"risk_score">> => <<"high">>}), - hg_ct_fixture:construct_inspector(?insp(3), <<"Fatalist">>, ?prx(2), #{<<"risk_score">> => <<"fatal">>}), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ + <<"risk_score">> => <<"low">> + }), + hg_ct_fixture:construct_inspector(?insp(2), <<"Skipper">>, ?prx(2), #{ + <<"risk_score">> => <<"high">> + }), + hg_ct_fixture:construct_inspector(?insp(3), <<"Fatalist">>, ?prx(2), #{ + <<"risk_score">> => <<"fatal">> + }), hg_ct_fixture:construct_inspector( ?insp(4), <<"Offliner">>, @@ -8407,17 +9551,20 @@ 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)) @@ -8447,7 +9594,9 @@ construct_domain_fixture() -> ?candidate({constant, true}, ?trm(7)) ]} ), - hg_ct_fixture:construct_payment_routing_ruleset(?ruleset(3), <<"Prohibitions">>, {candidates, []}), + hg_ct_fixture:construct_payment_routing_ruleset( + ?ruleset(3), <<"Prohibitions">>, {candidates, []} + ), {payment_institution, #domain_PaymentInstitutionObject{ ref = ?pinst(1), @@ -8593,7 +9742,7 @@ construct_domain_fixture() -> if_ = {condition, {party, #domain_PartyCondition{ - id = ?PARTYID_EXTERNAL + party_ref = ?PARTY_CONFIG_REF_EXTERNAL }}}, then_ = {value, ?eas(2)} }, @@ -8661,7 +9810,10 @@ construct_domain_fixture() -> ?pmt(bank_card, ?bank_card(<<"jcb-ref">>)), ?pmt(bank_card, ?bank_card_no_cvv(<<"visa-ref">>)), ?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>)), - ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)) + ?pmt( + bank_card, + ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>) + ) ])}, cash_limit = {value, @@ -8676,7 +9828,8 @@ construct_domain_fixture() -> {condition, {payment_tool, {digital_wallet, #domain_DigitalWalletCondition{ - definition = {payment_service_is, ?pmt_srv(<<"qiwi-ref">>)} + definition = + {payment_service_is, ?pmt_srv(<<"qiwi-ref">>)} }}}}, then_ = {value, [ @@ -8699,7 +9852,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = @@ -8723,7 +9878,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"mastercard-ref">>) + payment_system_is = ?pmt_sys( + <<"mastercard-ref">> + ) }} }}}}, then_ = @@ -8747,7 +9904,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"jcb-ref">>) + payment_system_is = ?pmt_sys( + <<"jcb-ref">> + ) }} }}}}, then_ = @@ -8771,8 +9930,12 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>), - token_service_is = ?token_srv(<<"applepay-ref">>), + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ), + token_service_is = ?token_srv( + <<"applepay-ref">> + ), tokenization_method_is = dpan }} }}}}, @@ -8795,7 +9958,8 @@ construct_domain_fixture() -> {condition, {payment_tool, {crypto_currency, #domain_CryptoCurrencyCondition{ - definition = {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} + definition = + {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} }}}}, then_ = {value, [ @@ -8822,7 +9986,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -8943,7 +10109,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(5)} @@ -8955,7 +10123,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"mastercard-ref">>) + payment_system_is = ?pmt_sys( + <<"mastercard-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(120)} @@ -9276,7 +10446,9 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -9413,13 +10585,21 @@ construct_domain_fixture() -> {terminal, ?terminal_obj(?trm(14), ?prv(7))}, hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), - hg_ct_fixture:construct_payment_system(?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">>), + hg_ct_fixture:construct_payment_system( + ?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">> + ), hg_ct_fixture:construct_payment_system(?pmt_sys(<<"jcb-ref">>), <<"jcb payment system">>), hg_ct_fixture:construct_mobile_operator(?mob(<<"mts-ref">>), <<"mts mobile operator">>), - hg_ct_fixture:construct_payment_service(?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">>), - hg_ct_fixture:construct_payment_service(?pmt_srv(<<"euroset-ref">>), <<"euroset payment service">>), + hg_ct_fixture:construct_payment_service( + ?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">> + ), + hg_ct_fixture:construct_payment_service( + ?pmt_srv(<<"euroset-ref">>), <<"euroset payment service">> + ), hg_ct_fixture:construct_crypto_currency(?crypta(<<"bitcoin-ref">>), <<"bitcoin currency">>), - hg_ct_fixture:construct_tokenized_service(?token_srv(<<"applepay-ref">>), <<"applepay tokenized service">>) + hg_ct_fixture:construct_tokenized_service( + ?token_srv(<<"applepay-ref">>), <<"applepay tokenized service">> + ) ]. construct_term_set_for_refund_eligibility_time(Seconds) -> @@ -9534,7 +10714,9 @@ get_payment_adjustment_fixture(Revision) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(10)} @@ -9684,17 +10866,23 @@ get_cashflow_rounding_fixture(Revision, _C) -> ?cfpost( {provider, settlement}, {merchant, settlement}, - ?share_with_rounding_method(1, 200000, operation_amount, round_half_towards_zero) + ?share_with_rounding_method( + 1, 200000, operation_amount, round_half_towards_zero + ) ), ?cfpost( {system, settlement}, {provider, settlement}, - ?share_with_rounding_method(1, 200000, operation_amount, round_half_away_from_zero) + ?share_with_rounding_method( + 1, 200000, operation_amount, round_half_away_from_zero + ) ), ?cfpost( {system, settlement}, {system, subagent}, - ?share_with_rounding_method(1, 200000, operation_amount, round_half_away_from_zero) + ?share_with_rounding_method( + 1, 200000, operation_amount, round_half_away_from_zero + ) ), ?cfpost( {system, settlement}, @@ -10049,7 +11237,9 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = @@ -10073,7 +11263,9 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = @@ -10119,7 +11311,9 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys(<<"visa-ref">>) + payment_system_is = ?pmt_sys( + <<"visa-ref">> + ) }} }}}}, then_ = {value, ?hold_lifetime(12)} diff --git a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl index 5524a7e1..1e03a3ea 100644 --- a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl +++ b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl @@ -34,8 +34,10 @@ -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 +93,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 +106,7 @@ init_per_suite(C) -> {apps, Apps}, {suite_test_sup, SupPid}, {party_client, PartyClient}, - {party_id, PartyID} + {party_config_ref, PartyConfigRef} | C ]. @@ -171,9 +173,18 @@ mock_dominant(SupPid) -> _ = hg_mock_helper:mock_dominant( [ {'RepositoryClient', fun - ('CheckoutObject', {{version, ?routing_with_fail_rate_domain_revision = Version}, ObjectRef}) -> + ( + 'CheckoutObject', + {{version, ?routing_with_fail_rate_domain_revision = Version}, ObjectRef} + ) -> Getter(Version, ObjectRef, RoutingWithFailRateDomain); - ('CheckoutObject', {{version, ?routing_with_risk_coverage_set_domain_revision = Version}, ObjectRef}) -> + ( + 'CheckoutObject', + { + {version, ?routing_with_risk_coverage_set_domain_revision = Version}, + ObjectRef + } + ) -> Getter(Version, ObjectRef, RoutingWithRiskCoverageSetDomain); ('CheckoutObject', {{version, Version}, ObjectRef}) -> Getter(Version, ObjectRef, Domain) @@ -224,7 +235,9 @@ 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{ @@ -247,8 +260,22 @@ mock_party_management(SupPid) -> 0, ?pin([currency, payment_tool, email, card_token, client_ip]) ), - ?candidate(<<"">>, {constant, true}, ?trm(2), 0, 0, ?pin([currency, payment_tool])), - ?candidate(<<"">>, {constant, true}, ?trm(3), 0, 0, ?pin([currency, payment_tool])) + ?candidate( + <<"">>, + {constant, true}, + ?trm(2), + 0, + 0, + ?pin([currency, payment_tool]) + ), + ?candidate( + <<"">>, + {constant, true}, + ?trm(3), + 0, + 0, + ?pin([currency, payment_tool]) + ) ]} }}; ('ComputeRoutingRuleset', {?ruleset(2), DomainRevision, _}) when @@ -311,7 +338,10 @@ mock_party_management(SupPid) -> name = <<"No prohibition: all candidate is allowed">>, decisions = {candidates, []} }}; - ('ComputeProviderTerminalTerms', {?prv(2), _, ?base_routing_rule_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(2), _, ?base_routing_rule_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ categories = @@ -327,7 +357,10 @@ mock_party_management(SupPid) -> ])} } }}; - ('ComputeProviderTerminalTerms', {?prv(3), _, ?base_routing_rule_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(3), _, ?base_routing_rule_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ payment_methods = @@ -343,26 +376,38 @@ mock_party_management(SupPid) -> ])} } }}; - ('ComputeProviderTerminalTerms', {?prv(4), _, ?base_routing_rule_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(4), _, ?base_routing_rule_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ allow = {constant, false} } }}; - ('ComputeProviderTerminalTerms', {?prv(7), _, ?base_routing_rule_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(7), _, ?base_routing_rule_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ allow = {constant, true}, global_allow = {constant, false} } }}; - ('ComputeProviderTerminalTerms', {?prv(1), _, ?routing_with_risk_coverage_set_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(1), _, ?routing_with_risk_coverage_set_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ risk_coverage = {value, low} } }}; - ('ComputeProviderTerminalTerms', {?prv(2), _, ?routing_with_risk_coverage_set_domain_revision, _}) -> + ( + 'ComputeProviderTerminalTerms', + {?prv(2), _, ?routing_with_risk_coverage_set_domain_revision, _} + ) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ risk_coverage = {value, high} @@ -451,13 +496,14 @@ mock_fault_detector(SupPid) -> -spec no_route_found_for_payment(config()) -> test_return(). no_route_found_for_payment(_C) -> Currency0 = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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 }, @@ -509,13 +555,14 @@ no_route_found_for_payment(_C) -> -spec gather_route_success(config()) -> test_return(). gather_route_success(_C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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 +603,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 +646,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 }, @@ -612,13 +659,15 @@ empty_candidate_ok(_C) -> }, ?assertMatch( {ok, {[], []}}, - unwrap_routing_context(hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx)) + unwrap_routing_context( + hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx) + ) ). -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 }, @@ -627,12 +676,17 @@ ruleset_misconfig(_C) -> Ctx = #{ currency => ?cur(<<"RUB">>), - payment_tool => {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + payment_tool => + {payment_terminal, #domain_PaymentTerminal{ + payment_service = ?pmt_srv(<<"euroset-ref">>) + }}, client_ip => undefined }, ?assertMatch( {misconfiguration, {routing_decisions, {delegates, []}}}, - hg_routing_ctx:error(hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx)) + hg_routing_ctx:error( + hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx) + ) ). -spec routes_selected_for_low_risk_score(config()) -> test_return(). @@ -645,13 +699,14 @@ routes_selected_for_high_risk_score(C) -> routes_selected_with_risk_score(_C, RiskScore, ProviderRefs) -> Currency = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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 }, @@ -705,18 +760,20 @@ empty_terms_allow_test(_C) -> -spec not_reduced_terms_allow_test(config()) -> test_return(). not_reduced_terms_allow_test(_C) -> - Error = {'Misconfiguration', {'Could not reduce predicate to a value', {allow, {all_of, [{constant, false}]}}}}, + Error = + {'Misconfiguration', {'Could not reduce predicate to a value', {allow, {all_of, [{constant, false}]}}}}, do_gather_routes(?not_reduced_allow_revision, undefined, [{?prv(6), ?trm(6), Error}]). do_gather_routes(Revision, ExpectedRouteTerminal, ExpectedRejectedRoutes) -> Currency = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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 }, @@ -745,18 +802,23 @@ do_gather_routes(Revision, ExpectedRouteTerminal, ExpectedRejectedRoutes) -> terminal_priority_for_shop(C) -> Route1 = hg_route:new(?prv(11), ?trm(11), 0, 10), Route2 = hg_route:new(?prv(12), ?trm(12), 0, 10), - ?assertMatch({Route1, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_1, C)), - ?assertMatch({Route2, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_2, C)). + ?assertMatch( + {Route1, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_1, C) + ), + ?assertMatch( + {Route2, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_2, C) + ). terminal_priority_for_shop(ShopID, _C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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 }, @@ -775,13 +837,14 @@ terminal_priority_for_shop(ShopID, _C) -> -spec gather_pinned_route(config()) -> test_return(). gather_pinned_route(_C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = + {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), 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, @@ -825,7 +888,9 @@ choose_route_w_override(_C) -> } = hg_routing:choose_route(Routes), %% with overrides - Route3WithOV = hg_route:new(?prv(3), ?trm(3), 0, 1000, #{}, #domain_RouteFaultDetectorOverrides{enabled = true}), + Route3WithOV = hg_route:new( + ?prv(3), ?trm(3), 0, 1000, #{}, #domain_RouteFaultDetectorOverrides{enabled = true} + ), RoutesWithOV = [Route1, Route2, Route3WithOV], {Route3WithOV, _} = hg_routing:choose_route(RoutesWithOV). @@ -860,9 +925,12 @@ routing_with_risk_score_fixture(Domain, AddRiskScore) -> construct_domain_fixture() -> #{ - {provider, ?prv(1)} => {provider, ?provider_obj(?prv(1), #domain_ProvisionTermSet{}, undefined)}, - {provider, ?prv(2)} => {provider, ?provider_obj(?prv(2), #domain_ProvisionTermSet{}, ?fd_overrides(undefined))}, - {provider, ?prv(3)} => {provider, ?provider_obj(?prv(3), #domain_ProvisionTermSet{}, ?fd_overrides(true))}, + {provider, ?prv(1)} => + {provider, ?provider_obj(?prv(1), #domain_ProvisionTermSet{}, undefined)}, + {provider, ?prv(2)} => + {provider, ?provider_obj(?prv(2), #domain_ProvisionTermSet{}, ?fd_overrides(undefined))}, + {provider, ?prv(3)} => + {provider, ?provider_obj(?prv(3), #domain_ProvisionTermSet{}, ?fd_overrides(true))}, {provider, ?prv(4)} => {provider, ?provider_obj(?prv(4), #domain_ProvisionTermSet{})}, {provider, ?prv(5)} => {provider, ?provider_obj(?prv(5), #domain_ProvisionTermSet{})}, {provider, ?prv(6)} => {provider, ?provider_obj(?prv(6), #domain_ProvisionTermSet{})}, @@ -912,4 +980,6 @@ maybe_set_risk_coverage(true, V) -> {value, V}. unwrap_routing_context(RoutingCtx) -> - {ok, {hg_routing_ctx:considered_candidates(RoutingCtx), hg_routing_ctx:rejected_routes(RoutingCtx)}}. + {ok, { + hg_routing_ctx:considered_candidates(RoutingCtx), hg_routing_ctx:rejected_routes(RoutingCtx) + }}. diff --git a/apps/routing/src/hg_routing_explanation.erl b/apps/routing/src/hg_routing_explanation.erl index 8f6ff7c2..3aadc334 100644 --- a/apps/routing/src/hg_routing_explanation.erl +++ b/apps/routing/src/hg_routing_explanation.erl @@ -35,7 +35,9 @@ get_explanation( %% If there's no routes even tried, then no explanation can be provided throw(#payproc_RouteNotChosen{}); [Route | AttemptedRoutes] -> - CandidateRoutesWithoutChosenRoute = exclude_chosen_route_from_candidates(CandidateRoutes, Route), + CandidateRoutesWithoutChosenRoute = exclude_chosen_route_from_candidates( + CandidateRoutes, Route + ), ChosenRWC = make_route_with_context(Route, RouteScores, RouteLimits), AttemptedExplanation = maybe_explain_attempted_routes( AttemptedRoutes, RouteScores, RouteLimits @@ -79,7 +81,9 @@ maybe_explain_attempted_routes([AttemptedRoute | AttemptedRoutes], RouteScores, maybe_explain_candidate_routes([], _RouteScores, _RouteLimits, _ChosenRWC) -> []; -maybe_explain_candidate_routes([CandidateRoute | CandidateRoutes], RouteScores, RouteLimits, ChosenRWC) -> +maybe_explain_candidate_routes( + [CandidateRoute | CandidateRoutes], RouteScores, RouteLimits, ChosenRWC +) -> RouteWithContext = make_route_with_context(CandidateRoute, RouteScores, RouteLimits), [ route_explanation(candidate, RouteWithContext, ChosenRWC) @@ -148,7 +152,8 @@ candidate_rejection_explanation( #{scores := RouteScores, limits := RouteLimits}, #{scores := ChosenScores} ) when RouteScores =:= ChosenScores -> - IfEmpty = <<"This route has the same score as the chosen route, but wasn't chosen due to order in ruleset.">>, + IfEmpty = + <<"This route has the same score as the chosen route, but wasn't chosen due to order in ruleset.">>, check_route_limits(RouteLimits, IfEmpty); candidate_rejection_explanation( #{scores := RouteScores, limits := RouteLimits}, @@ -229,7 +234,9 @@ check_route_scores( terminal_priority_rating = Rating1 } ) when Rating0 < Rating1 -> - format("Priority of this route was less than in chosen route, where ~p < ~p.", [Rating0, Rating1]); + format("Priority of this route was less than in chosen route, where ~p < ~p.", [ + Rating0, Rating1 + ]); check_route_scores( #domain_PaymentRouteScores{ route_pin = Pin0 @@ -278,8 +285,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 +295,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/rebar.config b/rebar.config index b43d7ab4..3900516d 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"}}}, @@ -116,7 +116,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..903d8d3d 100644 --- a/rebar.lock +++ b/rebar.lock @@ -27,11 +27,11 @@ {<<"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", From edf1ec68121516d8bfd5c3aafdc0981a75903616 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Fri, 29 Aug 2025 18:21:29 +0300 Subject: [PATCH 02/10] Bump erlfmt --- erlang_ls.config | 4 ++++ rebar.config | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 erlang_ls.config 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 3900516d..069fa452 100644 --- a/rebar.config +++ b/rebar.config @@ -108,7 +108,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"}}} ]}. From 75bc412c37dc3ed4a858493f4d287c29c3ef63f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Fri, 29 Aug 2025 19:41:37 +0300 Subject: [PATCH 03/10] Revert "BG-360: Bump damsel" This reverts commit ed2b2681281d382a800dde0631dc9e34673c5f63. --- apps/hellgate/src/hg_accounting.erl | 4 +- apps/hellgate/src/hg_allocation.erl | 12 +- apps/hellgate/src/hg_cashflow.erl | 20 +- apps/hellgate/src/hg_cashflow_utils.erl | 16 +- apps/hellgate/src/hg_invoice.erl | 36 +- apps/hellgate/src/hg_invoice_handler.erl | 18 +- apps/hellgate/src/hg_invoice_mutation.erl | 15 +- apps/hellgate/src/hg_invoice_payment.erl | 329 +++++------------- .../src/hg_invoice_payment_chargeback.erl | 22 +- .../src/hg_invoice_payment_refund.erl | 23 +- .../src/hg_invoice_registered_payment.erl | 12 +- apps/hellgate/src/hg_invoice_template.erl | 14 +- apps/hellgate/src/hg_limiter.erl | 108 ++---- apps/hellgate/test/hg_ct_domain.hrl | 28 +- .../test/hg_direct_recurrent_tests_SUITE.erl | 44 +-- apps/hellgate/test/hg_invoice_helper.erl | 13 +- .../test/hg_invoice_lite_tests_SUITE.erl | 73 +--- .../test/hg_route_rules_tests_SUITE.erl | 120 ++----- apps/routing/src/hg_routing_explanation.erl | 15 +- rebar.config | 4 +- 20 files changed, 232 insertions(+), 694 deletions(-) diff --git a/apps/hellgate/src/hg_accounting.erl b/apps/hellgate/src/hg_accounting.erl index 7012d5c5..25d4c519 100644 --- a/apps/hellgate/src/hg_accounting.erl +++ b/apps/hellgate/src/hg_accounting.erl @@ -136,9 +136,7 @@ collect_provider_account_map(Payment, #domain_Provider{accounts = ProviderAccoun -spec collect_system_account_map(payment(), payment_institution(), revision(), map()) -> map(). collect_system_account_map(Payment, PaymentInstitution, Revision, Acc) -> Currency = get_currency(get_payment_cost(Payment)), - SystemAccount = hg_payment_institution:get_system_account( - Currency, Revision, PaymentInstitution - ), + SystemAccount = hg_payment_institution:get_system_account(Currency, Revision, PaymentInstitution), Acc#{ {system, settlement} => SystemAccount#domain_SystemAccount.settlement, {system, subagent} => SystemAccount#domain_SystemAccount.subagent diff --git a/apps/hellgate/src/hg_allocation.erl b/apps/hellgate/src/hg_allocation.erl index a4b55f92..3c042739 100644 --- a/apps/hellgate/src/hg_allocation.erl +++ b/apps/hellgate/src/hg_allocation.erl @@ -181,9 +181,7 @@ calculate_trxs([Head | Transactions], FeeTarget, CostLeft, FeeAcc, ID0, Acc0) -> construct_positive_trx(ID, Target, Amount, Details, Body) -> case construct_trx(ID, Target, Amount, Details, Body) of undefined -> - throw( - {invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount} - ); + throw({invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount}); Trx -> Trx end. @@ -221,9 +219,7 @@ add_fee(undefined, FeeAmount) -> add_fee(FeeCost, FeeAmount) -> hg_cash:add(FeeCost, FeeAmount). -calculate_trxs_body( - ?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP -) -> +calculate_trxs_body(?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP) -> {undefined, Amount, ?cash(0, SymCode)}; calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget, TP) -> CalculatedFee = calculate_trxs_fee(Fee, Total), @@ -237,9 +233,7 @@ calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget, calculate_trxs_fee(?allocation_trx_prototype_fee_fixed(Amount), _Total) -> Amount; -calculate_trxs_fee( - ?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode) -) -> +calculate_trxs_fee(?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode)) -> RoundingMethod1 = genlib:define(RoundingMethod0, round_half_away_from_zero), R = genlib_rational:new(P * Total, Q), Amount = ?cash(genlib_rational:round(R, RoundingMethod1), SymCode), diff --git a/apps/hellgate/src/hg_cashflow.erl b/apps/hellgate/src/hg_cashflow.erl index 37ee9e39..0c404ce5 100644 --- a/apps/hellgate/src/hg_cashflow.erl +++ b/apps/hellgate/src/hg_cashflow.erl @@ -119,9 +119,7 @@ resolve_account(AccountType, AccountMap) -> #{AccountType := V} -> V; #{} -> - error( - {misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}} - ) + error({misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}}) end. %% @@ -146,9 +144,7 @@ revert_details(Details) -> ). -define(share(P, Q, Of, RoundingMethod), - {share, #domain_CashVolumeShare{ - 'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod - }} + {share, #domain_CashVolumeShare{'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod}} ). -define(product(Fun, CVs), @@ -188,16 +184,12 @@ compute_product(Fun, [CV | CVRest], CV0, Context) -> CVRest ). -compute_product( - Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context -) -> +compute_product(Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context) -> case compute_volume(CV, Context) of #domain_Cash{amount = Amount, currency = Currency} -> CVMin#domain_Cash{amount = compute_product_fun(Fun, AmountMin, Amount)}; _ -> - error( - {misconfiguration, {'Cash volume product over volumes of different currencies', CV0}} - ) + error({misconfiguration, {'Cash volume product over volumes of different currencies', CV0}}) end. compute_product_fun(min_of, V1, V2) -> @@ -242,9 +234,7 @@ increment_remainder(AccountType, Cash, Acc) -> decrement_remainder(AccountType, ?cash(Amount, Currency), Acc) -> modify_remainder(AccountType, ?cash(-Amount, Currency), Acc). -modify_remainder( - #domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc -) -> +modify_remainder(#domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc) -> maps:update_with( AccountType, fun(?cash(A, C)) when C == Currency -> diff --git a/apps/hellgate/src/hg_cashflow_utils.erl b/apps/hellgate/src/hg_cashflow_utils.erl index 272c66b0..6f929920 100644 --- a/apps/hellgate/src/hg_cashflow_utils.erl +++ b/apps/hellgate/src/hg_cashflow_utils.erl @@ -114,20 +114,14 @@ construct_transaction_cashflow( end, MerchantCashflowSelector = get_terms_cashflow(OpType, MerchantPaymentsTerms1), MerchantCashflow = get_selector_value(merchant_payment_fees, MerchantCashflowSelector), - AccountMap = hg_accounting:collect_account_map( - make_collect_account_context(PaymentInstitution, Context) - ), + AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)), construct_final_cashflow(MerchantCashflow, #{operation_amount => Amount}, AccountMap). construct_provider_cashflow(PaymentInstitution, Context = #{provision_terms := ProvisionTerms}) -> ProviderCashflowSelector = get_provider_cashflow_selector(ProvisionTerms), ProviderCashflow = get_selector_value(provider_payment_cash_flow, ProviderCashflowSelector), - AccountMap = hg_accounting:collect_account_map( - make_collect_account_context(PaymentInstitution, Context) - ), - construct_final_cashflow( - ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap - ). + AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)), + construct_final_cashflow(ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap). construct_final_cashflow(Cashflow, Context, AccountMap) -> hg_cashflow:finalize(Cashflow, Context, AccountMap). @@ -150,9 +144,7 @@ get_amount(#{payment := #domain_InvoicePayment{cost = Cost}}) -> get_provider_cashflow_selector(#domain_PaymentsProvisionTerms{cash_flow = ProviderCashflowSelector}) -> ProviderCashflowSelector; -get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{ - cash_flow = ProviderCashflowSelector -}) -> +get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{cash_flow = ProviderCashflowSelector}) -> ProviderCashflowSelector. get_terms_cashflow(payment, MerchantPaymentsTerms) -> diff --git a/apps/hellgate/src/hg_invoice.erl b/apps/hellgate/src/hg_invoice.erl index 328a1f5c..c8c782d5 100644 --- a/apps/hellgate/src/hg_invoice.erl +++ b/apps/hellgate/src/hg_invoice.erl @@ -317,9 +317,7 @@ handle_repair({changes, Changes, RepairAction, Params}, St) -> % Validating that these changes are at least applicable validate => should_validate_transitions(Params) }; -handle_repair({scenario, _}, #st{activity = Activity}) when - Activity =:= invoice orelse Activity =:= undefined --> +handle_repair({scenario, _}, #st{activity = Activity}) when Activity =:= invoice orelse Activity =:= undefined -> throw({exception, invoice_has_no_active_payment}); handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) -> PaymentSession = get_payment_session(PaymentID, St), @@ -361,9 +359,7 @@ merge_repair_action({remove, #repair_RemoveAction{}}, Action) -> merge_repair_action({_, undefined}, Action) -> Action. -should_validate_transitions(#payproc_InvoiceRepairParams{validate_transitions = V}) when - is_boolean(V) --> +should_validate_transitions(#payproc_InvoiceRepairParams{validate_transitions = V}) when is_boolean(V) -> V; should_validate_transitions(undefined) -> true. @@ -499,18 +495,12 @@ handle_call({callback, _Tag, _Callback} = Call, St) -> handle_call({session_change, _Tag, _SessionChange} = Call, St) -> dispatch_to_session(Call, St). --spec dispatch_to_session( - {callback, tag(), callback()} | {session_change, tag(), session_change()}, st() -) -> +-spec dispatch_to_session({callback, tag(), callback()} | {session_change, tag(), session_change()}, st()) -> call_result(). -dispatch_to_session( - {callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}} -) -> +dispatch_to_session({callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}}) -> PaymentSession = get_payment_session(PaymentID, St), process_payment_call({callback, Tag, Payload}, PaymentID, PaymentSession, St); -dispatch_to_session( - {session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}} -) -> +dispatch_to_session({session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}}) -> PaymentSession = get_payment_session(PaymentID, St), process_payment_call(Call, PaymentID, PaymentSession, St); dispatch_to_session(_Call, _St) -> @@ -570,9 +560,7 @@ do_register_payment(PaymentID, PaymentParams, St) -> _ = assert_no_pending_payment(St), Opts = #{timestamp := OccurredAt} = get_payment_opts(St), % TODO make timer reset explicit here - {PaymentSession, {Changes, Action}} = hg_invoice_registered_payment:init( - PaymentID, PaymentParams, Opts - ), + {PaymentSession, {Changes, Action}} = hg_invoice_registered_payment:init(PaymentID, PaymentParams, Opts), #{ response => get_payment_state(PaymentSession), changes => wrap_payment_changes(PaymentID, Changes, OccurredAt), @@ -674,9 +662,7 @@ handle_payment_result({done, {Changes, Action}}, PaymentID, PaymentSession, St, end. collapse_payment_changes(Changes, PaymentSession, ChangeOpts) -> - lists:foldl( - fun(C, St1) -> merge_payment_change(C, St1, ChangeOpts) end, PaymentSession, Changes - ). + lists:foldl(fun(C, St1) -> merge_payment_change(C, St1, ChangeOpts) end, PaymentSession, Changes). wrap_payment_changes(PaymentID, Changes, OccurredAt) -> [?payment_ev(PaymentID, C, OccurredAt) || C <- Changes]. @@ -804,9 +790,7 @@ start_chargeback(Params, PaymentID, PaymentSession, PaymentOpts, St) -> case get_chargeback_state(ID, PaymentSession) of undefined -> #payproc_InvoicePaymentChargebackParams{occurred_at = OccurredAt} = Params, - CreateResult = hg_invoice_payment:create_chargeback( - PaymentSession, PaymentOpts, Params - ), + CreateResult = hg_invoice_payment:create_chargeback(PaymentSession, PaymentOpts, Params), wrap_payment_impact(PaymentID, CreateResult, St, OccurredAt); ChargebackState -> #{ @@ -881,9 +865,7 @@ merge_change(?invoice_created(Invoice), St, _Opts) -> St#st{activity = invoice, invoice = Invoice}; merge_change(?invoice_status_changed(Status), St = #st{invoice = I}, _Opts) -> St#st{invoice = I#domain_Invoice{status = Status}}; -merge_change( - ?payment_ev(PaymentID, Change), St = #st{invoice = #domain_Invoice{id = InvoiceID}}, Opts -) -> +merge_change(?payment_ev(PaymentID, Change), St = #st{invoice = #domain_Invoice{id = InvoiceID}}, Opts) -> PaymentSession = try_get_payment_session(PaymentID, St), PaymentSession1 = merge_payment_change(Change, PaymentSession, Opts#{invoice_id => InvoiceID}), St1 = set_payment_session(PaymentID, PaymentSession1, St), diff --git a/apps/hellgate/src/hg_invoice_handler.erl b/apps/hellgate/src/hg_invoice_handler.erl index fc113840..7143d37f 100644 --- a/apps/hellgate/src/hg_invoice_handler.erl +++ b/apps/hellgate/src/hg_invoice_handler.erl @@ -21,8 +21,7 @@ %% API --spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> - term() | no_return(). +-spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). handle_function(Func, Args, Opts) -> scoper:scope( invoicing, @@ -31,8 +30,7 @@ handle_function(Func, Args, Opts) -> end ). --spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> - term() | no_return(). +-spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). handle_function_('Create', {InvoiceParams}, _Opts) -> DomainRevision = hg_domain:head(), InvoiceID = InvoiceParams#payproc_InvoiceParams.id, @@ -148,15 +146,11 @@ handle_function_('RepairWithScenario', {InvoiceID, Scenario}, _Opts) -> handle_function_('GetPaymentRoutesLimitValues', {InvoiceID, PaymentID}, _Opts) -> _ = set_invoicing_meta(InvoiceID, PaymentID), St = get_state(InvoiceID), - hg_invoice_payment:get_limit_values( - get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St) - ); + hg_invoice_payment:get_limit_values(get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St)); handle_function_('ExplainRoute', {InvoiceID, PaymentID}, _Opts) -> _ = set_invoicing_meta(InvoiceID, PaymentID), St = get_state(InvoiceID), - hg_routing_explanation:get_explanation( - get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St) - ). + hg_routing_explanation:get_explanation(get_payment_session(PaymentID, St), hg_invoice:get_payment_opts(St)). ensure_started(ID, TemplateID, Params, Allocation, Mutations, DomainRevision) -> Invoice = hg_invoice:create(ID, TemplateID, Params, Allocation, Mutations, DomainRevision), @@ -348,9 +342,7 @@ validate_invoice_cost(Cost, Shop, #domain_TermSet{payments = PaymentTerms}) -> maybe_make_mutations(InvoiceParams) -> Cost = InvoiceParams#payproc_InvoiceParams.cost, - Mutations = hg_invoice_mutation:make_mutations( - InvoiceParams#payproc_InvoiceParams.mutations, #{cost => Cost} - ), + Mutations = hg_invoice_mutation:make_mutations(InvoiceParams#payproc_InvoiceParams.mutations, #{cost => Cost}), NewCost = hg_invoice_mutation:get_mutated_cost(Mutations, Cost), {NewCost, Mutations}. diff --git a/apps/hellgate/src/hg_invoice_mutation.erl b/apps/hellgate/src/hg_invoice_mutation.erl index 3d1c3181..b06caa43 100644 --- a/apps/hellgate/src/hg_invoice_mutation.erl +++ b/apps/hellgate/src/hg_invoice_mutation.erl @@ -47,9 +47,7 @@ validate_mutations_w_cart(Mutations, #domain_InvoiceCart{lines = Lines}) -> Mutations1 = genlib:define(Mutations, []), amount_mutation_is_present(Mutations1) andalso cart_is_not_valid_for_mutation(Lines) andalso throw(#base_InvalidRequest{ - errors = [ - <<"Amount mutation with multiline cart or multiple items in a line is not allowed">> - ] + errors = [<<"Amount mutation with multiline cart or multiple items in a line is not allowed">>] }), ok. @@ -65,8 +63,7 @@ amount_mutation_is_present(Mutations) -> cart_is_not_valid_for_mutation(Lines) -> length(Lines) > 1 orelse (hd(Lines))#domain_InvoiceLine.quantity =/= 1. --spec apply_mutations([mutation()] | undefined, Invoice) -> Invoice when - Invoice :: hg_invoice:invoice(). +-spec apply_mutations([mutation()] | undefined, Invoice) -> Invoice when Invoice :: hg_invoice:invoice(). apply_mutations(Mutations, Invoice) -> lists:foldl(fun apply_mutation/2, Invoice, genlib:define(Mutations, [])). @@ -97,9 +94,7 @@ update_invoice_line_price(NewAmount, Line = #domain_InvoiceLine{price = Price}) -spec make_mutations([mutation_params()], mutation_context()) -> [mutation()]. make_mutations(MutationsParams, Context) -> - {Mutations, _} = lists:foldl( - fun make_mutation/2, {[], Context}, genlib:define(MutationsParams, []) - ), + {Mutations, _} = lists:foldl(fun make_mutation/2, {[], Context}, genlib:define(MutationsParams, [])), lists:reverse(Mutations). -define(SATISFY_RANDOMIZATION_CONDITION(P, Amount), @@ -119,9 +114,7 @@ make_mutation( {Mutations, Context = #{cost := #domain_Cash{amount = Amount}}} ) when ?SATISFY_RANDOMIZATION_CONDITION(Params, Amount) -> NewMutation = - {amount, #domain_InvoiceAmountMutation{ - original = Amount, mutated = calc_new_amount(Amount, Params) - }}, + {amount, #domain_InvoiceAmountMutation{original = Amount, mutated = calc_new_amount(Amount, Params)}}, {[NewMutation | Mutations], Context}; make_mutation(_, {Mutations, Context}) -> {Mutations, Context}. diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 9633390b..81c52d28 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -180,8 +180,7 @@ -type payment() :: dmsl_domain_thrift:'InvoicePayment'(). -type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'(). -type payment_status() :: dmsl_domain_thrift:'InvoicePaymentStatus'(). --type payment_status_type() :: - pending | processed | captured | cancelled | refunded | failed | charged_back. +-type payment_status_type() :: pending | processed | captured | cancelled | refunded | failed | charged_back. -type domain_refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'(). -type payment_refund() :: dmsl_payproc_thrift:'InvoicePaymentRefund'(). -type refund_id() :: dmsl_domain_thrift:'InvoicePaymentRefundID'(). @@ -245,9 +244,7 @@ %% --define(LOG_MD(Level, Format, Args), - logger:log(Level, Format, Args, logger:get_process_metadata()) -). +-define(LOG_MD(Level, Format, Args), logger:log(Level, Format, Args, logger:get_process_metadata())). -spec get_payment(st()) -> payment(). get_payment(#st{payment = Payment}) -> @@ -492,9 +489,7 @@ construct_payer( end, #domain_InvoicePayment{payer = ParentPayer} = get_payment(ParentPayment), ParentPaymentTool = get_payer_payment_tool(ParentPayer), - {ok, ?recurrent_payer(ParentPaymentTool, Parent, ContactInfo), #{ - parent_payment => ParentPayment - }}. + {ok, ?recurrent_payer(ParentPaymentTool, Parent, ContactInfo), #{parent_payment => ParentPayment}}. construct_payment( PaymentID, @@ -530,9 +525,7 @@ construct_payment( PaymentTool ), ParentPayment = maps:get(parent_payment, VS1, undefined), - ok = validate_recurrent_intention( - Payer, RecurrentTerms, PaymentTool, ShopObj, ParentPayment, MakeRecurrent - ), + ok = validate_recurrent_intention(Payer, RecurrentTerms, PaymentTool, ShopObj, ParentPayment, MakeRecurrent), #domain_InvoicePayment{ id = PaymentID, created_at = CreatedAt, @@ -610,18 +603,13 @@ validate_recurrent_intention( ok = validate_recurrent_terms(RecurrentTerms, PaymentTool), ok = validate_recurrent_payer(Payer, MakeRecurrent), ok = validate_recurrent_parent(ShopObj, ParentPayment); -validate_recurrent_intention( - Payer, RecurrentTerms, PaymentTool, _Shop, _ParentPayment, true = MakeRecurrent -) -> +validate_recurrent_intention(Payer, RecurrentTerms, PaymentTool, _Shop, _ParentPayment, true = MakeRecurrent) -> ok = validate_recurrent_terms(RecurrentTerms, PaymentTool), ok = validate_recurrent_payer(Payer, MakeRecurrent); -validate_recurrent_intention( - _Payer, _RecurrentTerms, _PaymentTool, _Shop, _ParentPayment, false = _MakeRecurrent -) -> +validate_recurrent_intention(_Payer, _RecurrentTerms, _PaymentTool, _Shop, _ParentPayment, false = _MakeRecurrent) -> ok. --spec validate_recurrent_terms(recurrent_paytool_service_terms(), payment_tool()) -> - ok | no_return(). +-spec validate_recurrent_terms(recurrent_paytool_service_terms(), payment_tool()) -> ok | no_return(). validate_recurrent_terms(undefined, _PaymentTool) -> throw(#payproc_OperationNotPermitted{}); validate_recurrent_terms(RecurrentTerms, PaymentTool) -> @@ -767,9 +755,7 @@ log_rejected_routes(in_blacklist, Routes, _VS) -> log_rejected_routes(adapter_unavailable, Routes, _VS) -> ?LOG_MD(notice, "Adapter unavailability caused route candidates to be rejected: ~p", [Routes]); log_rejected_routes(provider_conversion_is_too_low, Routes, _VS) -> - ?LOG_MD(notice, "Lacking conversion of provider caused route candidates to be rejected: ~p", [ - Routes - ]); + ?LOG_MD(notice, "Lacking conversion of provider caused route candidates to be rejected: ~p", [Routes]); log_rejected_routes(forbidden, Routes, VS) -> ?LOG_MD(notice, "Rejected routes found for varset: ~p", [VS]), ?LOG_MD(notice, "Rejected routes found, rejected routes: ~p", [Routes]); @@ -984,17 +970,13 @@ assert_capture_cost_currency(undefined, _) -> ok; assert_capture_cost_currency(?cash(_, SymCode), #domain_InvoicePayment{cost = ?cash(_, SymCode)}) -> ok; -assert_capture_cost_currency(?cash(_, PassedSymCode), #domain_InvoicePayment{ - cost = ?cash(_, SymCode) -}) -> +assert_capture_cost_currency(?cash(_, PassedSymCode), #domain_InvoicePayment{cost = ?cash(_, SymCode)}) -> throw(#payproc_InconsistentCaptureCurrency{ payment_currency = SymCode, passed_currency = PassedSymCode }). -validate_processing_deadline( - #domain_InvoicePayment{processing_deadline = Deadline}, _TargetType = processed -) -> +validate_processing_deadline(#domain_InvoicePayment{processing_deadline = Deadline}, _TargetType = processed) -> case hg_invoice_utils:check_deadline(Deadline) of ok -> ok; @@ -1020,21 +1002,15 @@ assert_capture_cart(Cost, Cart) -> check_equal_capture_cost_amount(undefined, _) -> true; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ - cost = ?cash(Amount, _) -}) when +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) when PassedAmount =:= Amount -> true; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ - cost = ?cash(Amount, _) -}) when +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) when PassedAmount < Amount -> false; -check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{ - cost = ?cash(Amount, _) -}) -> +check_equal_capture_cost_amount(?cash(PassedAmount, _), #domain_InvoicePayment{cost = ?cash(Amount, _)}) -> throw(#payproc_AmountExceededCaptureBalance{ payment_amount = Amount, passed_amount = PassedAmount @@ -1052,9 +1028,7 @@ validate_merchant_hold_terms(#domain_PaymentsServiceTerms{holds = Terms}) when T validate_merchant_hold_terms(#domain_PaymentsServiceTerms{holds = undefined}) -> ok. -validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) when - Terms /= undefined --> +validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) when Terms /= undefined -> case Terms of %% Чтобы упростить интеграцию, по умолчанию разрешили частичные подтверждения #domain_PaymentHoldsProvisionTerms{partial_captures = undefined} -> @@ -1066,8 +1040,7 @@ validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = Terms}) whe validate_provider_holds_terms(#domain_PaymentsProvisionTerms{holds = undefined}) -> ok. --spec create_chargeback(st(), opts(), hg_invoice_payment_chargeback:create_params()) -> - {chargeback(), result()}. +-spec create_chargeback(st(), opts(), hg_invoice_payment_chargeback:create_params()) -> {chargeback(), result()}. create_chargeback(St, Opts, Params) -> _ = assert_no_pending_chargebacks(St), _ = validate_payment_status(captured, get_payment(St)), @@ -1076,29 +1049,25 @@ create_chargeback(St, Opts, Params) -> {Chargeback, {Changes, Action}} = hg_invoice_payment_chargeback:create(CBOpts, Params), {Chargeback, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec cancel_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:cancel_params()) -> - {ok, result()}. +-spec cancel_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:cancel_params()) -> {ok, result()}. cancel_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:cancel(ChargebackState, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec reject_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reject_params()) -> - {ok, result()}. +-spec reject_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reject_params()) -> {ok, result()}. reject_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:reject(ChargebackState, St, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec accept_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:accept_params()) -> - {ok, result()}. +-spec accept_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:accept_params()) -> {ok, result()}. accept_chargeback(ChargebackID, St, Params) -> ChargebackState = get_chargeback_state(ChargebackID, St), {ok, {Changes, Action}} = hg_invoice_payment_chargeback:accept(ChargebackState, St, Params), {ok, {[?chargeback_ev(ChargebackID, C) || C <- Changes], Action}}. --spec reopen_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reopen_params()) -> - {ok, result()}. +-spec reopen_chargeback(chargeback_id(), st(), hg_invoice_payment_chargeback:reopen_params()) -> {ok, result()}. reopen_chargeback(ChargebackID, St, Params) -> _ = assert_no_pending_chargebacks(St), ChargebackState = get_chargeback_state(ChargebackID, St), @@ -1121,9 +1090,7 @@ refund(Params, St0, Opts = #{timestamp := CreatedAt}) -> VS = collect_validation_varset(St, Opts), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS), Refund = make_refund(Params, Payment, Revision, CreatedAt, St, Opts), - FinalCashflow = make_refund_cashflow( - Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt - ), + FinalCashflow = make_refund_cashflow(Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt), Changes = hg_invoice_payment_refund:create(#{ refund => Refund, cash_flow => FinalCashflow @@ -1138,9 +1105,7 @@ manual_refund(Params, St0, Opts = #{timestamp := CreatedAt}) -> VS = collect_validation_varset(St, Opts), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS), Refund = make_refund(Params, Payment, Revision, CreatedAt, St, Opts), - FinalCashflow = make_refund_cashflow( - Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt - ), + FinalCashflow = make_refund_cashflow(Refund, Payment, Revision, St, Opts, MerchantTerms, VS, CreatedAt), TransactionInfo = Params#payproc_InvoicePaymentRefundParams.transaction_info, Changes = hg_invoice_payment_refund:create(#{ refund => Refund, @@ -1360,8 +1325,7 @@ validate_common_refund_terms(Terms, Refund, Payment) -> %% --spec create_adjustment(hg_datetime:timestamp(), adjustment_params(), st(), opts()) -> - {adjustment(), result()}. +-spec create_adjustment(hg_datetime:timestamp(), adjustment_params(), st(), opts()) -> {adjustment(), result()}. create_adjustment(Timestamp, Params, St, Opts) -> _ = assert_no_adjustment_pending(St), case Params#payproc_InvoicePaymentAdjustmentParams.scenario of @@ -1489,9 +1453,7 @@ assert_no_refunds(St) -> throw_invalid_request(<<"Cannot change status of payment with refunds.">>) end. --spec assert_adjustment_payment_statuses( - TargetStatus :: payment_status(), Status :: payment_status() -) -> +-spec assert_adjustment_payment_statuses(TargetStatus :: payment_status(), Status :: payment_status()) -> ok | no_return(). assert_adjustment_payment_statuses(Status, Status) -> erlang:throw(#payproc_InvoicePaymentAlreadyHasStatus{status = Status}); @@ -1568,8 +1530,7 @@ calculate_cashflow(Context = #{route := Route, revision := Revision}, Opts) -> }), hg_cashflow_utils:collect_cashflow(CollectCashflowContext). --spec calculate_cashflow(hg_payment_institution:t(), cashflow_context(), opts()) -> - final_cash_flow(). +-spec calculate_cashflow(hg_payment_institution:t(), cashflow_context(), opts()) -> final_cash_flow(). calculate_cashflow(PaymentInstitution, Context = #{route := Route, revision := Revision}, Opts) -> CollectCashflowContext = genlib_map:compact(Context#{ operation => payment, @@ -1634,10 +1595,7 @@ assert_payment_status(_, #domain_InvoicePayment{status = Status}) -> throw(#payproc_InvalidPaymentStatus{status = Status}). assert_no_pending_chargebacks(PaymentState) -> - Chargebacks = [ - CB#payproc_InvoicePaymentChargeback.chargeback - || CB <- get_chargebacks(PaymentState) - ], + Chargebacks = [CB#payproc_InvoicePaymentChargeback.chargeback || CB <- get_chargebacks(PaymentState)], case lists:any(fun hg_invoice_payment_chargeback:is_pending/1, Chargebacks) of true -> throw(#payproc_InvoicePaymentChargebackPending{}); @@ -1931,9 +1889,7 @@ process_risk_score(Action, St) -> Payment = get_payment(St), VS1 = get_varset(St, #{}), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), - PaymentInstitution = hg_payment_institution:compute_payment_institution( - PaymentInstitutionRef, VS1, Revision - ), + PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), RiskScore = repair_inspect(Payment, PaymentInstitution, Opts, St), Events = [?risk_score_changed(RiskScore)], case check_risk_score(RiskScore) of @@ -1999,18 +1955,12 @@ produce_routing_events(Ctx = #{error := Error}, _Revision, St) when Error =/= un %% skipped. And all limit's 'hold' operations will be rolled back. %% For same purpose in cascade routing we use route from unfiltered list of %% originally resolved candidates. - [ - ?route_changed(Route, Candidates, RouteScores, RouteLimits), - ?payment_rollback_started(Failure) - ]; + [?route_changed(Route, Candidates, RouteScores, RouteLimits), ?payment_rollback_started(Failure)]; produce_routing_events(Ctx, Revision, _St) -> ok = log_route_choice_meta(Ctx, Revision), Route = hg_route:to_payment_route(hg_routing_ctx:choosen_route(Ctx)), Candidates = - ordsets:from_list([ - hg_route:to_payment_route(R) - || R <- hg_routing_ctx:considered_candidates(Ctx) - ]), + ordsets:from_list([hg_route:to_payment_route(R) || R <- hg_routing_ctx:considered_candidates(Ctx)]), RouteScores = hg_routing_ctx:route_scores(Ctx), RouteLimits = hg_routing_ctx:route_limits(Ctx), [?route_changed(Route, Candidates, RouteScores, RouteLimits)]. @@ -2023,13 +1973,9 @@ route_args(St) -> CreatedAt = get_payment_created_at(Payment), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), MerchantTerms = get_merchant_payments_terms(Opts, Revision, CreatedAt, VS1), - VS2 = collect_refund_varset( - MerchantTerms#domain_PaymentsServiceTerms.refunds, PaymentTool, VS1 - ), + VS2 = collect_refund_varset(MerchantTerms#domain_PaymentsServiceTerms.refunds, PaymentTool, VS1), VS3 = collect_chargeback_varset(MerchantTerms#domain_PaymentsServiceTerms.chargebacks, VS2), - PaymentInstitution = hg_payment_institution:compute_payment_institution( - PaymentInstitutionRef, VS1, Revision - ), + PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), {PaymentInstitution, VS3, Revision}. build_routing_context(PaymentInstitution, VS, Revision, St) -> @@ -2054,12 +2000,8 @@ build_blacklist_context(St) -> Opts = get_opts(St), VS1 = get_varset(St, #{}), PaymentInstitutionRef = get_payment_institution_ref(Opts, Revision), - PaymentInstitution = hg_payment_institution:compute_payment_institution( - PaymentInstitutionRef, VS1, Revision - ), - InspectorRef = get_selector_value( - inspector, PaymentInstitution#domain_PaymentInstitution.inspector - ), + PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS1, Revision), + InspectorRef = get_selector_value(inspector, PaymentInstitution#domain_PaymentInstitution.inspector), Inspector = hg_domain:get(Revision, {inspector, InspectorRef}), #{ revision => Revision, @@ -2094,22 +2036,16 @@ construct_routing_failure({rejected_routes, {SubCode, RejectedRoutes}}) when construct_routing_failure({rejected_routes, {_SubCode, RejectedRoutes}}) -> construct_routing_failure([forbidden], genlib:format(RejectedRoutes)); construct_routing_failure({misconfiguration = Code, Details}) -> - construct_routing_failure( - [unknown, {unknown_error, atom_to_binary(Code)}], genlib:format(Details) - ); + construct_routing_failure([unknown, {unknown_error, atom_to_binary(Code)}], genlib:format(Details)); construct_routing_failure(Code = risk_score_is_too_high) -> construct_routing_failure([Code], undefined); construct_routing_failure(Error) when is_atom(Error) -> construct_routing_failure([{unknown_error, Error}], undefined). construct_routing_failure(Codes, Reason) -> - {failure, - payproc_errors:construct( - 'PaymentFailure', mk_static_error([no_route_found | Codes]), Reason - )}. + {failure, payproc_errors:construct('PaymentFailure', mk_static_error([no_route_found | Codes]), Reason)}. -mk_static_error([_ | _] = Codes) -> - mk_static_error_(#payproc_error_GeneralFailure{}, lists:reverse(Codes)). +mk_static_error([_ | _] = Codes) -> mk_static_error_(#payproc_error_GeneralFailure{}, lists:reverse(Codes)). mk_static_error_(T, []) -> T; mk_static_error_(Sub, [Code | Codes]) -> mk_static_error_({Code, Sub}, Codes). @@ -2146,24 +2082,19 @@ process_cash_flow_building(Action, St) -> %% --spec process_chargeback(chargeback_activity_type(), chargeback_id(), action(), st()) -> - machine_result(). +-spec process_chargeback(chargeback_activity_type(), chargeback_id(), action(), st()) -> machine_result(). process_chargeback(Type = finalising_accounter, ID, Action0, St) -> ChargebackState = get_chargeback_state(ID, St), ChargebackOpts = get_chargeback_opts(St), ChargebackBody = hg_invoice_payment_chargeback:get_body(ChargebackState), ChargebackTarget = hg_invoice_payment_chargeback:get_target_status(ChargebackState), MaybeChargedback = maybe_set_charged_back_status(ChargebackTarget, ChargebackBody, St), - {Changes, Action1} = hg_invoice_payment_chargeback:process_timeout( - Type, ChargebackState, Action0, ChargebackOpts - ), + {Changes, Action1} = hg_invoice_payment_chargeback:process_timeout(Type, ChargebackState, Action0, ChargebackOpts), {done, {[?chargeback_ev(ID, C) || C <- Changes] ++ MaybeChargedback, Action1}}; process_chargeback(Type, ID, Action0, St) -> ChargebackState = get_chargeback_state(ID, St), ChargebackOpts = get_chargeback_opts(St), - {Changes0, Action1} = hg_invoice_payment_chargeback:process_timeout( - Type, ChargebackState, Action0, ChargebackOpts - ), + {Changes0, Action1} = hg_invoice_payment_chargeback:process_timeout(Type, ChargebackState, Action0, ChargebackOpts), Changes1 = [?chargeback_ev(ID, C) || C <- Changes0], case Type of %% NOTE In case if payment is already charged back and we want @@ -2206,9 +2137,7 @@ process_adjustment_cashflow(ID, _Action, St) -> Events = [?adjustment_ev(ID, ?adjustment_status_changed(?adjustment_processed()))], {next, {Events, hg_machine_action:instant()}}. -process_accounter_update( - Action, St = #st{partial_cash_flow = FinalCashflow, capture_data = CaptureData} -) -> +process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, capture_data = CaptureData}) -> #payproc_InvoicePaymentCaptureData{ reason = Reason, cash = Cost, @@ -2227,14 +2156,11 @@ process_accounter_update( %% --spec handle_callback(activity(), callback(), hg_session:t(), st()) -> - {callback_response(), machine_result()}. +-spec handle_callback(activity(), callback(), hg_session:t(), st()) -> {callback_response(), machine_result()}. handle_callback({refund, ID}, Payload, _Session0, St) -> PaymentInfo = construct_payment_info(St, get_opts(St)), Refund = try_get_refund_state(ID, St), - {Resp, {Step, {Events0, Action}}} = hg_invoice_payment_refund:process_callback( - Payload, PaymentInfo, Refund - ), + {Resp, {Step, {Events0, Action}}} = hg_invoice_payment_refund:process_callback(Payload, PaymentInfo, Refund), Events1 = hg_invoice_payment_refund:wrap_events(Events0, Refund), {Resp, {Step, {Events1, Action}}}; handle_callback(Activity, Payload, Session0, St) -> @@ -2410,9 +2336,7 @@ process_result({payment, finalizing_accounter}, Action, St) -> process_failure(Activity, Events, Action, Failure, St) -> process_failure(Activity, Events, Action, Failure, St, undefined). -process_failure( - {payment, processing_failure}, Events, Action, _Failure, #st{failure = Failure}, _RefundSt -) when +process_failure({payment, processing_failure}, Events, Action, _Failure, #st{failure = Failure}, _RefundSt) when Failure =/= undefined -> %% In case of cascade attempt we may catch and handle routing failure during 'processing_failure' activity @@ -2456,9 +2380,7 @@ check_recurrent_token(_) -> ok. choose_fd_operation_status_for_failure({failure, Failure}) -> - payproc_errors:match( - 'PaymentFailure', Failure, fun do_choose_fd_operation_status_for_failure/1 - ); + payproc_errors:match('PaymentFailure', Failure, fun do_choose_fd_operation_status_for_failure/1); choose_fd_operation_status_for_failure(_Failure) -> finish. @@ -2578,9 +2500,7 @@ filter_routes_with_limit_hold(Ctx0, VS, Iter, St) -> hg_routing_ctx:stash_current_candidates(Ctx1). filter_routes_by_limit_overflow(Ctx0, VS, Iter, St) -> - {_Routes, RejectedRoutes, Limits} = get_limit_overflow_routes( - hg_routing_ctx:candidates(Ctx0), VS, Iter, St - ), + {_Routes, RejectedRoutes, Limits} = get_limit_overflow_routes(hg_routing_ctx:candidates(Ctx0), VS, Iter, St), Ctx1 = hg_routing_ctx:stash_route_limits(Limits, Ctx0), reject_routes(limit_overflow, RejectedRoutes, Ctx1). @@ -2606,9 +2526,7 @@ get_limit_overflow_routes(Routes, VS, Iter, St) -> {[Route | RoutesNoOverflowIn], RejectedIn, LimitsIn#{PaymentRoute => Limits}}; {error, {limit_overflow, IDs, Limits}} -> RejectedRoute = hg_route:to_rejected_route(Route, {'LimitOverflow', IDs}), - {RoutesNoOverflowIn, [RejectedRoute | RejectedIn], LimitsIn#{ - PaymentRoute => Limits - }} + {RoutesNoOverflowIn, [RejectedRoute | RejectedIn], LimitsIn#{PaymentRoute => Limits}} end end, {[], [], #{}}, @@ -2684,9 +2602,7 @@ hold_limit_routes(Routes0, VS, Iter, St) -> ProviderTerms = hg_routing:get_payment_terms(PaymentRoute, VS, Revision), TurnoverLimits = get_turnover_limits(ProviderTerms), try - ok = hg_limiter:hold_payment_limits( - TurnoverLimits, Invoice, Payment, PaymentRoute, Iter - ), + ok = hg_limiter:hold_payment_limits(TurnoverLimits, Invoice, Payment, PaymentRoute, Iter), {[Route | LimitHeldRoutes], RejectedRoutes} catch error:(#limiter_LimitNotFound{} = LimiterError) -> @@ -2719,9 +2635,7 @@ rollback_payment_limits(Routes, Iter, St, Flags) -> fun(Route) -> ProviderTerms = hg_routing:get_payment_terms(Route, VS, Revision), TurnoverLimits = get_turnover_limits(ProviderTerms), - ok = hg_limiter:rollback_payment_limits( - TurnoverLimits, Invoice, Payment, Route, Iter, Flags - ) + ok = hg_limiter:rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, Flags) end, Routes ). @@ -2745,11 +2659,9 @@ rollback_broken_payment_limits(St) -> [], Values ), - ok = hg_limiter:rollback_payment_limits( - TurnoverLimits, Invoice, Payment, Route, Iter, [ - ignore_business_error - ] - ) + ok = hg_limiter:rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, [ + ignore_business_error + ]) end, ok, LimitValues @@ -2759,9 +2671,7 @@ rollback_unused_payment_limits(St) -> Route = get_route(St), Routes = get_candidate_routes(St), UnUsedRoutes = Routes -- [Route], - rollback_payment_limits(UnUsedRoutes, get_iter(St), St, [ - ignore_business_error, ignore_not_found - ]). + rollback_payment_limits(UnUsedRoutes, get_iter(St), St, [ignore_business_error, ignore_not_found]). get_turnover_limits(ProviderTerms) -> TurnoverLimitSelector = ProviderTerms#domain_PaymentsProvisionTerms.turnover_limits, @@ -2811,9 +2721,7 @@ do_try_with_ids([ID | OtherIDs], Func) when is_function(Func, 1) -> Func(ID) catch %% Very specific error to crutch around - error:{accounting, #base_InvalidRequest{ - errors = [<<"Posting plan not found: ", ID/binary>>] - }} -> + error:{accounting, #base_InvalidRequest{errors = [<<"Posting plan not found: ", ID/binary>>]}} -> do_try_with_ids(OtherIDs, Func) end. @@ -2837,9 +2745,7 @@ get_cashflow_plan(St = #st{new_cash_provided = true, new_cash_flow = NewCashFlow {2, hg_cashflow:revert(get_cashflow(St))}, {3, NewCashFlow} ]; -get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when - PartialCashFlow =/= undefined --> +get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when PartialCashFlow =/= undefined -> [ {1, get_cashflow(St)}, {2, hg_cashflow:revert(get_cashflow(St))}, @@ -2917,9 +2823,7 @@ construct_proxy_payment( construct_payment_resource(?payment_resource_payer(Resource, _)) -> {disposable_payment_resource, Resource}; -construct_payment_resource( - ?recurrent_payer(PaymentTool, ?recurrent_parent(InvoiceID, PaymentID), _) -) -> +construct_payment_resource(?recurrent_payer(PaymentTool, ?recurrent_parent(InvoiceID, PaymentID), _)) -> PreviousPayment = get_payment_state(InvoiceID, PaymentID), RecToken = get_recurrent_token(PreviousPayment), {recurrent_payment_resource, #proxy_provider_RecurrentPaymentResource{ @@ -2955,8 +2859,7 @@ construct_proxy_shop( Shop = #domain_ShopConfig{ location = Location, category = ShopCategoryRef - } - } + }} ) -> ShopCategory = hg_domain:get({category, ShopCategoryRef}), #proxy_provider_Shop{ @@ -3153,9 +3056,7 @@ merge_change( routes = [Route | Routes], candidate_routes = ordsets:to_list(Candidates), activity = {payment, cash_flow_building}, - route_scores = hg_maybe:apply( - fun(S) -> maps:merge(RouteScores, S) end, Scores, RouteScores - ), + route_scores = hg_maybe:apply(fun(S) -> maps:merge(RouteScores, S) end, Scores, RouteScores), route_limits = hg_maybe:apply(fun(L) -> maps:merge(RouteLimits, L) end, Limits, RouteLimits) }; merge_change(Change = ?payment_capture_started(Data), #st{} = St, Opts) -> @@ -3199,9 +3100,7 @@ merge_change(Change = ?cash_flow_changed(CashFlow), #st{activity = Activity} = S St end; merge_change(Change = ?rec_token_acquired(Token), #st{} = St, Opts) -> - _ = validate_transition( - [{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts - ), + _ = validate_transition([{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts), St#st{recurrent_token = Token}; merge_change(Change = ?cash_changed(_OldCash, NewCash), #st{} = St, Opts) -> _ = validate_transition( @@ -3238,9 +3137,7 @@ merge_change(Change = ?payment_rollback_started(Failure), St, Opts) -> activity = Activity, timings = accrue_status_timing(failed, Opts, St) }; -merge_change( - Change = ?payment_status_changed({failed, _} = Status), #st{payment = Payment} = St, Opts -) -> +merge_change(Change = ?payment_status_changed({failed, _} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition( [ {payment, S} @@ -3263,20 +3160,14 @@ merge_change( failure = undefined, timings = accrue_status_timing(failed, Opts, St) }; -merge_change( - Change = ?payment_status_changed({cancelled, _} = Status), #st{payment = Payment} = St, Opts -) -> +merge_change(Change = ?payment_status_changed({cancelled, _} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition({payment, finalizing_accounter}, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status}, activity = idle, timings = accrue_status_timing(cancelled, Opts, St) }; -merge_change( - Change = ?payment_status_changed({captured, Captured} = Status), - #st{payment = Payment} = St, - Opts -) -> +merge_change(Change = ?payment_status_changed({captured, Captured} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition([idle, {payment, finalizing_accounter}], Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{ @@ -3287,25 +3178,19 @@ merge_change( timings = accrue_status_timing(captured, Opts, St), allocation = get_captured_allocation(Captured) }; -merge_change( - Change = ?payment_status_changed({processed, _} = Status), #st{payment = Payment} = St, Opts -) -> +merge_change(Change = ?payment_status_changed({processed, _} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition({payment, processing_accounter}, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status}, activity = {payment, flow_waiting}, timings = accrue_status_timing(processed, Opts, St) }; -merge_change( - Change = ?payment_status_changed({refunded, _} = Status), #st{payment = Payment} = St, Opts -) -> +merge_change(Change = ?payment_status_changed({refunded, _} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition(idle, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status} }; -merge_change( - Change = ?payment_status_changed({charged_back, _} = Status), #st{payment = Payment} = St, Opts -) -> +merge_change(Change = ?payment_status_changed({charged_back, _} = Status), #st{payment = Payment} = St, Opts) -> _ = validate_transition(idle, Change, St, Opts), (record_status_change(Change, St))#st{ payment = Payment#domain_InvoicePayment{status = Status} @@ -3320,20 +3205,13 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> _ = validate_transition(idle, Change, St, Opts), St; ?chargeback_levy_changed(_) -> - _ = validate_transition( - [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts - ), + _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), St#st{activity = {chargeback, ID, updating_chargeback}}; ?chargeback_body_changed(_) -> - _ = validate_transition( - [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts - ), + _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), St#st{activity = {chargeback, ID, updating_chargeback}}; ?chargeback_cash_flow_changed(_) -> - Valid = [ - {chargeback, ID, Activity} - || Activity <- [preparing_initial_cash_flow, updating_cash_flow] - ], + Valid = [{chargeback, ID, Activity} || Activity <- [preparing_initial_cash_flow, updating_cash_flow]], _ = validate_transition(Valid, Change, St, Opts), case St of #st{activity = {chargeback, ID, preparing_initial_cash_flow}} -> @@ -3342,9 +3220,7 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> St#st{activity = {chargeback, ID, finalising_accounter}} end; ?chargeback_target_status_changed(?chargeback_status_accepted()) -> - _ = validate_transition( - [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts - ), + _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), case St of #st{activity = idle} -> St#st{activity = {chargeback, ID, finalising_accounter}}; @@ -3352,14 +3228,10 @@ merge_change(Change = ?chargeback_ev(ID, Event), St, Opts) -> St#st{activity = {chargeback, ID, updating_cash_flow}} end; ?chargeback_target_status_changed(_) -> - _ = validate_transition( - [idle, {chargeback, ID, updating_chargeback}], Change, St, Opts - ), + _ = validate_transition([idle, {chargeback, ID, updating_chargeback}], Change, St, Opts), St#st{activity = {chargeback, ID, updating_cash_flow}}; ?chargeback_status_changed(_) -> - _ = validate_transition( - [idle, {chargeback, ID, finalising_accounter}], Change, St, Opts - ), + _ = validate_transition([idle, {chargeback, ID, finalising_accounter}], Change, St, Opts), St#st{activity = idle} end, ChargebackSt = merge_chargeback_change(Event, try_get_chargeback_state(ID, St1)), @@ -3386,9 +3258,7 @@ merge_change(?refund_ev(ID, Event), St, Opts) -> _ -> St end, - RefundSt1 = hg_invoice_payment_refund:apply_event( - Event, try_get_refund_state(ID, St1), EventContext - ), + RefundSt1 = hg_invoice_payment_refund:apply_event(Event, try_get_refund_state(ID, St1), EventContext), St2 = set_refund_state(ID, RefundSt1, St1), case hg_invoice_payment_refund:status(RefundSt1) of S when S == succeeded; S == failed -> @@ -3439,9 +3309,7 @@ merge_change( Opts ), % FIXME why the hell dedicated handling - Session0 = hg_session:apply_event( - Event, undefined, create_session_event_context(Target, St, Opts) - ), + Session0 = hg_session:apply_event(Event, undefined, create_session_event_context(Target, St, Opts)), %% We need to pass processed trx_info to captured/cancelled session due to provider requirements Session1 = hg_session:set_trx_info(get_trx(St), Session0), St1 = add_session(Target, Session1, St#st{target = Target}), @@ -3450,9 +3318,7 @@ merge_change( {payment, processing_session} -> %% session retrying St2#st{activity = {payment, processing_session}}; - {payment, PaymentActivity} when - PaymentActivity == flow_waiting; PaymentActivity == processing_capture - -> + {payment, PaymentActivity} when PaymentActivity == flow_waiting; PaymentActivity == processing_capture -> %% session flow St2#st{ activity = {payment, finalizing_session}, @@ -3468,9 +3334,7 @@ merge_change( St2 end; merge_change(Change = ?session_ev(Target, Event), St = #st{activity = Activity}, Opts) -> - _ = validate_transition( - [{payment, S} || S <- [processing_session, finalizing_session]], Change, St, Opts - ), + _ = validate_transition([{payment, S} || S <- [processing_session, finalizing_session]], Change, St, Opts), Session = hg_session:apply_event( Event, get_session(Target, St), @@ -3525,27 +3389,19 @@ log_cascade_attempt_context( #domain_PaymentsServiceTerms{attempt_limit = AttemptLimit}, #st{routes = AttemptedRoutes} ) -> - ?LOG_MD( - notice, - "Cascade context: merchant payment terms' attempt limit '~p', attempted routes: ~p", - [ - AttemptLimit, AttemptedRoutes - ] - ). + ?LOG_MD(notice, "Cascade context: merchant payment terms' attempt limit '~p', attempted routes: ~p", [ + AttemptLimit, AttemptedRoutes + ]). get_routing_attempt_limit_value(undefined) -> 1; get_routing_attempt_limit_value({decisions, _}) -> get_routing_attempt_limit_value(undefined); -get_routing_attempt_limit_value({value, #domain_AttemptLimit{attempts = Value}}) when - is_integer(Value) --> +get_routing_attempt_limit_value({value, #domain_AttemptLimit{attempts = Value}}) when is_integer(Value) -> Value. save_retry_attempt(Target, #st{retry_attempts = Attempts} = St) -> - St#st{ - retry_attempts = maps:update_with(get_target_type(Target), fun(N) -> N + 1 end, 0, Attempts) - }. + St#st{retry_attempts = maps:update_with(get_target_type(Target), fun(N) -> N + 1 end, 0, Attempts)}. merge_chargeback_change(Change, ChargebackState) -> hg_invoice_payment_chargeback:merge_change(Change, ChargebackState). @@ -3583,8 +3439,7 @@ apply_adjustment_effect(status, #domain_InvoicePaymentAdjustment{}, St) -> apply_adjustment_effect(cashflow, Adjustment, St) -> set_cashflow(get_adjustment_cashflow(Adjustment), St). --spec validate_transition(activity() | [activity()], change(), st(), change_opts()) -> - ok | no_return(). +-spec validate_transition(activity() | [activity()], change(), st(), change_opts()) -> ok | no_return(). validate_transition(Allowed, Change, St, Opts) -> case {Opts, is_transition_valid(Allowed, St)} of {#{}, true} -> @@ -3693,8 +3548,7 @@ try_get_chargeback_state(ID, #st{chargebacks = CBs}) -> set_refund_state(ID, RefundSt, St = #st{refunds = Rs}) -> St#st{refunds = Rs#{ID => RefundSt}}. --spec get_origin(st() | undefined) -> - dmsl_domain_thrift:'InvoicePaymentRegistrationOrigin'() | undefined. +-spec get_origin(st() | undefined) -> dmsl_domain_thrift:'InvoicePaymentRegistrationOrigin'() | undefined. get_origin(#st{payment = #domain_InvoicePayment{registration_origin = Origin}}) -> Origin. @@ -3729,9 +3583,7 @@ get_refund_status(#domain_InvoicePaymentRefund{status = Status}) -> define_refund_cash(undefined, St) -> get_remaining_payment_balance(St); -define_refund_cash(?cash(_, SymCode) = Cash, #st{ - payment = #domain_InvoicePayment{cost = ?cash(_, SymCode)} -}) -> +define_refund_cash(?cash(_, SymCode) = Cash, #st{payment = #domain_InvoicePayment{cost = ?cash(_, SymCode)}}) -> Cash; define_refund_cash(?cash(_, SymCode), _St) -> throw(#payproc_InconsistentRefundCurrency{currency = SymCode}). @@ -3794,9 +3646,7 @@ update_session(Target, Session, St = #st{sessions = Sessions}) -> get_target(#st{target = Target}) -> Target. -get_target_type({Type, _}) when - Type == 'processed'; Type == 'captured'; Type == 'cancelled'; Type == 'refunded' --> +get_target_type({Type, _}) when Type == 'processed'; Type == 'captured'; Type == 'cancelled'; Type == 'refunded' -> Type. get_recurrent_token(#st{recurrent_token = Token}) -> @@ -3839,9 +3689,7 @@ get_route_provider(Route, Revision) -> hg_domain:get(Revision, {provider, get_route_provider_ref(Route)}). inspect(Payment = #domain_InvoicePayment{domain_revision = Revision}, PaymentInstitution, Opts) -> - InspectorRef = get_selector_value( - inspector, PaymentInstitution#domain_PaymentInstitution.inspector - ), + InspectorRef = get_selector_value(inspector, PaymentInstitution#domain_PaymentInstitution.inspector), Inspector = hg_domain:get(Revision, {inspector, InspectorRef}), hg_inspector:inspect(get_shop(Opts, Revision), get_invoice(Opts), Payment, Inspector). @@ -4037,9 +3885,7 @@ is_route_cascade_available( get_route_cascade_behaviour(Route, Revision) -> ProviderRef = get_route_provider(Route), - #domain_Provider{cascade_behaviour = Behaviour} = hg_domain:get( - Revision, {provider, ProviderRef} - ), + #domain_Provider{cascade_behaviour = Behaviour} = hg_domain:get(Revision, {provider, ProviderRef}), Behaviour. -ifdef(TEST). @@ -4090,14 +3936,11 @@ filter_attempted_routes_test_() -> ) ), ?_assertMatch( - #{candidates := []}, - filter_attempted_routes(hg_routing_ctx:new([]), #st{activity = idle, routes = []}) + #{candidates := []}, filter_attempted_routes(hg_routing_ctx:new([]), #st{activity = idle, routes = []}) ), ?_assertMatch( #{candidates := [R1, R2, R3]}, - filter_attempted_routes(hg_routing_ctx:new([R1, R2, R3]), #st{ - activity = idle, routes = [] - }) + filter_attempted_routes(hg_routing_ctx:new([R1, R2, R3]), #st{activity = idle, routes = []}) ), ?_assertMatch( #{candidates := [R1, R2]}, diff --git a/apps/hellgate/src/hg_invoice_payment_chargeback.erl b/apps/hellgate/src/hg_invoice_payment_chargeback.erl index 4195579e..927d6c62 100644 --- a/apps/hellgate/src/hg_invoice_payment_chargeback.erl +++ b/apps/hellgate/src/hg_invoice_payment_chargeback.erl @@ -361,8 +361,7 @@ finalise(State = #chargeback_st{target_status = Status}, Action, Opts) when _ = commit_cash_flow(State, Opts), {[?chargeback_status_changed(Status)], Action}. --spec build_chargeback(opts(), create_params(), revision(), timestamp()) -> - chargeback() | no_return(). +-spec build_chargeback(opts(), create_params(), revision(), timestamp()) -> chargeback() | no_return(). build_chargeback(Opts, Params = ?chargeback_params(Levy, Body, Reason), Revision, CreatedAt) -> Revision = hg_domain:head(), #domain_InvoicePaymentChargeback{ @@ -413,9 +412,7 @@ build_reopen_result(State, ?reopen_params(ParamsLevy, ParamsBody) = Params) -> {Changes, Action}. -spec build_chargeback_final_cash_flow(state(), opts()) -> final_cash_flow() | no_return(). -build_chargeback_final_cash_flow( - #chargeback_st{target_status = ?chargeback_status_cancelled()}, _Opts -) -> +build_chargeback_final_cash_flow(#chargeback_st{target_status = ?chargeback_status_cancelled()}, _Opts) -> []; build_chargeback_final_cash_flow(State, Opts) -> CreatedAt = get_created_at(State), @@ -436,9 +433,7 @@ build_chargeback_final_cash_flow(State, Opts) -> ProviderCashFlow = get_chargeback_provider_cash_flow(ProviderTerms), ProviderFees = collect_chargeback_provider_fees(ProviderTerms), PaymentInstitutionRef = Shop#domain_ShopConfig.payment_institution, - PaymentInst = hg_payment_institution:compute_payment_institution( - PaymentInstitutionRef, VS, Revision - ), + PaymentInst = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS, Revision), Provider = get_route_provider(Route, Revision), CollectAccountContext = #{ payment => Payment, @@ -544,9 +539,7 @@ collect_validation_varset( validate_eligibility_time(#domain_PaymentChargebackServiceTerms{eligibility_time = undefined}) -> ok; -validate_eligibility_time(#domain_PaymentChargebackServiceTerms{ - eligibility_time = {value, EligibilityTime} -}) -> +validate_eligibility_time(#domain_PaymentChargebackServiceTerms{eligibility_time = {value, EligibilityTime}}) -> Now = hg_datetime:format_now(), EligibleUntil = hg_datetime:add_time_span(EligibilityTime, Now), case hg_datetime:compare(Now, EligibleUntil) of @@ -591,9 +584,7 @@ validate_not_arbitration(#domain_InvoicePaymentChargeback{}) -> validate_chargeback_is_pending(#chargeback_st{chargeback = Chargeback}) -> validate_chargeback_is_pending(Chargeback); -validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{ - status = ?chargeback_status_pending() -}) -> +validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{status = ?chargeback_status_pending()}) -> ok; validate_chargeback_is_pending(#domain_InvoicePaymentChargeback{status = Status}) -> throw(#payproc_InvoicePaymentChargebackInvalidStatus{status = Status}). @@ -660,8 +651,7 @@ get_reopen_stage(#domain_InvoicePaymentChargeback{stage = CurrentStage} = Charge throw(#payproc_InvoicePaymentChargebackInvalidStage{stage = CurrentStage}) end. --spec get_next_stage(chargeback()) -> - ?chargeback_stage_pre_arbitration() | ?chargeback_stage_arbitration(). +-spec get_next_stage(chargeback()) -> ?chargeback_stage_pre_arbitration() | ?chargeback_stage_arbitration(). get_next_stage(#domain_InvoicePaymentChargeback{stage = ?chargeback_stage_chargeback()}) -> ?chargeback_stage_pre_arbitration(); get_next_stage(#domain_InvoicePaymentChargeback{stage = ?chargeback_stage_pre_arbitration()}) -> diff --git a/apps/hellgate/src/hg_invoice_payment_refund.erl b/apps/hellgate/src/hg_invoice_payment_refund.erl index 3258f4e5..6a12ac36 100644 --- a/apps/hellgate/src/hg_invoice_payment_refund.erl +++ b/apps/hellgate/src/hg_invoice_payment_refund.erl @@ -251,9 +251,7 @@ do_deduce_activity(#{status := pending, failure := _Failure}) -> failure; do_deduce_activity(#{status := pending, sessions := []}) -> new; -do_deduce_activity(#{ - status := pending, session_status := finished, session_result := {succeeded, _} -}) -> +do_deduce_activity(#{status := pending, session_status := finished, session_result := {succeeded, _}}) -> accounter; do_deduce_activity(#{status := pending, session_status := finished, session_result := {failed, _}}) -> failure; @@ -373,10 +371,7 @@ rollback_refund_limits(Refund) -> get_limits(Refund) -> Revision = revision(Refund), ProviderTerms = get_provider_terms( - Revision, - get_injected_payment(Refund), - get_injected_invoice(Refund), - Refund + Revision, get_injected_payment(Refund), get_injected_invoice(Refund), get_injected_party(Refund), Refund ), get_turnover_limits(ProviderTerms). @@ -526,10 +521,8 @@ get_injected_shop(#{injected_context := #{shop := 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). -get_injected_payment_info(#{injected_context := Context}) -> - maps:get(payment_info, Context, undefined). +get_injected_repair_scenario(#{injected_context := Context}) -> maps:get(repair_scenario, Context, undefined). +get_injected_payment_info(#{injected_context := Context}) -> maps:get(payment_info, Context, undefined). %% Event utils @@ -563,14 +556,10 @@ apply_event(?refund_created(Refund, Cashflow, TransactionInfo), undefined, Conte }); apply_event(?refund_status_changed(Status = {StatusTag, _}), Refund, _Context) -> DomainRefund = refund(Refund), - Refund#{ - status := StatusTag, refund := DomainRefund#domain_InvoicePaymentRefund{status = Status} - }; + Refund#{status := StatusTag, refund := DomainRefund#domain_InvoicePaymentRefund{status = Status}}; apply_event(?refund_rollback_started(Failure), Refund, _Context) -> Refund#{failure => Failure}; -apply_event( - ?session_ev(?refunded(), Event = ?session_started()), Refund = #{session_context := Context}, _ -) -> +apply_event(?session_ev(?refunded(), Event = ?session_started()), Refund = #{session_context := Context}, _) -> Session = hg_session:apply_event(Event, undefined, Context), add_refund_session(Session, Refund); apply_event(?session_ev(?refunded(), Event), Refund = #{session_context := Context}, _) -> diff --git a/apps/hellgate/src/hg_invoice_registered_payment.erl b/apps/hellgate/src/hg_invoice_registered_payment.erl index 321a3c80..613ff759 100644 --- a/apps/hellgate/src/hg_invoice_registered_payment.erl +++ b/apps/hellgate/src/hg_invoice_registered_payment.erl @@ -54,9 +54,7 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt0}) -> PaymentTool = get_payer_payment_tool(Payer), 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 - ), + PaymentInstitution = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS, Revision), Payment = construct_payment( PaymentID, @@ -83,9 +81,7 @@ init_(PaymentID, Params, Opts = #{timestamp := CreatedAt0}) -> varset => VS, revision => Revision }, - FinalCashflow = hg_invoice_payment:calculate_cashflow( - PaymentInstitution, CashflowContext, Opts - ), + FinalCashflow = hg_invoice_payment:calculate_cashflow(PaymentInstitution, CashflowContext, Opts), Events = [ @@ -170,9 +166,7 @@ process_processing_capture(Action, St) -> ok = hold_payment_cashflow(St), Events = [ hg_session:wrap_event(?captured(?CAPTURE_REASON, Cost), hg_session:create()), - hg_session:wrap_event( - ?captured(?CAPTURE_REASON, Cost), ?session_finished(?session_succeeded()) - ) + hg_session:wrap_event(?captured(?CAPTURE_REASON, Cost), ?session_finished(?session_succeeded())) ], {next, {Events, hg_machine_action:set_timeout(0, Action)}}. diff --git a/apps/hellgate/src/hg_invoice_template.erl b/apps/hellgate/src/hg_invoice_template.erl index 7d28f9b1..df6f1c69 100644 --- a/apps/hellgate/src/hg_invoice_template.erl +++ b/apps/hellgate/src/hg_invoice_template.erl @@ -47,8 +47,7 @@ get_invoice_template(ID) -> %% Woody handler --spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> - term() | no_return(). +-spec handle_function(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). handle_function(Func, Args, Opts) -> scoper:scope( invoice_templating, @@ -57,8 +56,7 @@ handle_function(Func, Args, Opts) -> end ). --spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> - term() | no_return(). +-spec handle_function_(woody:func(), woody:args(), hg_woody_service_wrapper:handler_opts()) -> term() | no_return(). handle_function_('Create', {Params}, _Opts) -> TplID = Params#payproc_InvoiceTemplateCreateParams.template_id, _ = set_meta(TplID), @@ -137,16 +135,12 @@ get_shop(ShopConfigRef, PartyConfigRef) -> set_meta(ID) -> scoper:add_meta(#{invoice_template_id => ID}). -validate_create_params( - #payproc_InvoiceTemplateCreateParams{details = Details, mutations = Mutations}, Shop -) -> +validate_create_params(#payproc_InvoiceTemplateCreateParams{details = Details, mutations = Mutations}, Shop) -> ok = validate_details(Details, Mutations, Shop). validate_update_params(#payproc_InvoiceTemplateUpdateParams{details = undefined}, _) -> ok; -validate_update_params( - #payproc_InvoiceTemplateUpdateParams{details = Details, mutations = Mutations}, Shop -) -> +validate_update_params(#payproc_InvoiceTemplateUpdateParams{details = Details, mutations = Mutations}, Shop) -> ok = validate_details(Details, Mutations, Shop). validate_details({cart, #domain_InvoiceCart{}} = Details, Mutations, _) -> diff --git a/apps/hellgate/src/hg_limiter.erl b/apps/hellgate/src/hg_limiter.erl index 04e0eeb7..a0af074b 100644 --- a/apps/hellgate/src/hg_limiter.erl +++ b/apps/hellgate/src/hg_limiter.erl @@ -50,13 +50,10 @@ get_turnover_limits({value, Limits}) -> get_turnover_limits(Ambiguous) -> error({misconfiguration, {'Could not reduce selector to a value', Ambiguous}}). --spec get_limit_values([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> - [turnover_limit_value()]. +-spec get_limit_values([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> [turnover_limit_value()]. get_limit_values(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - get_limit_values( - Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) - ). + get_limit_values(Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)). make_route_operation_segments(Invoice, Payment, ?route(ProviderRef, TerminalRef), Iter) -> [ @@ -68,9 +65,7 @@ make_route_operation_segments(Invoice, Payment, ?route(ProviderRef, TerminalRef) ]. get_limit_values(Context, TurnoverLimits, OperationIdSegments) -> - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), get_legacy_limit_values(Context, LegacyTurnoverLimits) ++ get_batch_limit_values(Context, BatchTurnoverLimits, OperationIdSegments). @@ -103,9 +98,7 @@ get_batch_limit_values(Context, TurnoverLimits, OperationIdSegments) -> | {error, {limit_overflow, [binary()], [turnover_limit_value()]}}. check_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - Limits = get_limit_values( - Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) - ), + Limits = get_limit_values(Context, TurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)), try ok = check_limits_(Limits, Context), {ok, Limits} @@ -168,13 +161,9 @@ check_limits_([TurnoverLimitValue | TLVs], Context) -> -spec hold_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer()) -> ok. hold_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> Context = gen_limit_context(Invoice, Payment, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), ok = legacy_hold_payment_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter), - ok = batch_hold_limits( - Context, BatchTurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter) - ). + ok = batch_hold_limits(Context, BatchTurnoverLimits, make_route_operation_segments(Invoice, Payment, Route, Iter)). legacy_hold_payment_limits(Context, TurnoverLimits, Invoice, Payment, Route, Iter) -> ChangeIDs = [construct_payment_change_id(Route, Iter, Invoice, Payment)], @@ -213,13 +202,9 @@ legacy_hold_shop_limits(Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, -spec hold_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. hold_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), ok = legacy_hold_refund_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Refund), - ok = batch_hold_limits( - Context, BatchTurnoverLimits, make_refund_operation_segments(Invoice, Payment, Refund) - ). + ok = batch_hold_limits(Context, BatchTurnoverLimits, make_refund_operation_segments(Invoice, Payment, Refund)). make_refund_operation_segments(Invoice, Payment, Refund) -> [ @@ -233,18 +218,12 @@ legacy_hold_refund_limits(Context, TurnoverLimits, Invoice, Payment, Refund) -> LimitChanges = gen_limit_changes(TurnoverLimits, ChangeIDs), hold(LimitChanges, get_latest_clock(), Context). --spec commit_payment_limits( - [turnover_limit()], invoice(), payment(), route(), pos_integer(), cash() | undefined -) -> ok. +-spec commit_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), cash() | undefined) -> ok. commit_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, CapturedCash) -> Context = gen_limit_context(Invoice, Payment, Route, CapturedCash), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), Clock = get_latest_clock(), - ok = legacy_commit_payment_limits( - Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter - ), + ok = legacy_commit_payment_limits(Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter), OperationIdSegments = make_route_operation_segments(Invoice, Payment, Route, Iter), ok = batch_commit_limits(Context, BatchTurnoverLimits, OperationIdSegments), ok = log_limit_changes(TurnoverLimits, Clock, Context). @@ -268,9 +247,7 @@ legacy_commit_payment_limits(Clock, Context, TurnoverLimits, Invoice, Payment, R ) -> 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 - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), Clock = get_latest_clock(), ok = legacy_commit_shop_limits( Clock, Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment @@ -291,13 +268,9 @@ legacy_commit_shop_limits( -spec commit_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. commit_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), Clock = get_latest_clock(), - ok = legacy_commit_refund_limits( - Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Refund - ), + ok = legacy_commit_refund_limits(Clock, Context, LegacyTurnoverLimits, Invoice, Payment, Refund), OperationIdSegments = make_refund_operation_segments(Invoice, Payment, Refund), ok = batch_commit_limits(Context, BatchTurnoverLimits, OperationIdSegments), ok = log_limit_changes(TurnoverLimits, Clock, Context). @@ -315,18 +288,12 @@ legacy_commit_refund_limits(Clock, Context, TurnoverLimits, Invoice, Payment, Re %% %% - `ignore_not_found` -- does not raise error if limiter won't be able to %% find according posting plan in accountant service --spec rollback_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), [ - handling_flag() -]) -> +-spec rollback_payment_limits([turnover_limit()], invoice(), payment(), route(), pos_integer(), [handling_flag()]) -> ok. rollback_payment_limits(TurnoverLimits, Invoice, Payment, Route, Iter, Flags) -> Context = gen_limit_context(Invoice, Payment, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), - ok = legacy_rollback_payment_limits( - Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter, Flags - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + ok = legacy_rollback_payment_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Route, Iter, Flags), OperationIdSegments = make_route_operation_segments(Invoice, Payment, Route, Iter), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). @@ -373,9 +340,7 @@ legacy_rollback_shop_limits( -spec rollback_refund_limits([turnover_limit()], invoice(), payment(), refund(), route()) -> ok. rollback_refund_limits(TurnoverLimits, Invoice, Payment, Refund, Route) -> Context = gen_limit_refund_context(Invoice, Payment, Refund, Route), - {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api( - TurnoverLimits - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), ok = legacy_rollback_refund_limits(Context, LegacyTurnoverLimits, Invoice, Payment, Refund), OperationIdSegments = make_refund_operation_segments(Invoice, Payment, Refund), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). @@ -393,9 +358,7 @@ hold(LimitChanges, Clock, Context) -> commit(LimitChanges, Clock, Context) -> process_changes(LimitChanges, fun hg_limiter_client:commit/3, Clock, Context, []). --spec rollback([change_queue()], hg_limiter_client:clock(), hg_limiter_client:context(), [ - handling_flag() -]) -> ok. +-spec rollback([change_queue()], hg_limiter_client:clock(), hg_limiter_client:context(), [handling_flag()]) -> ok. rollback(LimitChanges, Clock, Context, Flags) -> process_changes(LimitChanges, fun hg_limiter_client:rollback/3, Clock, Context, Flags). @@ -408,9 +371,7 @@ process_changes(LimitChangesQueues, WithFun, Clock, Context, Flags) -> ). %% Very specific error to crutch around --define(POSTING_PLAN_NOT_FOUND(ID), #base_InvalidRequest{ - errors = [<<"Posting plan not found: ", ID/binary>>] -}). +-define(POSTING_PLAN_NOT_FOUND(ID), #base_InvalidRequest{errors = [<<"Posting plan not found: ", ID/binary>>]}). process_changes_try_wrap([LimitChange], WithFun, Clock, Context, Flags) -> IgnoreNotFound = lists:member(ignore_not_found, Flags), @@ -434,16 +395,11 @@ process_changes_try_wrap([LimitChange | OtherLimitChanges], WithFun, Clock, Cont handle_caught_exception(Class, Reason, Stacktrace, IgnoreBusinessError) end. -handle_caught_exception(error, #limiter_LimitNotFound{}, _Stacktrace, true) -> - ok; -handle_caught_exception(error, #limiter_InvalidOperationCurrency{}, _Stacktrace, true) -> - ok; -handle_caught_exception(error, #limiter_OperationContextNotSupported{}, _Stacktrace, true) -> - ok; -handle_caught_exception(error, #limiter_PaymentToolNotSupported{}, _Stacktrace, true) -> - ok; -handle_caught_exception(Class, Reason, Stacktrace, _IgnoreBusinessError) -> - erlang:raise(Class, Reason, Stacktrace). +handle_caught_exception(error, #limiter_LimitNotFound{}, _Stacktrace, true) -> ok; +handle_caught_exception(error, #limiter_InvalidOperationCurrency{}, _Stacktrace, true) -> ok; +handle_caught_exception(error, #limiter_OperationContextNotSupported{}, _Stacktrace, true) -> ok; +handle_caught_exception(error, #limiter_PaymentToolNotSupported{}, _Stacktrace, true) -> ok; +handle_caught_exception(Class, Reason, Stacktrace, _IgnoreBusinessError) -> erlang:raise(Class, Reason, Stacktrace). gen_limit_context(Invoice, Payment, Route) -> gen_limit_context(Invoice, Payment, Route, undefined). @@ -572,14 +528,8 @@ convert_to_limit_route(#domain_PaymentRoute{provider = Provider, terminal = Term log_limit_changes(TurnoverLimits, Clock, Context) -> Attrs = mk_limit_log_attributes(Context), lists:foreach( - fun( - #domain_TurnoverLimit{ - id = ID, upper_boundary = UpperBoundary, domain_revision = DomainRevision - } - ) -> - #limiter_Limit{amount = LimitAmount} = hg_limiter_client:get( - ID, DomainRevision, Clock, Context - ), + fun(#domain_TurnoverLimit{id = ID, upper_boundary = UpperBoundary, domain_revision = DomainRevision}) -> + #limiter_Limit{amount = LimitAmount} = hg_limiter_client:get(ID, DomainRevision, Clock, Context), ok = logger:log(notice, "Limit change commited", [], #{ limit => Attrs#{config_id => ID, boundary => UpperBoundary, amount => LimitAmount} }) @@ -632,9 +582,7 @@ maybe_route_context(#base_Route{provider = Provider, terminal = Terminal}) -> }. split_turnover_limits_by_available_limiter_api(TurnoverLimits) -> - lists:partition( - fun(#domain_TurnoverLimit{domain_revision = V}) -> V =:= undefined end, TurnoverLimits - ). + lists:partition(fun(#domain_TurnoverLimit{domain_revision = V}) -> V =:= undefined end, TurnoverLimits). prepare_limit_request(TurnoverLimits, IdSegments) -> {TurnoverLimitsIdList, LimitChanges} = lists:unzip( diff --git a/apps/hellgate/test/hg_ct_domain.hrl b/apps/hellgate/test/hg_ct_domain.hrl index 6e8911c2..c911c87c 100644 --- a/apps/hellgate/test/hg_ct_domain.hrl +++ b/apps/hellgate/test/hg_ct_domain.hrl @@ -34,9 +34,7 @@ -define(crypta(ID), #domain_CryptoCurrencyRef{id = ID}). -define(token_srv(ID), #domain_BankCardTokenServiceRef{id = ID}). -define(bank_card(ID), #domain_BankCardPaymentMethod{payment_system = ?pmt_sys(ID)}). --define(bank_card_no_cvv(ID), #domain_BankCardPaymentMethod{ - payment_system = ?pmt_sys(ID), is_cvv_empty = true -}). +-define(bank_card_no_cvv(ID), #domain_BankCardPaymentMethod{payment_system = ?pmt_sys(ID), is_cvv_empty = true}). -define(token_bank_card(ID, Prv), ?token_bank_card(ID, Prv, dpan)). -define(token_bank_card(ID, Prv, Method), #domain_BankCardPaymentMethod{ payment_system = ?pmt_sys(ID), @@ -88,32 +86,12 @@ -define(contact_info(EMail, Phone), ?contact_info( - EMail, - Phone, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined + EMail, Phone, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined ) ). -define(contact_info( - EMail, - Phone, - FirstName, - LastName, - Country, - State, - City, - Address, - PostalCode, - DateOfBirth, - DocumentId + EMail, Phone, FirstName, LastName, Country, State, City, Address, PostalCode, DateOfBirth, DocumentId ), #domain_ContactInfo{ email = EMail, diff --git a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl index 72fa075c..8a1b3be8 100644 --- a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl +++ b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl @@ -207,9 +207,7 @@ another_shop_test(C) -> Invoice2ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(Invoice1ID, Payment1ID), Payment2Params = make_recurrent_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{ - details = <<"Parent payment refer to another shop">> - }, + ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment refer to another shop">>}, {error, ExpectedError} = start_payment(Invoice2ID, Payment2Params, Client). -spec not_recurring_first_test(config()) -> test_result(). @@ -224,9 +222,7 @@ not_recurring_first_test(C) -> Invoice2ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(Invoice1ID, Payment1ID), Payment2Params = make_recurrent_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{ - details = <<"Parent payment has no recurrent token">> - }, + ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment has no recurrent token">>}, {error, ExpectedError} = start_payment(Invoice2ID, Payment2Params, Client). -spec cancelled_first_payment_test(config()) -> test_result(). @@ -263,9 +259,7 @@ not_exists_invoice_test(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(<<"not_exists">>, <<"not_exists">>), PaymentParams = make_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{ - details = <<"Parent invoice not found">> - }, + ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent invoice not found">>}, {error, ExpectedError} = start_payment(InvoiceID, PaymentParams, Client). -spec not_exists_payment_test(config()) -> test_result(). @@ -274,9 +268,7 @@ not_exists_payment_test(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), RecurrentParent = ?recurrent_parent(InvoiceID, <<"not_exists">>), PaymentParams = make_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)), - ExpectedError = #payproc_InvalidRecurrentParentPayment{ - details = <<"Parent payment not found">> - }, + ExpectedError = #payproc_InvalidRecurrentParentPayment{details = <<"Parent payment not found">>}, {error, ExpectedError} = start_payment(InvoiceID, PaymentParams, Client). %% Internal functions @@ -337,9 +329,7 @@ make_payment_params(FlowType, MakeRecurrent, RecurrentParent, PmtSys) -> make_payment_params(PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent). make_payment_params(PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent) -> - make_payment_params( - #domain_ClientInfo{}, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent - ). + make_payment_params(#domain_ClientInfo{}, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent). make_payment_params(ClientInfo, PaymentTool, Session, FlowType, MakeRecurrent, RecurrentParent) -> Flow = @@ -376,9 +366,7 @@ make_recurrent_payment_params(MakeRecurrent, RecurrentParent, PmtSys) -> make_recurrent_payment_params(FlowType, MakeRecurrent, RecurrentParent, PmtSys) -> {PaymentTool, _Session} = hg_dummy_provider:make_payment_tool(no_preauth, PmtSys), - make_payment_params( - undefined, PaymentTool, undefined, FlowType, MakeRecurrent, RecurrentParent - ). + make_payment_params(undefined, PaymentTool, undefined, FlowType, MakeRecurrent, RecurrentParent). make_due_date(LifetimeSeconds) -> genlib_time:unow() + LifetimeSeconds. @@ -394,9 +382,7 @@ start_invoice(ShopConfigRef, Product, Due, Amount, C) -> PartyConfigRef, ShopConfigRef, Product, Due, Cash ), InvoiceID = create_invoice(InvoiceParams, Client), - _Events = await_events( - InvoiceID, [?evp(?invoice_created(?invoice_w_status(?invoice_unpaid())))], Client - ), + _Events = await_events(InvoiceID, [?evp(?invoice_created(?invoice_w_status(?invoice_unpaid())))], Client), InvoiceID. start_payment(InvoiceID, PaymentParams, Client) -> @@ -450,9 +436,7 @@ do_await_events(_InvoiceID, Filters, _Timeout, _Client, timeout, MatchedEvents) do_await_events(InvoiceID, Filters, Timeout, Client, [], MatchedEvents) -> NewEvents = next_event(InvoiceID, Timeout, Client), do_await_events(InvoiceID, Filters, Timeout, Client, NewEvents, MatchedEvents); -do_await_events( - InvoiceID, [FilterFn | FTail] = Filters, Timeout, Client, [Ev | EvTail], MatchedEvents -) -> +do_await_events(InvoiceID, [FilterFn | FTail] = Filters, Timeout, Client, [Ev | EvTail], MatchedEvents) -> case FilterFn(Ev) of true -> do_await_events(InvoiceID, FTail, Timeout, Client, EvTail, [Ev | MatchedEvents]); @@ -551,9 +535,7 @@ construct_domain_fixture(TermSet) -> hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ - <<"risk_score">> => <<"low">> - }), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"low">>}), hg_ct_fixture:construct_system_account_set(?sas(1)), hg_ct_fixture:construct_external_account_set(?eas(1)), @@ -655,9 +637,7 @@ construct_domain_fixture(TermSet) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -687,7 +667,5 @@ construct_domain_fixture(TermSet) -> }}, hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), - hg_ct_fixture:construct_payment_system( - ?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">> - ) + hg_ct_fixture:construct_payment_system(?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">>) ]. diff --git a/apps/hellgate/test/hg_invoice_helper.erl b/apps/hellgate/test/hg_invoice_helper.erl index ac707522..58765260 100644 --- a/apps/hellgate/test/hg_invoice_helper.erl +++ b/apps/hellgate/test/hg_invoice_helper.erl @@ -252,9 +252,7 @@ register_payment(InvoiceID, RegisterPaymentParams, WithRiskScoring, Client) -> -spec start_payment(_, _, _) -> _. start_payment(InvoiceID, PaymentParams, Client) -> - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), _ = start_payment_ev(InvoiceID, Client), ?payment_ev(PaymentID, ?cash_flow_changed(_)) = next_change(InvoiceID, Client), @@ -303,9 +301,7 @@ await_payment_capture(InvoiceID, PaymentID, Reason, TrxID, Client) -> ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), TrxID =/= undefined andalso - (?payment_ev( - PaymentID, ?session_ev(?captured(Reason, Cost, _Cart, _), ?trx_bound(?trx_info(TrxID))) - ) = + (?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, _Cart, _), ?trx_bound(?trx_info(TrxID)))) = next_change(InvoiceID, Client)), await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client). @@ -328,10 +324,7 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client) -> -spec await_payment_capture_finish(_, _, _, _, _, _) -> _. await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client) -> [ - ?payment_ev( - PaymentID, - ?session_ev(?captured(Reason, Cost, Cart, _), ?session_finished(?session_succeeded())) - ), + ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, Cart, _), ?session_finished(?session_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?captured(Reason, Cost, Cart, _))), ?invoice_status_changed(?invoice_paid()) ] = next_changes(InvoiceID, 3, Client), diff --git a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl index 6771601e..3157ff58 100644 --- a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl @@ -117,9 +117,7 @@ init_per_suite(C) -> {apps, Apps} | C ], - ok = hg_invoice_helper:start_proxies([ - {hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC} - ]), + ok = hg_invoice_helper:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]), NewC. -spec end_per_suite(config()) -> _. @@ -259,9 +257,7 @@ payment_success(C) -> payment_w_first_blacklisted_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - inspector_fail_first, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(inspector_fail_first, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = process_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), @@ -284,21 +280,16 @@ payment_w_first_blacklisted_success(C) -> ] } = hg_client_invoicing:explain_route(InvoiceID, PaymentID, Client), ?assertEqual( - <<"Route was blacklisted {domain_PaymentRoute,{domain_ProviderRef,1},{domain_TerminalRef,1}}.">>, - Desc + <<"Route was blacklisted {domain_PaymentRoute,{domain_ProviderRef,1},{domain_TerminalRef,1}}.">>, Desc ). -spec payment_w_all_blacklisted(config()) -> test_return(). payment_w_all_blacklisted(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - inspector_fail_all, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(inspector_fail_all, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -321,9 +312,7 @@ register_payment_success(C) -> data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) }, PayerSessionInfo = #domain_PayerSessionInfo{}, - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), Route = ?route(?prv(1), ?trm(1)), Cost = ?cash(41999, <<"RUB">>), ID = hg_utils:unique_id(), @@ -378,9 +367,7 @@ register_payment_success(C) -> payment_success_additional_info(C) -> Client = hg_ct_helper:cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - empty_cvv, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -413,9 +400,7 @@ payment_w_mobile_commerce(C, Expectation) -> Client = cfg(client, C), PayCash = 1001, InvoiceID = start_invoice(<<"oatmeal">>, make_due_date(10), PayCash, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - {mobile_commerce, Expectation}, ?mob(<<"mts-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool({mobile_commerce, Expectation}, ?mob(<<"mts-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = @@ -425,9 +410,7 @@ payment_w_mobile_commerce(C, Expectation) -> case Expectation of success -> [ - ?payment_ev( - PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) - ), + ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?processed())) ] = next_changes(InvoiceID, 2, Client); @@ -435,9 +418,7 @@ payment_w_mobile_commerce(C, Expectation) -> [ ?payment_ev( PaymentID, - ?session_ev( - ?processed(), ?session_finished(?session_failed({failure, Failure})) - ) + ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) ), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) @@ -450,9 +431,7 @@ payment_w_crypto_currency_success(C) -> Client = cfg(client, C), PayCash = 2000, InvoiceID = start_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - crypto_currency, ?crypta(<<"bitcoin-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(crypto_currency, ?crypta(<<"bitcoin-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), ?payment_state(#domain_InvoicePayment{ id = PaymentID, @@ -462,16 +441,10 @@ payment_w_crypto_currency_success(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(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 - ). + CFContext = construct_ta_context(PartyID, ShopID, 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). -spec payment_w_wallet_success(config()) -> _ | no_return(). payment_w_wallet_success(C) -> @@ -488,9 +461,7 @@ payment_w_wallet_success(C) -> payment_success_empty_cvv(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - empty_cvv, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -753,9 +724,7 @@ construct_domain_fixture() -> hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ - <<"risk_score">> => <<"trusted">> - }), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"trusted">>}), hg_ct_fixture:construct_system_account_set(?sas(1)), hg_ct_fixture:construct_external_account_set(?eas(1)), @@ -884,9 +853,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -952,9 +919,7 @@ construct_domain_fixture() -> }}, hg_ct_fixture:construct_mobile_operator(?mob(<<"mts-ref">>), <<"mts mobile operator">>), - hg_ct_fixture:construct_payment_service( - ?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">> - ), + hg_ct_fixture:construct_payment_service(?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">>), hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), hg_ct_fixture:construct_crypto_currency(?crypta(<<"bitcoin-ref">>), <<"bitcoin currency">>) ]. diff --git a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl index 1e03a3ea..abd273a5 100644 --- a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl +++ b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl @@ -173,18 +173,9 @@ mock_dominant(SupPid) -> _ = hg_mock_helper:mock_dominant( [ {'RepositoryClient', fun - ( - 'CheckoutObject', - {{version, ?routing_with_fail_rate_domain_revision = Version}, ObjectRef} - ) -> + ('CheckoutObject', {{version, ?routing_with_fail_rate_domain_revision = Version}, ObjectRef}) -> Getter(Version, ObjectRef, RoutingWithFailRateDomain); - ( - 'CheckoutObject', - { - {version, ?routing_with_risk_coverage_set_domain_revision = Version}, - ObjectRef - } - ) -> + ('CheckoutObject', {{version, ?routing_with_risk_coverage_set_domain_revision = Version}, ObjectRef}) -> Getter(Version, ObjectRef, RoutingWithRiskCoverageSetDomain); ('CheckoutObject', {{version, Version}, ObjectRef}) -> Getter(Version, ObjectRef, Domain) @@ -260,22 +251,8 @@ mock_party_management(SupPid) -> 0, ?pin([currency, payment_tool, email, card_token, client_ip]) ), - ?candidate( - <<"">>, - {constant, true}, - ?trm(2), - 0, - 0, - ?pin([currency, payment_tool]) - ), - ?candidate( - <<"">>, - {constant, true}, - ?trm(3), - 0, - 0, - ?pin([currency, payment_tool]) - ) + ?candidate(<<"">>, {constant, true}, ?trm(2), 0, 0, ?pin([currency, payment_tool])), + ?candidate(<<"">>, {constant, true}, ?trm(3), 0, 0, ?pin([currency, payment_tool])) ]} }}; ('ComputeRoutingRuleset', {?ruleset(2), DomainRevision, _}) when @@ -338,10 +315,7 @@ mock_party_management(SupPid) -> name = <<"No prohibition: all candidate is allowed">>, decisions = {candidates, []} }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(2), _, ?base_routing_rule_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(2), _, ?base_routing_rule_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ categories = @@ -357,10 +331,7 @@ mock_party_management(SupPid) -> ])} } }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(3), _, ?base_routing_rule_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(3), _, ?base_routing_rule_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ payment_methods = @@ -376,38 +347,26 @@ mock_party_management(SupPid) -> ])} } }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(4), _, ?base_routing_rule_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(4), _, ?base_routing_rule_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ allow = {constant, false} } }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(7), _, ?base_routing_rule_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(7), _, ?base_routing_rule_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ allow = {constant, true}, global_allow = {constant, false} } }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(1), _, ?routing_with_risk_coverage_set_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(1), _, ?routing_with_risk_coverage_set_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ risk_coverage = {value, low} } }}; - ( - 'ComputeProviderTerminalTerms', - {?prv(2), _, ?routing_with_risk_coverage_set_domain_revision, _} - ) -> + ('ComputeProviderTerminalTerms', {?prv(2), _, ?routing_with_risk_coverage_set_domain_revision, _}) -> {ok, #domain_ProvisionTermSet{ payments = PaymentTerms#domain_PaymentsProvisionTerms{ risk_coverage = {value, high} @@ -496,8 +455,7 @@ mock_fault_detector(SupPid) -> -spec no_route_found_for_payment(config()) -> test_return(). no_route_found_for_payment(_C) -> Currency0 = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency0, @@ -555,8 +513,7 @@ no_route_found_for_payment(_C) -> -spec gather_route_success(config()) -> test_return(). gather_route_success(_C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency, @@ -659,9 +616,7 @@ empty_candidate_ok(_C) -> }, ?assertMatch( {ok, {[], []}}, - unwrap_routing_context( - hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx) - ) + unwrap_routing_context(hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx)) ). -spec ruleset_misconfig(config()) -> test_return(). @@ -676,17 +631,12 @@ ruleset_misconfig(_C) -> Ctx = #{ currency => ?cur(<<"RUB">>), - payment_tool => - {payment_terminal, #domain_PaymentTerminal{ - payment_service = ?pmt_srv(<<"euroset-ref">>) - }}, + payment_tool => {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, client_ip => undefined }, ?assertMatch( {misconfiguration, {routing_decisions, {delegates, []}}}, - hg_routing_ctx:error( - hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx) - ) + hg_routing_ctx:error(hg_routing:gather_routes(payment, PaymentInstitution, VS, Revision, Ctx)) ). -spec routes_selected_for_low_risk_score(config()) -> test_return(). @@ -699,8 +649,7 @@ routes_selected_for_high_risk_score(C) -> routes_selected_with_risk_score(_C, RiskScore, ProviderRefs) -> Currency = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency, @@ -760,14 +709,12 @@ empty_terms_allow_test(_C) -> -spec not_reduced_terms_allow_test(config()) -> test_return(). not_reduced_terms_allow_test(_C) -> - Error = - {'Misconfiguration', {'Could not reduce predicate to a value', {allow, {all_of, [{constant, false}]}}}}, + Error = {'Misconfiguration', {'Could not reduce predicate to a value', {allow, {all_of, [{constant, false}]}}}}, do_gather_routes(?not_reduced_allow_revision, undefined, [{?prv(6), ?trm(6), Error}]). do_gather_routes(Revision, ExpectedRouteTerminal, ExpectedRejectedRoutes) -> Currency = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency, @@ -802,17 +749,12 @@ do_gather_routes(Revision, ExpectedRouteTerminal, ExpectedRejectedRoutes) -> terminal_priority_for_shop(C) -> Route1 = hg_route:new(?prv(11), ?trm(11), 0, 10), Route2 = hg_route:new(?prv(12), ?trm(12), 0, 10), - ?assertMatch( - {Route1, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_1, C) - ), - ?assertMatch( - {Route2, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_2, C) - ). + ?assertMatch({Route1, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_1, C)), + ?assertMatch({Route2, _}, terminal_priority_for_shop(?shop_id_for_ruleset_w_priority_distribution_2, C)). terminal_priority_for_shop(ShopID, _C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency, @@ -837,8 +779,7 @@ terminal_priority_for_shop(ShopID, _C) -> -spec gather_pinned_route(config()) -> test_return(). gather_pinned_route(_C) -> Currency = ?cur(<<"RUB">>), - PaymentTool = - {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, + PaymentTool = {payment_terminal, #domain_PaymentTerminal{payment_service = ?pmt_srv(<<"euroset-ref">>)}}, VS = #{ category => ?cat(1), currency => Currency, @@ -888,9 +829,7 @@ choose_route_w_override(_C) -> } = hg_routing:choose_route(Routes), %% with overrides - Route3WithOV = hg_route:new( - ?prv(3), ?trm(3), 0, 1000, #{}, #domain_RouteFaultDetectorOverrides{enabled = true} - ), + Route3WithOV = hg_route:new(?prv(3), ?trm(3), 0, 1000, #{}, #domain_RouteFaultDetectorOverrides{enabled = true}), RoutesWithOV = [Route1, Route2, Route3WithOV], {Route3WithOV, _} = hg_routing:choose_route(RoutesWithOV). @@ -925,12 +864,9 @@ routing_with_risk_score_fixture(Domain, AddRiskScore) -> construct_domain_fixture() -> #{ - {provider, ?prv(1)} => - {provider, ?provider_obj(?prv(1), #domain_ProvisionTermSet{}, undefined)}, - {provider, ?prv(2)} => - {provider, ?provider_obj(?prv(2), #domain_ProvisionTermSet{}, ?fd_overrides(undefined))}, - {provider, ?prv(3)} => - {provider, ?provider_obj(?prv(3), #domain_ProvisionTermSet{}, ?fd_overrides(true))}, + {provider, ?prv(1)} => {provider, ?provider_obj(?prv(1), #domain_ProvisionTermSet{}, undefined)}, + {provider, ?prv(2)} => {provider, ?provider_obj(?prv(2), #domain_ProvisionTermSet{}, ?fd_overrides(undefined))}, + {provider, ?prv(3)} => {provider, ?provider_obj(?prv(3), #domain_ProvisionTermSet{}, ?fd_overrides(true))}, {provider, ?prv(4)} => {provider, ?provider_obj(?prv(4), #domain_ProvisionTermSet{})}, {provider, ?prv(5)} => {provider, ?provider_obj(?prv(5), #domain_ProvisionTermSet{})}, {provider, ?prv(6)} => {provider, ?provider_obj(?prv(6), #domain_ProvisionTermSet{})}, @@ -980,6 +916,4 @@ maybe_set_risk_coverage(true, V) -> {value, V}. unwrap_routing_context(RoutingCtx) -> - {ok, { - hg_routing_ctx:considered_candidates(RoutingCtx), hg_routing_ctx:rejected_routes(RoutingCtx) - }}. + {ok, {hg_routing_ctx:considered_candidates(RoutingCtx), hg_routing_ctx:rejected_routes(RoutingCtx)}}. diff --git a/apps/routing/src/hg_routing_explanation.erl b/apps/routing/src/hg_routing_explanation.erl index 3aadc334..24ee9554 100644 --- a/apps/routing/src/hg_routing_explanation.erl +++ b/apps/routing/src/hg_routing_explanation.erl @@ -35,9 +35,7 @@ get_explanation( %% If there's no routes even tried, then no explanation can be provided throw(#payproc_RouteNotChosen{}); [Route | AttemptedRoutes] -> - CandidateRoutesWithoutChosenRoute = exclude_chosen_route_from_candidates( - CandidateRoutes, Route - ), + CandidateRoutesWithoutChosenRoute = exclude_chosen_route_from_candidates(CandidateRoutes, Route), ChosenRWC = make_route_with_context(Route, RouteScores, RouteLimits), AttemptedExplanation = maybe_explain_attempted_routes( AttemptedRoutes, RouteScores, RouteLimits @@ -81,9 +79,7 @@ maybe_explain_attempted_routes([AttemptedRoute | AttemptedRoutes], RouteScores, maybe_explain_candidate_routes([], _RouteScores, _RouteLimits, _ChosenRWC) -> []; -maybe_explain_candidate_routes( - [CandidateRoute | CandidateRoutes], RouteScores, RouteLimits, ChosenRWC -) -> +maybe_explain_candidate_routes([CandidateRoute | CandidateRoutes], RouteScores, RouteLimits, ChosenRWC) -> RouteWithContext = make_route_with_context(CandidateRoute, RouteScores, RouteLimits), [ route_explanation(candidate, RouteWithContext, ChosenRWC) @@ -152,8 +148,7 @@ candidate_rejection_explanation( #{scores := RouteScores, limits := RouteLimits}, #{scores := ChosenScores} ) when RouteScores =:= ChosenScores -> - IfEmpty = - <<"This route has the same score as the chosen route, but wasn't chosen due to order in ruleset.">>, + IfEmpty = <<"This route has the same score as the chosen route, but wasn't chosen due to order in ruleset.">>, check_route_limits(RouteLimits, IfEmpty); candidate_rejection_explanation( #{scores := RouteScores, limits := RouteLimits}, @@ -234,9 +229,7 @@ check_route_scores( terminal_priority_rating = Rating1 } ) when Rating0 < Rating1 -> - format("Priority of this route was less than in chosen route, where ~p < ~p.", [ - Rating0, Rating1 - ]); + format("Priority of this route was less than in chosen route, where ~p < ~p.", [Rating0, Rating1]); check_route_scores( #domain_PaymentRouteScores{ route_pin = Pin0 diff --git a/rebar.config b/rebar.config index 069fa452..70514dd2 100644 --- a/rebar.config +++ b/rebar.config @@ -116,9 +116,7 @@ {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, [ From cf09fc91d16f93717a6084d62a3428eda88ef9c8 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Sun, 31 Aug 2025 20:43:45 +0300 Subject: [PATCH 04/10] Revert some format --- apps/hellgate/src/hg_invoice_payment.erl | 3 +- .../src/hg_invoice_payment_refund.erl | 2 +- .../test/hg_direct_recurrent_tests_SUITE.erl | 8 +- apps/hellgate/test/hg_invoice_helper.erl | 11 +- .../test/hg_invoice_lite_tests_SUITE.erl | 2 +- .../test/hg_invoice_template_tests_SUITE.erl | 64 +-- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 524 ++++++------------ rebar.config | 8 +- rebar.lock | 5 + 9 files changed, 195 insertions(+), 432 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 81c52d28..7e8ef576 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -2859,7 +2859,8 @@ construct_proxy_shop( Shop = #domain_ShopConfig{ location = Location, category = ShopCategoryRef - }} + } + } ) -> ShopCategory = hg_domain:get({category, ShopCategoryRef}), #proxy_provider_Shop{ diff --git a/apps/hellgate/src/hg_invoice_payment_refund.erl b/apps/hellgate/src/hg_invoice_payment_refund.erl index 6a12ac36..c9c5d9af 100644 --- a/apps/hellgate/src/hg_invoice_payment_refund.erl +++ b/apps/hellgate/src/hg_invoice_payment_refund.erl @@ -371,7 +371,7 @@ 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). diff --git a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl index 8a1b3be8..0a864cec 100644 --- a/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl +++ b/apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl @@ -196,9 +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_config_ref, 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), @@ -378,9 +376,7 @@ start_invoice(ShopConfigRef, Product, Due, Amount, C) -> Client = cfg(client, C), PartyConfigRef = cfg(party_config_ref, C), Cash = hg_ct_helper:make_cash(Amount, <<"RUB">>), - InvoiceParams = hg_ct_helper:make_invoice_params( - PartyConfigRef, ShopConfigRef, 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 58765260..9bf3895b 100644 --- a/apps/hellgate/test/hg_invoice_helper.erl +++ b/apps/hellgate/test/hg_invoice_helper.erl @@ -146,9 +146,7 @@ start_invoice(PartyConfigRef, ShopConfigRef, Product, Due, Amount, Client) -> #domain_ShopConfig{} = hg_domain:get({shop_config, ShopConfigRef}), % Создаем параметры инвойса с помощью существующих функций - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, 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. @@ -374,9 +372,10 @@ get_cashflow_volume(Source, Destination, CF, CFContext) -> Volume. -spec convert_transaction_account(_, _) -> _. -convert_transaction_account({merchant, Type}, #{ - party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef -}) -> +convert_transaction_account( + {merchant, Type}, + #{party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef} +) -> {merchant, #domain_MerchantTransactionAccount{ type = Type, owner = #domain_MerchantTransactionAccountOwner{ diff --git a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl index 3157ff58..0c121aaa 100644 --- a/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl @@ -441,7 +441,7 @@ payment_w_crypto_currency_success(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(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). diff --git a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl index c8331011..1791db6d 100644 --- a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl @@ -96,9 +96,8 @@ init_per_suite(C) -> PartyConfigRef = #domain_PartyConfigRef{id = hg_utils:unique_id()}, Client = {party_client:create_client(), party_client:create_context()}, ok = hg_context:save(hg_context:create()), - ShopConfigRef = hg_ct_helper:create_party_and_shop( - PartyConfigRef, ?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_config_ref, PartyConfigRef}, @@ -211,9 +210,7 @@ create_invoice_template_with_mutations(C) -> Lifetime = make_lifetime(0, 0, 2), #domain_InvoiceTemplate{id = TplID, mutations = Mutations} = create_invoice_tpl_w_mutations(C, Product, Lifetime, Cost, Mutations), - #domain_InvoiceTemplate{mutations = Mutations} = hg_client_invoice_templating:get( - TplID, Client - ). + #domain_InvoiceTemplate{mutations = Mutations} = hg_client_invoice_templating:get(TplID, Client). create_cost(Cost, C) -> Product = <<"rubberduck">>, @@ -272,13 +269,9 @@ update_invalid_party_status(C) -> Client = cfg(client, 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">>) - ) - } - ), + 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(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} @@ -296,13 +289,9 @@ update_invalid_shop_status(C) -> Client = cfg(client, 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">>) - ) - } - ), + 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(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} @@ -375,16 +364,11 @@ update_invoice_template(C) -> } = hg_client_invoice_templating:update(TplID, Diff1, Client), Tpl2 = update_cost(make_cost(fixed, 42, <<"RUB">>), Tpl1, Client), - Tpl3 = update_cost( - make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 42, <<"RUB">>}), Tpl2, Client - ), - _ = update_cost( - make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 100, <<"RUB">>}), Tpl3, Client - ). + Tpl3 = update_cost(make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 42, <<"RUB">>}), Tpl2, Client), + _ = update_cost(make_cost(range, {inclusive, 42, <<"RUB">>}, {inclusive, 100, <<"RUB">>}), Tpl3, Client). update_cost(Cost, Tpl, Client) -> - {product, #domain_InvoiceTemplateProduct{product = Product}} = - Tpl#domain_InvoiceTemplate.details, + {product, #domain_InvoiceTemplateProduct{product = Product}} = Tpl#domain_InvoiceTemplate.details, NewDetails = hg_ct_helper:make_invoice_tpl_details(Product, Cost), TplNext = Tpl#domain_InvoiceTemplate{details = NewDetails}, TplNext = hg_client_invoice_templating:update( @@ -491,16 +475,10 @@ delete_invoice_template(C) -> Client = cfg(client, C), ?invoice_tpl(TplID) = create_invoice_tpl(C), ok = hg_client_invoice_templating:delete(TplID, Client), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:get( - TplID, Client - ), + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:get(TplID, Client), Diff = make_invoice_tpl_update_params(#{}), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:update( - TplID, Diff, Client - ), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:delete( - TplID, Client - ). + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:update(TplID, Diff, Client), + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoice_templating:delete(TplID, Client). -spec terms_retrieval(config()) -> _. terms_retrieval(C) -> @@ -552,9 +530,7 @@ create_invoice_tpl(Config, Product, Lifetime, Cost) -> 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( - PartyConfigRef, ShopConfigRef, 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) -> @@ -581,9 +557,7 @@ update_invalid_cost(Cost, currency, TplID, Client) -> update_invalid_cost(Cost, Error, TplID, Client) -> Details = hg_ct_helper:make_invoice_tpl_details(<<"RNGName">>, Cost), Diff = make_invoice_tpl_update_params(#{details => Details}), - {exception, #base_InvalidRequest{errors = [Error]}} = hg_client_invoice_templating:update( - TplID, Diff, Client - ), + {exception, #base_InvalidRequest{errors = [Error]}} = hg_client_invoice_templating:update(TplID, Diff, Client), ok. create_invalid_cost(Cost, amount, Config) -> @@ -593,9 +567,7 @@ create_invalid_cost(Cost, currency, Config) -> create_invalid_cost(Cost, Error, Config) -> Product = <<"rubberduck">>, Lifetime = make_lifetime(0, 0, 2), - {exception, #base_InvalidRequest{errors = [Error]}} = create_invoice_tpl( - Config, Product, Lifetime, Cost - ), + {exception, #base_InvalidRequest{errors = [Error]}} = create_invoice_tpl(Config, Product, Lifetime, Cost), ok. make_invoice_tpl_create_params(PartyConfigRef, ShopConfigRef) -> diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 0a32036c..bfa406fb 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -701,9 +701,7 @@ init_per_testcase(Name = payments_w_bank_conditions, C) -> init_per_testcase(Name = payment_w_misconfigured_routing_failed, C) -> override_domain_fixture(fun payment_w_misconfigured_routing_failed_fixture/2, Name, C); init_per_testcase(Name = ineligible_payment_partial_refund, C) -> - override_domain_fixture( - fun(_, _) -> construct_term_set_for_refund_eligibility_time(1) end, Name, C - ); + override_domain_fixture(fun(_, _) -> construct_term_set_for_refund_eligibility_time(1) end, Name, C); init_per_testcase(Name = invalid_permit_partial_capture_in_service, C) -> override_domain_fixture(fun construct_term_set_for_partial_capture_service_permit/2, Name, C); init_per_testcase(Name = invalid_permit_partial_capture_in_provider, C) -> @@ -766,9 +764,7 @@ init_per_testcase_(Name, C) -> trace_testcase(Name, C) -> SpanName = iolist_to_binary([atom_to_binary(?MODULE), ":", atom_to_binary(Name), "/1"]), - SpanCtx = otel_tracer:start_span(opentelemetry:get_application_tracer(?MODULE), SpanName, #{ - kind => internal - }), + SpanCtx = otel_tracer:start_span(opentelemetry:get_application_tracer(?MODULE), SpanName, #{kind => internal}), %% NOTE This also puts otel context to process dictionary _ = otel_tracer:set_current_span(SpanCtx), [{span_ctx, SpanCtx} | C]. @@ -807,9 +803,7 @@ invoice_creation_idempotency(C) -> PartyConfigRef = cfg(party_config_ref, C), InvoiceID = hg_utils:unique_id(), ExternalID = <<"123">>, - InvoiceParams0 = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"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 @@ -828,9 +822,7 @@ invalid_invoice_shop(C) -> Client = cfg(client, C), PartyConfigRef = cfg(party_config_ref, C), ShopConfigRef = #domain_ShopConfigRef{id = hg_utils:unique_id()}, - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(10000) - ), + 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(). @@ -838,20 +830,14 @@ invalid_invoice_amount(C) -> Client = cfg(client, C), ShopConfigRef = cfg(shop_config_ref, C), PartyConfigRef = cfg(party_config_ref, C), - InvoiceParams0 = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(-10000) - ), + 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( - PartyConfigRef, ShopConfigRef, <<"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( - PartyConfigRef, ShopConfigRef, <<"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). @@ -860,9 +846,7 @@ invalid_invoice_currency(C) -> Client = cfg(client, C), ShopConfigRef = cfg(shop_config_ref, C), PartyConfigRef = cfg(party_config_ref, C), - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100, <<"KEK">>) - ), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100, <<"KEK">>)), {exception, #base_InvalidRequest{ errors = [<<"Invalid currency">>] }} = hg_client_invoicing:create(InvoiceParams, Client). @@ -872,9 +856,7 @@ invalid_party_status(C) -> Client = cfg(client, C), ShopConfigRef = cfg(shop_config_ref, C), PartyConfigRef = cfg(party_config_ref, C), - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000) - ), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), @@ -901,9 +883,7 @@ invalid_shop_status(C) -> Client = cfg(client, C), ShopConfigRef = cfg(shop_config_ref, C), PartyConfigRef = cfg(party_config_ref, C), - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000) - ), + InvoiceParams = make_invoice_params(PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(100000)), TplID = create_invoice_tpl(C), InvoiceParamsWithTpl = hg_ct_helper:make_invoice_params_tpl(TplID), @@ -975,16 +955,12 @@ invalid_invoice_template_id(C) -> TplID1 = <<"Watsthat">>, Params1 = hg_ct_helper:make_invoice_params_tpl(TplID1), - {exception, #payproc_InvoiceTemplateNotFound{}} = hg_client_invoicing:create_with_tpl( - Params1, Client - ), + {exception, #payproc_InvoiceTemplateNotFound{}} = hg_client_invoicing:create_with_tpl(Params1, Client), TplID2 = create_invoice_tpl(C), _ = delete_invoice_tpl(TplID2, C), Params2 = hg_ct_helper:make_invoice_params_tpl(TplID2), - {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoicing:create_with_tpl( - Params2, Client - ). + {exception, #payproc_InvoiceTemplateRemoved{}} = hg_client_invoicing:create_with_tpl(Params2, Client). -spec invoice_w_template_idempotency(config()) -> _ | no_return(). invoice_w_template_idempotency(C) -> @@ -1064,12 +1040,8 @@ invoice_w_template_amount_randomization(C) -> }, #domain_InvoiceTemplate{id = TplID} = hg_client_invoice_templating:create(TplParams, TplClient), InvoiceID = hg_utils:unique_id(), - Params = hg_ct_helper:make_invoice_params_tpl( - InvoiceID, TplID, FixedCost, hg_ct_helper:make_invoice_context() - ), - ?invoice_state(#domain_Invoice{mutations = Mutations}) = hg_client_invoicing:create_with_tpl( - Params, Client - ), + Params = hg_ct_helper:make_invoice_params_tpl(InvoiceID, TplID, FixedCost, hg_ct_helper:make_invoice_context()), + ?invoice_state(#domain_Invoice{mutations = Mutations}) = hg_client_invoicing:create_with_tpl(Params, Client), ?assertMatch( [{amount, #domain_InvoiceAmountMutation{original = OriginalAmount, mutated = Mutated}}] when Mutated =< OriginalAmount, @@ -1133,9 +1105,7 @@ invoice_cancellation(C) -> Client = cfg(client, C), ShopConfigRef = cfg(shop_config_ref, C), PartyConfigRef = cfg(party_config_ref, C), - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_cash(10000) - ), + 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). @@ -1175,9 +1145,7 @@ register_invoice_payment(ShopID, Client, C) -> register_invoice_payment(Route, ShopID, Client, C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = #payproc_RegisterInvoicePaymentParams{ payer_params = {payment_resource, #payproc_PaymentResourcePayerParams{ @@ -1219,9 +1187,7 @@ payment_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( @@ -1241,18 +1207,15 @@ payment_shop_limit_success(C) -> domain_revision = hg_domain:head() } ], - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( - PartyConfigRef, ShopConfigRef, 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) -> @@ -1266,9 +1229,8 @@ payment_shop_limit_overflow(C) -> domain_revision = hg_domain:head() } ]), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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, @@ -1293,18 +1255,15 @@ payment_shop_limit_more_overflow(C) -> domain_revision = hg_domain:head() } ]), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( - PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>) - ), + ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>)), Failure = create_payment_shop_limit_overflow( PartyConfigRef, ShopConfigRef, PaymentAmount, Client, ?pmt_sys(<<"visa-ref">>) @@ -1320,9 +1279,7 @@ payment_routes_limit_values(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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)), #payproc_Invoice{ @@ -1335,9 +1292,7 @@ payment_routes_limit_values(C) -> #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{ - id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY - }, + limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, value = 10000 } ] @@ -1348,9 +1303,7 @@ register_payment_limit_success(C0) -> Client = cfg(client, C0), PartyClient = cfg(party_client, C0), #{party_config_ref := PartyConfigRef} = cfg(limits, C0), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ), + 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, ShopConfigRef, Client, C1), @@ -1365,12 +1318,8 @@ payment_limit_other_shop_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{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 - ), + 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, @@ -1390,9 +1339,7 @@ payment_limit_overflow(C) -> RootUrl = cfg(root_url, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), PartyClient = cfg(party_client, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( @@ -1404,11 +1351,13 @@ payment_limit_overflow(C) -> 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) -> @@ -1422,9 +1371,7 @@ limit_hold_operation_not_supported(C) -> -spec limit_hold_payment_tool_not_supported(config()) -> test_return(). limit_hold_payment_tool_not_supported(C) -> - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - crypto_currency, ?crypta(<<"bitcoin-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(crypto_currency, ?crypta(<<"bitcoin-ref">>)), Failure = payment_route_not_found(PaymentTool, Session, C), ?assertRouteNotFound(Failure, {rejected, {limit_misconfiguration, _}}, <<"[{">>). @@ -1442,22 +1389,16 @@ payment_route_not_found(PaymentTool, Session, C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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)), Cash = make_cash(10000, <<"RUB">>), - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"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), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), _ = start_payment_ev(InvoiceID, Client), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) = next_change(InvoiceID, Client), @@ -1471,9 +1412,7 @@ switch_provider_after_limit_overflow(C) -> PartyClient = cfg(party_client, C), #{party_config_ref_w_several_limits := PartyConfigRef} = cfg(limits, C), PaymentAmount = 69999, - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( @@ -1486,9 +1425,8 @@ switch_provider_after_limit_overflow(C) -> ), #domain_InvoicePayment{id = PaymentID} = Payment, - InvoiceID = start_invoice( - PartyConfigRef, ShopConfigRef, <<"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), @@ -1507,9 +1445,7 @@ limit_not_found(C) -> PartyClient = cfg(party_client, C), #{party_config_ref_w_several_limits := PartyConfigRef} = cfg(limits, C), PaymentAmount = 69999, - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( @@ -1525,9 +1461,7 @@ refund_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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( @@ -1543,11 +1477,11 @@ refund_limit_success(C) -> ?payment(PaymentID) = Payment, 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), + 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), @@ -1571,9 +1505,7 @@ payment_partial_capture_limit_success(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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)), InvoiceParams = make_invoice_params( @@ -1600,7 +1532,8 @@ payment_partial_capture_limit_success(C) -> ?invoice_state(Invoice, [PaymentState]) = InvoiceState, ?assertMatch(?invoice_w_status(?invoice_paid()), Invoice), ?assertMatch( - ?payment_state(?payment_w_status(PaymentID, ?captured(Reason, Cash))), PaymentState + ?payment_state(?payment_w_status(PaymentID, ?captured(Reason, Cash))), + PaymentState ), ?payment_cashflow(CF2) = PaymentState, ?assertNotEqual(undefined, CF2), @@ -1609,9 +1542,8 @@ payment_partial_capture_limit_success(C) -> %%----------------- operation_limits helpers create_payment(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount) - ), + 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), @@ -1620,28 +1552,22 @@ create_payment(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> hg_client_invoicing:get(InvoiceID, Client). create_payment_limit_overflow(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount) - ), + 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), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), await_payment_rollback(InvoiceID, PaymentID, Client). create_payment_shop_limit_overflow(PartyConfigRef, ShopConfigRef, Amount, Client, PmtSys) -> - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"rubberduck">>, make_due_date(10), make_cash(Amount) - ), + 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), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), await_payment_shop_limit_rollback(InvoiceID, PaymentID, Client). @@ -1653,12 +1579,9 @@ payment_success_ruleset(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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), @@ -1693,13 +1616,9 @@ payment_w_misconfigured_routing_failed(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -1721,10 +1640,7 @@ payment_w_misconfigured_routing_failed_fixture(_Revision, _C) -> {delegates, [ ?delegate( <<"Inexistent merchant">>, - {condition, - {party, #domain_PartyCondition{ - party_ref = ?PARTY_CONFIG_REF_DEPRIVED_1 - }}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF_DEPRIVED_1}}}, ?ruleset(1) ), ?delegate( @@ -1759,9 +1675,7 @@ mk_provider_w_term(TerminalRef, TerminalName, ProviderRef, ProviderName, Provide }} ]. -new_merchant_terms_attempt_limit( - TermSetHierarchyRef, TargetTermSetHierarchyRef, Attempts, Revision -) -> +new_merchant_terms_attempt_limit(TermSetHierarchyRef, TargetTermSetHierarchyRef, Attempts, Revision) -> #domain_TermSetHierarchy{term_set = TermsSet} = hg_domain:get(Revision, {term_set_hierarchy, TermSetHierarchyRef}), #domain_TermSet{payments = PaymentsTerms0} = TermsSet, @@ -1771,16 +1685,12 @@ new_merchant_terms_attempt_limit( [ {term_set_hierarchy, #domain_TermSetHierarchyObject{ ref = TargetTermSetHierarchyRef, - data = #domain_TermSetHierarchy{ - term_set = TermsSet#domain_TermSet{payments = PaymentsTerms1} - } + data = #domain_TermSetHierarchy{term_set = TermsSet#domain_TermSet{payments = PaymentsTerms1}} }} ]. patch_limit_config_w_invalid_currency(Revision, _C) -> - NewRevision = hg_domain:update( - {limit_config, hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"KEK">>)} - ), + NewRevision = hg_domain:update({limit_config, hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"KEK">>)}), [ change_terms_limit_config_version(Revision, NewRevision) ]. @@ -1788,9 +1698,7 @@ patch_limit_config_w_invalid_currency(Revision, _C) -> patch_limit_config_for_withdrawal(Revision, _C) -> NewRevision = hg_domain:update( {limit_config, - hg_limiter_helper:mk_config_object( - ?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal) - )} + hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal))} ), [ change_terms_limit_config_version(Revision, NewRevision) @@ -1833,9 +1741,7 @@ patch_providers_limits_to_fail_and_overflow(Revision, _C) -> %% 4. Second must get rejected due limit overflow. NewRevision = hg_domain:update([ {limit_config, - hg_limiter_helper:mk_config_object( - ?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal) - )} + hg_limiter_helper:mk_config_object(?LIMIT_ID, <<"RUB">>, hg_limiter_helper:mk_context_type(withdrawal))} ]), [ hg_ct_fixture:construct_payment_routing_ruleset( @@ -1866,10 +1772,7 @@ patch_providers_limits_to_fail_and_overflow(Revision, _C) -> ]. unset_providers_chargebacks_terms(Revision, _C) -> - lists:flatten([ - unset_provider_chargebacks_terms(Revision, ProviderRef) - || ProviderRef <- [?prv(2)] - ]). + lists:flatten([unset_provider_chargebacks_terms(Revision, ProviderRef) || ProviderRef <- [?prv(2)]]). unset_provider_chargebacks_terms(Revision, ProviderRef) -> Provider = @@ -1881,9 +1784,7 @@ unset_provider_chargebacks_terms(Revision, ProviderRef) -> ref = ProviderRef, data = Provider#domain_Provider{ terms = Terms#domain_ProvisionTermSet{ - payments = PaymentsTermSet#domain_PaymentsProvisionTerms{ - chargebacks = undefined - } + payments = PaymentsTermSet#domain_PaymentsProvisionTerms{chargebacks = undefined} } } }} @@ -1900,14 +1801,10 @@ change_terms_limit_config_version(Revision, LimitConfigRevision) -> change_terms_limit_config_version(Revision, ProviderRef, TurnoverLimits) -> change_provider_payments_provision_terms(ProviderRef, Revision, fun(PaymentsProvisionTerms) -> - PaymentsProvisionTerms#domain_PaymentsProvisionTerms{ - turnover_limits = {value, TurnoverLimits} - } + PaymentsProvisionTerms#domain_PaymentsProvisionTerms{turnover_limits = {value, TurnoverLimits}} end). -change_provider_payments_provision_terms(ProviderID, Revision, Changer) when - is_function(Changer, 1) --> +change_provider_payments_provision_terms(ProviderID, Revision, Changer) when is_function(Changer, 1) -> Provider = #domain_Provider{terms = Terms} = hg_domain:get(Revision, {provider, ProviderID}), Terms1 = Terms#domain_ProvisionTermSet{ @@ -1944,9 +1841,7 @@ payment_capture_retries_exceeded(C) -> Amount = 42000, Cost = ?cash(Amount, <<"RUB">>), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - PaymentParams = make_scenario_payment_params( - [good, temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>) - ), + PaymentParams = make_scenario_payment_params([good, temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), PaymentID = process_payment(InvoiceID, PaymentParams, Client), Reason = ?timeout_reason(), Target = ?captured(Reason, Cost), @@ -1986,9 +1881,7 @@ payment_partial_capture_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). @@ -1998,26 +1891,20 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> Client = cfg(client, C), PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopConfigRef = hg_ct_helper:create_battle_ready_shop( - PartyConfigRef, ?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), {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(ShopConfigRef, <<"rubberduck">>, make_due_date(1000), 42000, C), - PaymentParams = make_scenario_payment_params( - [good, fail, good], {hold, capture}, ?pmt_sys(<<"visa-ref">>) - ), + 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)), ok = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"cancel">>, Client), ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_started())) = next_change(InvoiceID, Client), timeout = next_change(InvoiceID, Client), - ?assertMatch( - #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting:get_balance(SettlementID) - ), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), ?assertException( error, {{woody_error, _}, _}, @@ -2030,33 +1917,24 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> Client = cfg(client, C), PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopConfigRef = hg_ct_helper:create_battle_ready_shop( - PartyConfigRef, ?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">>), {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(ShopConfigRef, <<"rubberduck">>, make_due_date(1000), Amount, C), - PaymentParams = make_scenario_payment_params( - [good, fail, good], {hold, cancel}, ?pmt_sys(<<"visa-ref">>) - ), + 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) - ), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _, _Allocation)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), timeout = next_change(InvoiceID, Client), - ?assertMatch( - #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting:get_balance(SettlementID) - ), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), ?assertException( error, {{woody_error, _}, _}, @@ -2079,10 +1957,7 @@ repair_failed_cancel(InvoiceID, PaymentID, Reason, Client) -> ], ok = repair_invoice(InvoiceID, Changes, Client), [ - ?payment_ev( - PaymentID, - ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded())) - ), + ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_changes(InvoiceID, 2, Client), PaymentID. @@ -2096,17 +1971,14 @@ payment_success_ruleset_provider_available(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ), + 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 - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state( ?invoice_w_status(?invoice_paid()), @@ -2135,9 +2007,8 @@ route_found_provider_lacking_conversion(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ), + 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) ), @@ -2145,9 +2016,7 @@ route_found_provider_lacking_conversion(C) -> 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 - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state(?invoice_w_status(?invoice_paid()), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -2161,12 +2030,9 @@ failed_payment_wo_cascade(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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), @@ -2198,9 +2064,7 @@ payment_w_terminal_w_payment_service_success(C) -> BadForm = #{<<"tag">> => <<"666">>}, _ = assert_invalid_post_request({URL, BadForm}), _ = assert_success_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), ?invoice_state( @@ -2224,24 +2088,18 @@ payment_bank_card_category_condition(C) -> Client = cfg(client, C), PayCash = 2000, InvoiceID = start_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C), - {{bank_card, BC}, Session} = hg_dummy_provider:make_payment_tool( - empty_cvv, ?pmt_sys(<<"visa-ref">>) - ), + {{bank_card, BC}, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)), BankCard = BC#domain_BankCard{ category = <<"CORPORATE CARD">> }, PaymentTool = {bank_card, BankCard}, PaymentParams = make_payment_params(PaymentTool, Session, instant), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = 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(cfg(party_config_ref, C), cfg(shop_config_ref, C), Route), - ?cash(200, <<"RUB">>) = get_cashflow_volume( - {merchant, settlement}, {system, settlement}, CF, CFContext - ). + ?cash(200, <<"RUB">>) = get_cashflow_volume({merchant, settlement}, {system, settlement}, CF, CFContext). -spec payment_success_on_second_try(config()) -> test_return(). payment_success_on_second_try(C) -> @@ -2260,9 +2118,7 @@ payment_success_on_second_try(C) -> _ = assert_success_post_request({URL, GoodForm}), %% ensure that callback is now invalid̋ _ = assert_invalid_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client). @@ -2270,9 +2126,7 @@ payment_success_on_second_try(C) -> payment_success_with_increased_cost(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - change_cash_increase, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_increase, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_cash_changed_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -2296,18 +2150,12 @@ refund_payment_with_increased_cost(C) -> % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), 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">>) - ), + {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 - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2351,25 +2199,25 @@ refund_payment_with_increased_cost(C) -> PrvAccount2 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), 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 - ), + #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) + 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) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - change_cash_decrease, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(change_cash_decrease, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = execute_cash_changed_payment(InvoiceID, PaymentParams, Client), ?invoice_state( @@ -2393,18 +2241,12 @@ refund_payment_with_decreased_cost(C) -> % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), 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">>) - ), + {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 - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2448,23 +2290,23 @@ refund_payment_with_decreased_cost(C) -> PrvAccount2 = get_deprecated_cashflow_account({provider, settlement}, CF, CFContext), 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 - ), + #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) + 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), - PaymentID = hg_invoice_helper:await_payment_session_started( - InvoiceID, PaymentID, Client, ?processed() - ), + PaymentID = hg_invoice_helper:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(_)))), ?payment_ev(PaymentID, ?cash_changed(_, _)), @@ -2479,9 +2321,7 @@ execute_cash_changed_payment(InvoiceID, PaymentParams, Client) -> payment_fail_after_silent_callback(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberdick">>, make_due_date(20), 42000, C), - PaymentID = start_payment( - InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client - ), + PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), {URL, Form} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, hg_dummy_provider:construct_silent_callback(Form)}), @@ -2492,9 +2332,7 @@ payment_session_changed_to_fail(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberdick">>, make_due_date(20), 42000, C), %% Payment w/ preauth for suspend w/ user interaction occurrence. - PaymentID = start_payment( - InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client - ), + PaymentID = start_payment(InvoiceID, make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)), Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), Failure = payproc_errors:construct( @@ -2514,9 +2352,7 @@ payment_session_changed_to_fail(C) -> %% from request parameter. Tag = user_interaction_callback_tag(UserInteraction), ok = hg_dummy_provider:change_payment_session(Tag, Change), - {failed, PaymentID, {failure, Failure}} = await_payment_process_failure( - InvoiceID, PaymentID, Client - ), + {failed, PaymentID, {failure, Failure}} = await_payment_process_failure(InvoiceID, PaymentID, Client), %% Bad session callback tag must not be found again ?assertMatch( @@ -2549,9 +2385,7 @@ payments_w_bank_card_issuer_conditions(C) -> %kaz fail SecondInvoice = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 1001, C), ?assertEqual( - {exception, #base_InvalidRequest{ - errors = [<<"Invalid amount, more than allowed maximum">>] - }}, + {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, hg_client_invoicing:start_payment(SecondInvoice, KazPaymentParams, Client) ), %rus success @@ -2598,9 +2432,7 @@ payments_w_bank_conditions(C) -> %bank 1 fail SecondInvoice = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 1001, C), ?assertEqual( - {exception, #base_InvalidRequest{ - errors = [<<"Invalid amount, more than allowed maximum">>] - }}, + {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, hg_client_invoicing:start_payment(SecondInvoice, TestPaymentParams, Client) ), %bank 1 /w different wildcard fail @@ -2611,9 +2443,7 @@ payments_w_bank_conditions(C) -> }, WildPaymentParams = make_payment_params({bank_card, WildBankCard}, Session1, instant), ?assertEqual( - {exception, #base_InvalidRequest{ - errors = [<<"Invalid amount, more than allowed maximum">>] - }}, + {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, hg_client_invoicing:start_payment(ThirdInvoice, WildPaymentParams, Client) ), %some other bank success @@ -2632,9 +2462,7 @@ payments_w_bank_conditions(C) -> }, FallbackPaymentParams = make_payment_params({bank_card, FallbackBankCard}, Session3, instant), ?assertEqual( - {exception, #base_InvalidRequest{ - errors = [<<"Invalid amount, more than allowed maximum">>] - }}, + {exception, #base_InvalidRequest{errors = [<<"Invalid amount, more than allowed maximum">>]}}, hg_client_invoicing:start_payment(FifthInvoice, FallbackPaymentParams, Client) ). @@ -2656,9 +2484,7 @@ invoice_success_on_third_payment(C) -> GoodPost = get_post_request(UserInteraction), %% simulate user interaction FTW! _ = assert_success_post_request(GoodPost), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID3, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID3, UserInteraction, Client), PaymentID3 = await_payment_process_finish(InvoiceID, PaymentID3, Client), PaymentID3 = await_payment_capture(InvoiceID, PaymentID3, Client). @@ -2669,9 +2495,7 @@ payment_risk_score_check(C) -> % Invoice w/ cost < 500000 InvoiceID1 = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment( - InvoiceID1, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment(InvoiceID1, PaymentParams, Client), ?payment_ev(PaymentID1, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID1, Client), % low risk score... @@ -2683,9 +2507,7 @@ payment_risk_score_check(C) -> PaymentID1 = await_payment_capture(InvoiceID1, PaymentID1, Client), % Invoice w/ 500000 < cost < 100000000 InvoiceID2 = start_invoice(<<"rubberbucks">>, make_due_date(10), 31337000, C), - ?payment_state(?payment(PaymentID2)) = hg_client_invoicing:start_payment( - InvoiceID2, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID2)) = hg_client_invoicing:start_payment(InvoiceID2, PaymentParams, Client), ?payment_ev(PaymentID2, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID2, Client), % high risk score... @@ -2697,9 +2519,7 @@ payment_risk_score_check(C) -> PaymentID2 = await_payment_capture(InvoiceID2, PaymentID2, Client), % Invoice w/ 100000000 =< cost InvoiceID3 = start_invoice(<<"rubbersocks">>, make_due_date(10), 100000000, C), - ?payment_state(?payment(PaymentID3)) = hg_client_invoicing:start_payment( - InvoiceID3, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID3)) = hg_client_invoicing:start_payment(InvoiceID3, PaymentParams, Client), [ ?payment_ev(PaymentID3, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -2731,17 +2551,13 @@ invalid_payment_adjustment(C) -> PaymentID = start_payment(InvoiceID, PaymentParams, Client), %% no way to create adjustment for a payment not yet finished ?invalid_payment_status(?pending()) = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, make_adjustment_params(), Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), _UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), PaymentID = await_payment_process_timeout(InvoiceID, PaymentID, Client), %% no way to create adjustment for a failed payment %% Correction. It was changed to failed payment not being in the way of adjustment ?adjustment(_AdjustmentID, ?adjustment_pending()) = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, make_adjustment_params(), Client - ). + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client). -spec payment_adjustment_success(config()) -> test_return(). payment_adjustment_success(C) -> @@ -2759,9 +2575,7 @@ payment_adjustment_success(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2787,14 +2601,8 @@ payment_adjustment_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 2, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -2837,9 +2645,7 @@ payment_adjustment_w_amount_success(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -2870,17 +2676,9 @@ payment_adjustment_w_amount_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev( - PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 3, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -2894,10 +2692,7 @@ payment_adjustment_w_amount_success(C) -> OriginalAmount, ?merchant_to_system_share_1, ?system_to_provider_share_initial, ZeroShare ), {NewOpDiffMrc, NewOpDiffSys, NewOpDiffPrv} = compute_operation_amount_diffs( - NewAmount, - ?merchant_to_system_share_1, - ?system_to_provider_share_actual, - ?system_to_external_fixed + NewAmount, ?merchant_to_system_share_1, system_to_provider_share_actual, ?system_to_external_fixed ), ?assertEqual( NewOpDiffMrc - OpDiffMrc, @@ -2920,19 +2715,16 @@ 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_config_ref, 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 ), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), - _AdjustmentID = execute_payment_adjustment( - InvoiceID, PaymentID, make_adjustment_params(), Client - ), + _AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), NewCashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), ?assertEqual( [ @@ -3044,12 +2836,8 @@ payment_adjustment_captured_partial(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF2, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF2, CFContext), Context = #{operation_amount => Cash}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( - ?merchant_to_system_share_1, Context - ), - #domain_Cash{amount = MrcAmount2} = hg_cashflow:compute_volume( - ?merchant_to_system_share_3, Context - ), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), + #domain_Cash{amount = MrcAmount2} = hg_cashflow:compute_volume(?merchant_to_system_share_3, Context), % fees after adjustment are less than before, so own amount is greater MrcDiff = MrcAmount1 - MrcAmount2, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), @@ -3062,9 +2850,7 @@ payment_adjustment_captured_partial(C) -> % inversed in opposite of merchant fees PrvDiff = PrvAmount2 - PrvAmount1, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), - #domain_Cash{amount = SysAmount2} = hg_cashflow:compute_volume( - ?system_to_external_fixed, Context - ), + #domain_Cash{amount = SysAmount2} = hg_cashflow:compute_volume(?system_to_external_fixed, Context), SysDiff = MrcDiff + PrvDiff - SysAmount2, ?assertEqual(SysDiff, maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)). diff --git a/rebar.config b/rebar.config index 70514dd2..d42ed343 100644 --- a/rebar.config +++ b/rebar.config @@ -49,7 +49,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, [ @@ -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 903d8d3d..ff9f28ef 100644 --- a/rebar.lock +++ b/rebar.lock @@ -41,6 +41,11 @@ {git,"https://github.com/epgsql/epgsql.git", {ref,"7ba52768cf0ea7d084df24d4275a88eef4db13c2"}}, 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"}}, From 7e7b2140750f8ef31cabc28df46675c05bdc4b86 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Sun, 31 Aug 2025 22:08:34 +0300 Subject: [PATCH 05/10] Revert some more format --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 1627 ++++------------- 1 file changed, 395 insertions(+), 1232 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index bfa406fb..6caaf1a6 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -2720,9 +2720,7 @@ payment_adjustment_refunded_success(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), - _RefundID = execute_payment_refund( - InvoiceID, PaymentID, make_refund_params(1000, <<"RUB">>), Client - ), + _RefundID = execute_payment_refund(InvoiceID, PaymentID, make_refund_params(1000, <<"RUB">>), Client), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), _AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), NewCashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), @@ -2757,9 +2755,7 @@ payment_adjustment_chargeback_success(C) -> PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), % % Контракт на основе шаблона ?trms(1) - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?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(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 10000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), @@ -2767,9 +2763,7 @@ payment_adjustment_chargeback_success(C) -> Params = make_chargeback_params(?cash(10000, <<"RUB">>)), _ChargebackID = execute_payment_chargeback(InvoiceID, PaymentID, Params, Client), ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(actual)), - _AdjustmentID = execute_payment_adjustment( - InvoiceID, PaymentID, make_adjustment_params(), Client - ), + _AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, make_adjustment_params(), Client), NewCashFlow = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client), ?assertEqual( [ @@ -2841,12 +2835,8 @@ payment_adjustment_captured_partial(C) -> % fees after adjustment are less than before, so own amount is greater MrcDiff = MrcAmount1 - MrcAmount2, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( - ?system_to_provider_share_initial, Context - ), - #domain_Cash{amount = PrvAmount2} = hg_cashflow:compute_volume( - ?system_to_provider_share_actual, Context - ), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), + #domain_Cash{amount = PrvAmount2} = hg_cashflow:compute_volume(?system_to_provider_share_actual, Context), % inversed in opposite of merchant fees PrvDiff = PrvAmount2 - PrvAmount1, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), @@ -2861,9 +2851,7 @@ payment_adjustment_captured_from_failed(C) -> ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(1)), Amount = 42000, InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(3), Amount, C), - PaymentParams = make_scenario_payment_params( - [temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>) - ), + PaymentParams = make_scenario_payment_params([temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), CaptureAmount = Amount div 2, CaptureCost = ?cash(CaptureAmount, <<"RUB">>), Captured = {captured, #domain_InvoicePaymentCaptured{cost = CaptureCost}}, @@ -2872,9 +2860,7 @@ payment_adjustment_captured_from_failed(C) -> ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?invalid_payment_status(?pending()) = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, AdjustmentParams, Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -2891,19 +2877,13 @@ payment_adjustment_captured_from_failed(C) -> % update merchant fees ok = hg_ct_helper:shop_set_terms(ShopConfigRef, ?trms(3)), - InvalidAdjustmentParams1 = make_status_adjustment_params( - {processed, #domain_InvoicePaymentProcessed{}} - ), + InvalidAdjustmentParams1 = make_status_adjustment_params({processed, #domain_InvoicePaymentProcessed{}}), ?invalid_payment_target_status(?processed()) = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, InvalidAdjustmentParams1, Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, InvalidAdjustmentParams1, Client), FailedTargetStatus = ?failed({failure, #domain_Failure{code = <<"404">>}}), FailedAdjustmentParams = make_status_adjustment_params(FailedTargetStatus), - _FailedAdjustmentID = execute_payment_adjustment( - InvoiceID, PaymentID, FailedAdjustmentParams, Client - ), + _FailedAdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client), ?assertMatch( ?payment_state(?payment_w_status(PaymentID, FailedTargetStatus)), @@ -2911,9 +2891,7 @@ payment_adjustment_captured_from_failed(C) -> ), ?payment_already_has_status(FailedTargetStatus) = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, FailedAdjustmentParams, Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client), AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client), ?payment_state(Payment) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -2928,14 +2906,10 @@ payment_adjustment_captured_from_failed(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, DCF2, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, DCF2, CFContext), Context = #{operation_amount => CaptureCost}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( - ?merchant_to_system_share_1, Context - ), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), MrcDiff = CaptureAmount - MrcAmount1, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount2) - maps:get(own_amount, MrcAccount1)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( - ?system_to_provider_share_initial, Context - ), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), PrvDiff = PrvAmount1 - CaptureAmount, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount2) - maps:get(own_amount, PrvAccount1)), SysDiff = MrcAmount1 - PrvAmount1, @@ -2950,9 +2924,7 @@ payment_adjustment_failed_from_captured(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 - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_started(InvoiceID, PaymentID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -2983,14 +2955,10 @@ payment_adjustment_failed_from_captured(C) -> SysAccount2 = get_deprecated_cashflow_account({system, settlement}, CF1, CFContext), MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), Context = #{operation_amount => ?cash(Amount, <<"RUB">>)}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( - ?merchant_to_system_share_1, Context - ), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context), MrcDiff = Amount - MrcAmount1, ?assertEqual(MrcDiff, maps:get(own_amount, MrcAccount1) - maps:get(own_amount, MrcAccount2)), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( - ?system_to_provider_share_initial, Context - ), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context), PrvDiff = PrvAmount1 - Amount, ?assertEqual(PrvDiff, maps:get(own_amount, PrvAccount1) - maps:get(own_amount, PrvAccount2)), SysDiff = MrcAmount1 - PrvAmount1, @@ -3015,9 +2983,7 @@ payment_adjustment_change_amount_and_captured(C) -> % {ShopID, Shop} = hg_party:get_shop(PartyID, cfg(shop_id, C), hg_party:get_party_revision()), % reinit terminal cashflow - ok = update_payment_terms_cashflow( - ?prv(100), get_payment_adjustment_provider_cashflow(initial) - ), + ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(initial)), OriginalAmount = 100000, NewAmount = 200000, @@ -3025,9 +2991,7 @@ payment_adjustment_change_amount_and_captured(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -3076,12 +3040,8 @@ payment_adjustment_change_amount_and_captured(C) -> MrcAccount2 = get_deprecated_cashflow_account({merchant, settlement}, CF1, CFContext), Context0 = #{operation_amount => ?cash(OriginalAmount, <<"RUB">>)}, - #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume( - ?merchant_to_system_share_1, Context0 - ), - #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume( - ?system_to_provider_share_initial, Context0 - ), + #domain_Cash{amount = MrcAmount1} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context0), + #domain_Cash{amount = PrvAmount1} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context0), MrcDiff0 = OriginalAmount - MrcAmount1, PrvDiff0 = PrvAmount1 - OriginalAmount, SysDiff0 = MrcAmount1 - PrvAmount1, @@ -3093,25 +3053,15 @@ payment_adjustment_change_amount_and_captured(C) -> AdjustmentParams1 = make_adjustment_params(AdjReason1 = <<"imdrunk">>, undefined, NewAmount), ?adjustment(AdjustmentID1, ?adjustment_pending()) = Adjustment1 = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, AdjustmentParams1, Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams1, Client), #domain_InvoicePaymentAdjustment{id = AdjustmentID1, reason = AdjReason1} = hg_client_invoicing:get_payment_adjustment(InvoiceID, PaymentID, AdjustmentID1, Client), ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_created(Adjustment1))) = next_change(InvoiceID, Client), [ - ?payment_ev( - PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 3, Client), ?payment_state(Payment1) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -3150,12 +3100,8 @@ payment_adjustment_change_amount_and_captured(C) -> ), Context2 = #{operation_amount => ChangedCost}, - #domain_Cash{amount = MrcAmount3} = hg_cashflow:compute_volume( - ?merchant_to_system_share_1, Context2 - ), - #domain_Cash{amount = PrvAmount3} = hg_cashflow:compute_volume( - ?system_to_provider_share_initial, Context2 - ), + #domain_Cash{amount = MrcAmount3} = hg_cashflow:compute_volume(?merchant_to_system_share_1, Context2), + #domain_Cash{amount = PrvAmount3} = hg_cashflow:compute_volume(?system_to_provider_share_initial, Context2), MrcDiff2 = NewAmount - MrcAmount3, PrvDiff2 = PrvAmount3 - NewAmount, SysDiff2 = MrcAmount3 - PrvAmount3, @@ -3181,25 +3127,19 @@ payment_adjustment_change_amount_and_refund_all(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) - ), + ok = update_payment_terms_cashflow(?prv(100), get_payment_adjustment_provider_cashflow(initial)), OriginalAmount = 100000, NewAmount = 200000, % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), NewAmount, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), OriginalAmount, C), %% start a healthy man's payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, Client), {_CF1, Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client), @@ -3228,25 +3168,15 @@ payment_adjustment_change_amount_and_refund_all(C) -> AdjustmentParams1 = make_adjustment_params(AdjReason1 = <<"imdrunk">>, undefined, NewAmount), ?adjustment(AdjustmentID1, ?adjustment_pending()) = Adjustment1 = - hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, AdjustmentParams1, Client - ), + hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams1, Client), #domain_InvoicePaymentAdjustment{id = AdjustmentID1, reason = AdjReason1} = hg_client_invoicing:get_payment_adjustment(InvoiceID, PaymentID, AdjustmentID1, Client), ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_created(Adjustment1))) = next_change(InvoiceID, Client), [ - ?payment_ev( - PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>)) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?cash_changed(?cash(OriginalAmount, <<"RUB">>), ?cash(NewAmount, <<"RUB">>))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID1, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 3, Client), ?payment_state(Payment1) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client), @@ -3287,16 +3217,18 @@ 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 - ), + #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) + 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(). @@ -3319,9 +3251,7 @@ status_adjustment_of_partial_refunded_payment(C) -> FailedAdjustmentParams = make_status_adjustment_params(FailedTargetStatus), {exception, #base_InvalidRequest{ errors = [<<"Cannot change status of payment with refunds.">>] - }} = hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, FailedAdjustmentParams, Client - ). + }} = hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, FailedAdjustmentParams, Client). -spec registered_payment_adjustment_success(config()) -> _. registered_payment_adjustment_success(C) -> @@ -3338,9 +3268,7 @@ registered_payment_adjustment_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), Route = ?route(?prv(100), ?trm(1)), String = <<"STRING">>, PaymentParams = #payproc_RegisterInvoicePaymentParams{ @@ -3352,17 +3280,7 @@ registered_payment_adjustment_success(C) -> client_info = #domain_ClientInfo{} }, contact_info = ?contact_info( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String + String, String, String, String, String, String, String, String, String, String, String ) }}, route = Route, @@ -3395,14 +3313,8 @@ registered_payment_adjustment_success(C) -> ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))) = next_change(InvoiceID, Client), [ - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 2, Client), %% verify that cash deposited correctly everywhere #domain_InvoicePaymentAdjustment{new_cash_flow = DCF2} = Adjustment, @@ -3420,9 +3332,7 @@ payment_temporary_unavailability_retry_success(C) -> Amount = 42000, Cost = make_cash(Amount), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - PaymentParams = make_scenario_payment_params( - [temp, temp, good, temp, temp], ?pmt_sys(<<"visa-ref">>) - ), + PaymentParams = make_scenario_payment_params([temp, temp, good, temp, temp], ?pmt_sys(<<"visa-ref">>)), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_sessions_restarts(PaymentID, ?processed(), InvoiceID, Client, 2), @@ -3431,9 +3341,7 @@ payment_temporary_unavailability_retry_success(C) -> ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _, _)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_changes(InvoiceID, 2, Client), - PaymentID = await_sessions_restarts( - PaymentID, ?captured(Reason, Cost, undefined), InvoiceID, Client, 2 - ), + PaymentID = await_sessions_restarts(PaymentID, ?captured(Reason, Cost, undefined), InvoiceID, Client, 2), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client), ?invoice_state( ?invoice_w_status(?invoice_paid()), @@ -3444,9 +3352,7 @@ payment_temporary_unavailability_retry_success(C) -> payment_temporary_unavailability_too_many_retries(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentParams = make_scenario_payment_params( - [temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>) - ), + PaymentParams = make_scenario_payment_params([temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)), PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), {failed, PaymentID, {failure, Failure}} = @@ -3516,16 +3422,12 @@ invalid_payment_w_deprived_party(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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 - ), + ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, InvoicingClient), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), Exception = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, InvoicingClient), {exception, #base_InvalidRequest{}} = Exception. @@ -3582,12 +3484,10 @@ terminal_cashflow_overrides_provider(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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( @@ -3690,9 +3590,7 @@ create_chargeback_idempotency(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3700,21 +3598,14 @@ create_chargeback_idempotency(C) -> ] = next_changes(IID, 2, Client), ?assertMatch(CB, hg_client_invoicing:create_chargeback(IID, PID, CBParams, Client)), NewCBParams = make_chargeback_params(Levy), - ?assertMatch( - ?chargeback_pending(), hg_client_invoicing:create_chargeback(IID, PID, NewCBParams, Client) - ), + ?assertMatch(?chargeback_pending(), hg_client_invoicing:create_chargeback(IID, PID, NewCBParams, Client)), Settlement0 = hg_accounting:get_balance(SID), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3731,9 +3622,7 @@ cancel_payment_chargeback(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3743,14 +3632,9 @@ cancel_payment_chargeback(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3768,9 +3652,7 @@ cancel_partial_payment_chargeback(C) -> Paid = Partial - Fee, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback_partial_capture( - C, Cost, Partial, CBParams, ?pmt_sys(<<"mastercard-ref">>) - ), + {IID, PID, SID, CB} = start_chargeback_partial_capture(C, Cost, Partial, CBParams, ?pmt_sys(<<"mastercard-ref">>)), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3780,14 +3662,9 @@ cancel_partial_payment_chargeback(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Partial - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3815,9 +3692,7 @@ cancel_payment_chargeback_refund(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3828,14 +3703,9 @@ cancel_payment_chargeback_refund(C) -> CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), RefundOk = hg_client_invoicing:refund_payment(IID, PID, RefundParams, Client), ?assertMatch(?chargeback_pending(), RefundError), @@ -3848,29 +3718,20 @@ reject_payment_chargeback_inconsistent(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))) ] = next_changes(IID, 2, Client), InconsistentParams = make_chargeback_reject_params(?cash(10, <<"USD">>)), - Inconsistent = hg_client_invoicing:reject_chargeback( - IID, PID, CBID, InconsistentParams, Client - ), + Inconsistent = hg_client_invoicing:reject_chargeback(IID, PID, CBID, InconsistentParams, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), ?assertMatch(?inconsistent_chargeback_currency(_), Inconsistent). @@ -3883,9 +3744,7 @@ reject_payment_chargeback(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3895,14 +3754,9 @@ reject_payment_chargeback(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3919,9 +3773,7 @@ reject_payment_chargeback_no_fees(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3931,14 +3783,9 @@ reject_payment_chargeback_no_fees(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -3955,9 +3802,7 @@ reject_payment_chargeback_new_levy(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -3970,14 +3815,9 @@ reject_payment_chargeback_new_levy(C) -> ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(RejectLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(CF1))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 4, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertNotEqual(CF0, CF1), @@ -3993,9 +3833,7 @@ accept_payment_chargeback_inconsistent(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4003,23 +3841,14 @@ accept_payment_chargeback_inconsistent(C) -> ] = next_changes(IID, 2, Client), InconsistentLevyParams = make_chargeback_accept_params(?cash(10, <<"USD">>), undefined), InconsistentBodyParams = make_chargeback_accept_params(undefined, ?cash(10, <<"USD">>)), - InconsistentLevy = hg_client_invoicing:accept_chargeback( - IID, PID, CBID, InconsistentLevyParams, Client - ), - InconsistentBody = hg_client_invoicing:accept_chargeback( - IID, PID, CBID, InconsistentBodyParams, Client - ), + InconsistentLevy = hg_client_invoicing:accept_chargeback(IID, PID, CBID, InconsistentLevyParams, Client), + InconsistentBody = hg_client_invoicing:accept_chargeback(IID, PID, CBID, InconsistentBodyParams, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentLevy), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentBody). @@ -4031,30 +3860,21 @@ accept_payment_chargeback_exceeded(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))) ] = next_changes(IID, 2, Client), ExceedBody = 200000, - ExceedParams = make_chargeback_accept_params( - ?cash(LevyAmount, <<"RUB">>), ?cash(ExceedBody, <<"RUB">>) - ), + ExceedParams = make_chargeback_accept_params(?cash(LevyAmount, <<"RUB">>), ?cash(ExceedBody, <<"RUB">>)), Exceeded = hg_client_invoicing:accept_chargeback(IID, PID, CBID, ExceedParams, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), ?assertMatch(?invoice_payment_amount_exceeded(_), Exceeded). @@ -4067,9 +3887,7 @@ accept_payment_chargeback_empty_params(C) -> LevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4079,13 +3897,8 @@ accept_payment_chargeback_empty_params(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), @@ -4105,9 +3918,7 @@ accept_payment_chargeback_twice(C) -> Body = ?cash(BodyAmount, <<"RUB">>), Levy = ?cash(LevyAmount, <<"RUB">>), CBParams1 = make_chargeback_params(Levy, Body), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams1, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams1, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4117,13 +3928,8 @@ accept_payment_chargeback_twice(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))) ] = next_changes(IID, 2, Client), Settlement1 = hg_accounting:get_balance(SID), CBParams2 = make_chargeback_params(Levy), @@ -4137,13 +3943,8 @@ accept_payment_chargeback_twice(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID2, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID2, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID2, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID2, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID2, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4165,9 +3966,7 @@ accept_payment_chargeback_new_body(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4179,14 +3978,9 @@ accept_payment_chargeback_new_body(C) -> ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_body_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))) ] = next_changes(IID, 4, Client), Settlement1 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -4204,9 +3998,7 @@ accept_payment_chargeback_new_levy(C) -> NewLevyAmount = 4000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4216,17 +4008,10 @@ accept_payment_chargeback_new_levy(C) -> AcceptParams = make_chargeback_accept_params(?cash(NewLevyAmount, <<"RUB">>), undefined), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(?cash(NewLevyAmount, <<"RUB">>))) - ), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(?cash(NewLevyAmount, <<"RUB">>)))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 5, Client), Settlement1 = hg_accounting:get_balance(SID), @@ -4242,9 +4027,7 @@ reopen_accepted_payment_chargeback_and_cancel_ok(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4253,42 +4036,24 @@ reopen_accepted_payment_chargeback_and_cancel_ok(C) -> AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), ReopenParams = make_chargeback_reopen_params(Levy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) - ), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(CBCF))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 4, Client), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed([]))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?payment_status_changed(?captured())) ] = next_changes(IID, 4, Client), ok. @@ -4300,9 +4065,7 @@ reopen_payment_chargeback_inconsistent(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4311,23 +4074,14 @@ reopen_payment_chargeback_inconsistent(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), InconsistentLevyParams = make_chargeback_reopen_params(?cash(10, <<"USD">>), undefined), InconsistentBodyParams = make_chargeback_reopen_params(Levy, ?cash(10, <<"USD">>)), - InconsistentLevy = hg_client_invoicing:reopen_chargeback( - IID, PID, CBID, InconsistentLevyParams, Client - ), - InconsistentBody = hg_client_invoicing:reopen_chargeback( - IID, PID, CBID, InconsistentBodyParams, Client - ), + InconsistentLevy = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, InconsistentLevyParams, Client), + InconsistentBody = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, InconsistentBodyParams, Client), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentLevy), ?assertMatch(?inconsistent_chargeback_currency(_), InconsistentBody). @@ -4338,9 +4092,7 @@ reopen_payment_chargeback_exceeded(C) -> LevyAmount = 5000, Levy = ?cash(LevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, _SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, _SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4349,14 +4101,9 @@ reopen_payment_chargeback_exceeded(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), ExceededParams = make_chargeback_reopen_params(Levy, ?cash(50000, <<"RUB">>)), Exceeded = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ExceededParams, Client), @@ -4373,9 +4120,7 @@ reopen_payment_chargeback_cancel(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4385,45 +4130,27 @@ reopen_payment_chargeback_cancel(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), CancelParams = make_chargeback_cancel_params(), ok = hg_client_invoicing:cancel_chargeback(IID, PID, CBID, CancelParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_cancelled()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_cancelled()))) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -4446,9 +4173,7 @@ reopen_payment_chargeback_reject(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4458,45 +4183,27 @@ reopen_payment_chargeback_reject(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), ok = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(?chargeback_stage_pre_arbitration()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(Levy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ?assertEqual(Paid - Cost - LevyAmount, maps:get(min_available_amount, Settlement0)), @@ -4519,9 +4226,7 @@ reopen_payment_chargeback_accept(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4531,14 +4236,9 @@ reopen_payment_chargeback_accept(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4546,26 +4246,16 @@ reopen_payment_chargeback_accept(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4589,9 +4279,7 @@ reopen_payment_chargeback_skip_stage_accept(C) -> Levy = ?cash(LevyAmount, <<"RUB">>), ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4601,14 +4289,9 @@ reopen_payment_chargeback_skip_stage_accept(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), NextStage = ?chargeback_stage_arbitration(), @@ -4617,26 +4300,16 @@ reopen_payment_chargeback_skip_stage_accept(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(NextStage))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4663,9 +4336,7 @@ reopen_payment_chargeback_accept_new_levy(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), AcceptLevy = ?cash(AcceptLevyAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4675,14 +4346,9 @@ reopen_payment_chargeback_accept_new_levy(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4690,28 +4356,18 @@ reopen_payment_chargeback_accept_new_levy(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(AcceptLevy, Body), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 5, Client), Settlement3 = hg_accounting:get_balance(SID), @@ -4737,9 +4393,7 @@ reopen_payment_chargeback_arbitration(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), ReopenArbLevy = ?cash(ReopenArbAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4749,14 +4403,9 @@ reopen_payment_chargeback_arbitration(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4764,27 +4413,17 @@ reopen_payment_chargeback_arbitration(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ReopenArbParams = make_chargeback_reopen_params(ReopenArbLevy), @@ -4792,26 +4431,16 @@ reopen_payment_chargeback_arbitration(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement4 = hg_accounting:get_balance(SID), AcceptParams = make_chargeback_accept_params(), ok = hg_client_invoicing:accept_chargeback(IID, PID, CBID, AcceptParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted())) - ), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_accepted()))), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PID, ?payment_status_changed(?charged_back())) ] = next_changes(IID, 3, Client), Settlement5 = hg_accounting:get_balance(SID), @@ -4841,9 +4470,7 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> ReopenLevy = ?cash(ReopenLevyAmount, <<"RUB">>), ReopenArbLevy = ?cash(ReopenArbAmount, <<"RUB">>), CBParams = make_chargeback_params(Levy), - {IID, PID, SID, CB} = start_chargeback( - C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>)) - ), + {IID, PID, SID, CB} = start_chargeback(C, Cost, CBParams, make_payment_params(?pmt_sys(<<"visa-ref">>))), CBID = CB#domain_InvoicePaymentChargeback.id, [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_created(CB))), @@ -4853,14 +4480,9 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> RejectParams = make_chargeback_reject_params(Levy), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 3, Client), Settlement1 = hg_accounting:get_balance(SID), ReopenParams = make_chargeback_reopen_params(ReopenLevy), @@ -4868,27 +4490,17 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(ReopenLevy))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement2 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 4, Client), Settlement3 = hg_accounting:get_balance(SID), ReopenArbParams = make_chargeback_reopen_params(ReopenArbLevy), @@ -4896,27 +4508,17 @@ reopen_payment_chargeback_arbitration_reopen_fails(C) -> [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_stage_changed(_))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_pending()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_pending()))) ] = next_changes(IID, 5, Client), Settlement4 = hg_accounting:get_balance(SID), ok = hg_client_invoicing:reject_chargeback(IID, PID, CBID, RejectParams, Client), [ ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_levy_changed(_))), - ?payment_ev( - PID, - ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected())) - ), + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_target_status_changed(?chargeback_status_rejected()))), ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_cash_flow_changed(_))), - ?payment_ev( - PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected())) - ) + ?payment_ev(PID, ?chargeback_ev(CBID, ?chargeback_status_changed(?chargeback_status_rejected()))) ] = next_changes(IID, 4, Client), Settlement5 = hg_accounting:get_balance(SID), Error = hg_client_invoicing:reopen_chargeback(IID, PID, CBID, ReopenArbParams, Client), @@ -4940,9 +4542,8 @@ start_chargeback(C, Cost, CBParams, PaymentParams) -> Client = cfg(client, C), PartyConfigRef = cfg(party_config_ref, C), PartyPair = cfg(party_client, C), - ShopConfigRef = hg_ct_helper:create_battle_ready_shop( - PartyConfigRef, ?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), {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _} = hg_invoice_utils:get_shop_account(Shop), @@ -4962,9 +4563,8 @@ start_chargeback_partial_capture(C, Cost, Partial, CBParams, PmtSys) -> PartyConfigRef = cfg(party_config_ref, C), Cash = ?cash(Partial, <<"RUB">>), PartyPair = cfg(party_client, C), - ShopConfigRef = hg_ct_helper:create_battle_ready_shop( - PartyConfigRef, ?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), {PartyConfigRef, _Party} = hg_party:get_party(PartyConfigRef), {ShopConfigRef, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef), {SettlementID, _} = hg_invoice_utils:get_shop_account(Shop), @@ -5033,9 +4633,7 @@ payment_refund_idempotency(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), PaymentID = execute_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), InvoiceID2 = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), RefundID = <<"1">>, ExternalID = <<"42">>, RefundParams1 = RefundParams0#payproc_InvoicePaymentRefundParams{ @@ -5082,9 +4680,7 @@ payment_refund_success(C) -> PartyClient ), 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 - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, capture}), Client), RefundParams = make_refund_params(), % not finished yet ?invalid_payment_status(?processed()) = @@ -5102,15 +4698,11 @@ payment_refund_success(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(Failure))), - ?payment_ev( - PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(Failure))) - ) + ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally RefundID = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), #domain_InvoicePaymentRefund{status = ?refund_succeeded()} = @@ -5132,9 +4724,7 @@ payment_refund_failure(C) -> PartyClient ), 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">>) - ), + PaymentParams = make_scenario_payment_params([good, good, fail], {hold, capture}, ?pmt_sys(<<"visa-ref">>)), PaymentID = process_payment(InvoiceID, PaymentParams, Client), RefundParams = make_refund_params(), % not finished yet @@ -5153,28 +4743,19 @@ payment_refund_failure(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev( - PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds))) - ) + ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally ?refund_id(RefundID) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID, Client), [ - ?payment_ev( - PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?trx_bound(?trx_info(_TrxID)))) - ), - ?payment_ev( - PaymentID, - ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure)))) - ), + ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?trx_bound(?trx_info(_TrxID))))), + ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure))))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_rollback_started(Failure))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 4, Client), @@ -5195,28 +4776,20 @@ payment_refund_success_after_callback(C) -> ), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % start invoice that will be refunded 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 - ), + 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 {URL, GoodForm} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, GoodForm}), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), % create a refund finally RefundParams = make_refund_params(), - ?refund_id(RefundID) = hg_client_invoicing:refund_payment( - InvoiceID, PaymentID, RefundParams, Client - ), + ?refund_id(RefundID) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID, Client), ?payment_ev( @@ -5282,15 +4855,11 @@ deadline_doesnt_affect_payment_refund(C) -> PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID0, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev( - PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds))) - ) + ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 2, Client), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create a refund finally RefundID = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), #domain_InvoicePaymentRefund{status = ?refund_succeeded()} = @@ -5329,15 +4898,11 @@ payment_manual_refund(C) -> [ ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_created(Refund0, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_rollback_started(NoFunds))), - ?payment_ev( - PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds))) - ) + ?payment_ev(PaymentID, ?refund_ev(RefundID0, ?refund_status_changed(?refund_failed(NoFunds)))) ] = next_changes(InvoiceID, 3, Client), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % prevent proxy access OriginalRevision = hg_domain:head(), Fixture = payment_manual_refund_fixture(OriginalRevision), @@ -5368,9 +4933,7 @@ payment_partial_refunds_success(C) -> RefundParams0 = make_refund_params(43000, <<"RUB">>), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 3000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % refund amount exceeds payment amount ?invoice_payment_amount_exceeded(_) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams0, Client), @@ -5530,9 +5093,7 @@ cant_start_simultaneous_partial_refunds(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 - ), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), ?operation_not_permitted() = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), @@ -5588,14 +5149,10 @@ retry_temporary_unavailability_refund(C) -> PartyClient ), InvoiceID = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - PaymentParams = make_scenario_payment_params( - [good, good, temp, temp], ?pmt_sys(<<"visa-ref">>) - ), + 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">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( - InvoiceID, PaymentID, RefundParams1, Client - ), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_payment_process_finish(InvoiceID, PaymentID, Client, 2), @@ -5634,24 +5191,16 @@ payment_refund_id_types(C) -> PaymentID = await_payment_capture(InvoiceID, PaymentID, Client), % top up merchant account InvoiceID2 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 42000, C), - _PaymentID2 = execute_payment( - InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID2 = execute_payment(InvoiceID2, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), % create refund RefundParams = #payproc_InvoicePaymentRefundParams{ reason = <<"42">>, cash = ?cash(5000, <<"RUB">>) }, % 0 - ManualRefundParams = RefundParams#payproc_InvoicePaymentRefundParams{ - transaction_info = TrxInfo - }, - ?refund_id(RefundID0) = hg_client_invoicing:refund_payment_manual( - InvoiceID, PaymentID, ManualRefundParams, Client - ), - PaymentID = await_partial_manual_refund_succeeded( - InvoiceID, PaymentID, RefundID0, TrxInfo, Client - ), + ManualRefundParams = RefundParams#payproc_InvoicePaymentRefundParams{transaction_info = TrxInfo}, + ?refund_id(RefundID0) = hg_client_invoicing:refund_payment_manual(InvoiceID, PaymentID, ManualRefundParams, Client), + PaymentID = await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID0, TrxInfo, Client), % 1 RefundID1 = execute_payment_refund(InvoiceID, PaymentID, RefundParams, Client), % 2 @@ -5662,9 +5211,7 @@ payment_refund_id_types(C) -> CustomIdManualParams, Client ), - PaymentID = await_partial_manual_refund_succeeded( - InvoiceID, PaymentID, RefundID2, TrxInfo, Client - ), + PaymentID = await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID2, TrxInfo, Client), % 3 CustomIdParams = RefundParams#payproc_InvoicePaymentRefundParams{id = <<"m3">>}, {exception, #base_InvalidRequest{}} = @@ -5690,9 +5237,7 @@ registered_payment_manual_refund_success(C) -> %% create balance InvoiceID1 = start_invoice(ShopConfigRef, <<"rubberduck">>, make_due_date(10), 50000, C), - _PaymentID1 = execute_payment( - InvoiceID1, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client - ), + _PaymentID1 = execute_payment(InvoiceID1, make_payment_params(?pmt_sys(<<"visa-ref">>)), Client), %% register_payment {InvoiceID, PaymentID} = register_invoice_payment(ShopConfigRef, Client, C), @@ -5724,9 +5269,7 @@ payment_hold_double_cancellation(C) -> InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 10000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertEqual( - ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client) - ), + ?assertEqual(ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client)), Result = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5734,9 +5277,7 @@ payment_hold_double_cancellation(C) -> payment_hold_cancellation_captured(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment( - InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), ?assertEqual(ok, hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client)), Result = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5758,9 +5299,7 @@ payment_hold_auto_cancellation(C) -> payment_hold_capturing(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment( - InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), PaymentID = await_payment_capture(InvoiceID, PaymentID, <<"ok">>, Client). @@ -5768,9 +5307,7 @@ payment_hold_capturing(C) -> payment_hold_double_capturing(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment( - InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), ?assertEqual(ok, hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client)), Result = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5779,12 +5316,8 @@ payment_hold_double_capturing(C) -> payment_hold_capturing_cancelled(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - PaymentID = process_payment( - InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client - ), - ?assertEqual( - ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client) - ), + PaymentID = process_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}), Client), + ?assertEqual(ok, hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"whynot">>, Client)), Result = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"ok">>, Client), ?assertMatch({exception, #payproc_InvalidPaymentStatus{}}, Result). @@ -5891,9 +5424,7 @@ invalid_permit_partial_capture_in_service(C) -> PaymentID = process_payment(InvoiceID, PaymentParams, Client), Cash = ?cash(10000, <<"RUB">>), Reason = <<"ok">>, - ?operation_not_permitted() = hg_client_invoicing:capture_payment( - InvoiceID, PaymentID, Reason, Cash, Client - ). + ?operation_not_permitted() = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, Reason, Cash, Client). -spec invalid_permit_partial_capture_in_provider(config()) -> _ | no_return(). invalid_permit_partial_capture_in_provider(C) -> @@ -5903,9 +5434,7 @@ invalid_permit_partial_capture_in_provider(C) -> PaymentID = process_payment(InvoiceID, PaymentParams, Client), Cash = ?cash(10000, <<"RUB">>), Reason = <<"ok">>, - ?operation_not_permitted() = hg_client_invoicing:capture_payment( - InvoiceID, PaymentID, Reason, Cash, Client - ). + ?operation_not_permitted() = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, Reason, Cash, Client). -spec payment_hold_auto_capturing(config()) -> _ | no_return(). payment_hold_auto_capturing(C) -> @@ -5915,9 +5444,7 @@ payment_hold_auto_capturing(C) -> PaymentID = start_payment(InvoiceID, PaymentParams, Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), _ = assert_success_post_request(get_post_request(UserInteraction)), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), _ = assert_invalid_post_request(get_post_request(UserInteraction)), PaymentID = await_payment_capture(InvoiceID, PaymentID, ?timeout_reason(), Client). @@ -5927,27 +5454,17 @@ rounding_cashflow_volume(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C), PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = 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), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), 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 - ), - ?cash(1, <<"RUB">>) = get_cashflow_volume( - {system, settlement}, {external, outcome}, CF, CFContext - ), + ?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), + ?cash(1, <<"RUB">>) = get_cashflow_volume({system, settlement}, {external, outcome}, CF, CFContext), PaymentID = await_payment_capture(InvoiceID, PaymentID, Client). get_cashflow_volume(Source, Destination, CF, CFContext) -> @@ -5958,9 +5475,7 @@ convert_transaction_account(Entity, Context) -> %% --define(repair_set_timer(T), #repair_ComplexAction{ - timer = {set_timer, #repair_SetTimerAction{timer = T}} -}). +-define(repair_set_timer(T), #repair_ComplexAction{timer = {set_timer, #repair_SetTimerAction{timer = T}}}). -define(repair_mark_removal(), #repair_ComplexAction{remove = #repair_RemoveAction{}}). -spec adhoc_repair_working_failed(config()) -> _ | no_return(). @@ -5978,9 +5493,7 @@ adhoc_repair_working_failed(C) -> adhoc_repair_failed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -5990,9 +5503,7 @@ adhoc_repair_failed_succeeded(C) -> ] = next_changes(InvoiceID, 2, Client), % assume no more events here since machine is FUBAR already timeout = next_change(InvoiceID, 2000, Client), - Change = ?payment_ev( - PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) - ), + Change = ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), ok = repair_invoice(InvoiceID, [Change], ?repair_set_timer({timeout, 0}), undefined, Client), Change = next_change(InvoiceID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?processed())) = @@ -6019,9 +5530,7 @@ adhoc_repair_force_removal(C) -> adhoc_repair_invalid_changes_failed(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -6047,9 +5556,7 @@ adhoc_repair_invalid_changes_failed(C) -> {{woody_error, {external, result_unexpected, _}}, _}, repair_invoice(InvoiceID, InvalidChanges2, Client) ), - Change = ?payment_ev( - PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())) - ), + Change = ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))), ?assertEqual( ok, repair_invoice(InvoiceID, [Change], Client) @@ -6093,9 +5600,7 @@ adhoc_repair_force_invalid_transition(C) -> payment_with_offsite_preauth_success(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), @@ -6123,9 +5628,7 @@ payment_with_offsite_preauth_success(C) -> payment_with_offsite_preauth_failed(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(3), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds_offsite, ?pmt_sys(<<"jcb-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), _UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), @@ -6162,22 +5665,17 @@ repair_fail_routing_succeeded(C) -> Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), %% Invoice - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"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), %% Payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -6192,9 +5690,7 @@ repair_fail_routing_succeeded(C) -> #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{ - id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY - }, + limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, value = 10000 } ] @@ -6204,17 +5700,13 @@ repair_fail_routing_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, fail_pre_processing, Client), %% Check final status - ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change( - InvoiceID, Client - ), + ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change(InvoiceID, Client), %% Check limits rolled back #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{ - id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY - }, + limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, value = 0 } ] @@ -6232,22 +5724,17 @@ repair_fail_cash_flow_building_succeeded(C) -> Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), PartyClient = cfg(party_client, C), #{party_config_ref := PartyConfigRef} = cfg(limits, C), - ShopConfigRef = hg_ct_helper:create_shop( - PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ), + ShopConfigRef = hg_ct_helper:create_shop(PartyConfigRef, ?cat(8), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient), %% Invoice - InvoiceParams = make_invoice_params( - PartyConfigRef, ShopConfigRef, <<"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), %% Payment PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)), - ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -6262,9 +5749,7 @@ repair_fail_cash_flow_building_succeeded(C) -> #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{ - id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY - }, + limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, value = 10000 } ] @@ -6274,17 +5759,13 @@ repair_fail_cash_flow_building_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, fail_pre_processing, Client), %% Check final status - ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change( - InvoiceID, Client - ), + ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure}))) = next_change(InvoiceID, Client), %% Check limits rolled back #{ Route := [ #payproc_TurnoverLimitValue{ - limit = #domain_TurnoverLimit{ - id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY - }, + limit = #domain_TurnoverLimit{id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY}, value = 0 } ] @@ -6294,9 +5775,7 @@ repair_fail_cash_flow_building_succeeded(C) -> repair_fail_session_on_processed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -6315,10 +5794,7 @@ repair_fail_session_on_processed_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, {fail_session, Failure}, Client), [ - ?payment_ev( - PaymentID, - ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) - ), + ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -6341,10 +5817,7 @@ repair_fail_suspended_session_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, {fail_session, Failure}, Client), [ - ?payment_ev( - PaymentID, - ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) - ), + ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -6353,9 +5826,7 @@ repair_fail_suspended_session_succeeded(C) -> repair_complex_second_scenario_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), TrxID = hg_utils:construct_complex_id([PaymentID, <<"brovider">>]), @@ -6372,10 +5843,7 @@ repair_complex_second_scenario_succeeded(C) -> ok = repair_invoice_with_scenario(InvoiceID, Scenarios, Client), [ - ?payment_ev( - PaymentID, - ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure}))) - ), + ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_failed({failure, Failure})))), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_changes(InvoiceID, 3, Client). @@ -6387,15 +5855,11 @@ repair_fulfill_session_on_refund_succeeded(C) -> PaymentParams = make_scenario_payment_params([good, good, error], ?pmt_sys(<<"visa-ref">>)), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), RefundParams1 = make_refund_params(1000, <<"RUB">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( - InvoiceID, PaymentID, RefundParams1, Client - ), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), timeout = next_change(InvoiceID, 2000, Client), - ok = repair_invoice_with_scenario( - InvoiceID, {fulfill_session, ?trx_info(PaymentID, #{})}, Client - ), + ok = repair_invoice_with_scenario(InvoiceID, {fulfill_session, ?trx_info(PaymentID, #{})}, Client), PaymentID = await_refund_payment_process_finish(InvoiceID, PaymentID, Client), ?payment_state( ?payment_w_status(?captured()), @@ -6409,20 +5873,13 @@ repair_fail_session_on_refund_succeeded(C) -> PaymentParams = make_scenario_payment_params([good, good, error], ?pmt_sys(<<"visa-ref">>)), PaymentID = execute_payment(InvoiceID, PaymentParams, Client), RefundParams1 = make_refund_params(1000, <<"RUB">>), - ?refund_id(RefundID1) = hg_client_invoicing:refund_payment( - InvoiceID, PaymentID, RefundParams1, Client - ), + ?refund_id(RefundID1) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, RefundParams1, Client), PaymentID = await_refund_created(InvoiceID, PaymentID, RefundID1, Client), PaymentID = await_refund_session_started(InvoiceID, PaymentID, RefundID1, Client), timeout = next_change(InvoiceID, 2000, Client), - ok = repair_invoice_with_scenario( - InvoiceID, {fail_session, construct_authorization_failure()}, Client - ), + ok = repair_invoice_with_scenario(InvoiceID, {fail_session, construct_authorization_failure()}, Client), [ - ?payment_ev( - PaymentID, - ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure)))) - ), + ?payment_ev(PaymentID, ?refund_ev(ID, ?session_ev(?refunded(), ?session_finished(?session_failed(Failure))))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_rollback_started(Failure))), ?payment_ev(PaymentID, ?refund_ev(ID, ?refund_status_changed(?refund_failed(Failure)))) ] = next_changes(InvoiceID, 3, Client), @@ -6435,9 +5892,7 @@ repair_fail_session_on_refund_succeeded(C) -> repair_fulfill_session_on_processed_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) = @@ -6496,9 +5951,7 @@ repair_fulfill_session_on_captured_succeeded(C) -> repair_fulfill_session_with_trx_succeeded(C) -> Client = cfg(client, C), InvoiceID = start_invoice(<<"rubbercrack">>, make_due_date(10), 42000, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(unexpected_failure_no_trx, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), PaymentID = start_payment(InvoiceID, PaymentParams, Client), ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) = @@ -6596,10 +6049,7 @@ cascade_fixture(Revision, C) -> ?delegate( ?partycond( PartyConfigRef, - {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, C) - )} + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, C))} ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID)) ), @@ -6608,10 +6058,7 @@ cascade_fixture(Revision, C) -> PartyConfigRef, {shop_is, shop_id_from_config_ref( - cfg( - {shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, - C - ) + cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID}, C) )} ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID)) @@ -6620,19 +6067,14 @@ cascade_fixture(Revision, C) -> ?partycond( PartyConfigRef, {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, C) - )} + 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( PartyConfigRef, - {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, C) - )} + {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)) ), @@ -6641,10 +6083,7 @@ cascade_fixture(Revision, C) -> PartyConfigRef, {shop_is, shop_id_from_config_ref( - cfg( - {shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, - C - ) + 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)) @@ -6652,10 +6091,7 @@ cascade_fixture(Revision, C) -> ?delegate( ?partycond( PartyConfigRef, - {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, C) - )} + {shop_is, shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, C))} ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID)) ), @@ -6663,9 +6099,7 @@ cascade_fixture(Revision, C) -> ?partycond( PartyConfigRef, {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C) - )} + shop_id_from_config_ref(cfg({shop_config_ref, ?PAYMENT_CASCADE_DEADLINE_FAILURES_ID}, C))} ), ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID)) ), @@ -6673,9 +6107,7 @@ cascade_fixture(Revision, C) -> ?partycond( PartyConfigRef, {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, C) - )} + 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)) ), @@ -6683,19 +6115,14 @@ cascade_fixture(Revision, C) -> ?partycond( PartyConfigRef, {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID}, C) - )} + 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( PartyConfigRef, - {shop_is, - shop_id_from_config_ref( - cfg({shop_config_ref, ?PAYMENT_CASCADE_FAIL_UI_ID}, C) - )} + {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)) ) @@ -6722,9 +6149,7 @@ init_route_cascading_group(C1) -> C2 = [ { {shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_ID}, - hg_ct_helper:create_shop( - PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ) + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { {shop_config_ref, ?PAYMENT_BIG_CASCADE_SUCCESS_ID}, @@ -6750,9 +6175,7 @@ init_route_cascading_group(C1) -> }, { {shop_config_ref, ?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID}, - hg_ct_helper:create_shop( - PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ) + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { {shop_config_ref, ?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID}, @@ -6767,15 +6190,11 @@ init_route_cascading_group(C1) -> }, { {shop_config_ref, ?PAYMENT_CASCADE_FAILURES_ID}, - hg_ct_helper:create_shop( - PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient - ) + hg_ct_helper:create_shop(PartyConfigRef, ?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 - ) + hg_ct_helper:create_shop(PartyConfigRef, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), PartyClient) }, { {shop_config_ref, ?PAYMENT_CASCADE_FAIL_PROVIDER_ERROR_ID}, @@ -6908,12 +6327,8 @@ payment_cascade_success_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 2)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 2))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))) ]} ) ]. @@ -6929,12 +6344,8 @@ payment_cascade_success(C) -> make_due_date(10), make_cash(Amount) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( - InvoiceParams, Client - ), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -6946,9 +6357,7 @@ payment_cascade_success(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -6964,11 +6373,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), @@ -6979,10 +6388,7 @@ payment_cascade_success(C) -> ?payment_ev(PaymentID, ?cash_flow_changed(_CashFlow2)) ] = next_changes(InvoiceID, 2, Client), - ?assertMatch( - #domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))}, - Route2 - ), + ?assertMatch(#domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_ID + 1))}, Route2), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(TrxID2)))), @@ -7012,11 +6418,7 @@ payment_cascade_success(C) -> ), %% At the end of this scenario limit must be accounted only once. _ = hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, - configured_limit_version(?LIMIT_ID4, C), - InitialAccountedAmount + Amount, - PaymentFinal, - Invoice + ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount + Amount, PaymentFinal, Invoice ), #payproc_InvoicePaymentExplanation{ explained_routes = [ @@ -7090,13 +6492,8 @@ payment_cascade_success_w_refund_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID + 1)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID + 1))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_SUCCESS_W_REFUND_ID))) ]} ) ]. @@ -7105,16 +6502,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_config_ref, C), <<"rubberduck">>, make_due_date(10), 42000, C - ), - {PaymentID, [_FailedRoute, _UsedRoute]} = execute_payment_w_cascade( - InvoiceID, PaymentParams, Client, 1 - ), + 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_config_ref, 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()} = @@ -7243,27 +6634,13 @@ payment_big_cascade_success_fixture(Revision, _C) -> <<"Big Main with cascading">>, %% 7 route candidates, 6 to fail {candidates, [ - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 2)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 3)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 4)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 5)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 6)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 7)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 2))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 3))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 4))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 5))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 6))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 7))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1))) ]} ) ]). @@ -7338,14 +6715,8 @@ payment_cascade_limit_overflow_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 2)) - ), - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 1)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 2))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_LIMIT_OVERFLOW_ID + 1))) ]} ) ]. @@ -7361,12 +6732,8 @@ payment_cascade_limit_overflow(C) -> make_due_date(10), make_cash(Amount) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( - InvoiceParams, Client - ), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -7378,9 +6745,7 @@ payment_cascade_limit_overflow(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -7396,9 +6761,7 @@ payment_cascade_limit_overflow(C) -> ] = next_changes(InvoiceID, 4, Client), {Route1, _CashFlow1, _TrxID1, Failure1} = await_cascade_triggering(InvoiceID, PaymentID, Client), - ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> ok end), %% And again but no route found [ ?payment_ev(PaymentID, ?route_changed(Route2, Candidates2)), @@ -7419,11 +6782,7 @@ payment_cascade_limit_overflow(C) -> ?invoice_status_changed(?invoice_cancelled(<<"overdue">>)) = next_change(InvoiceID, Client), %% At the end of this scenario limit must not be changed. hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, - configured_limit_version(?LIMIT_ID4, C), - InitialAccountedAmount, - FinalPayment, - Invoice + ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount, FinalPayment, Invoice ). -spec payment_big_cascade_success(config()) -> test_return(). @@ -7437,12 +6796,8 @@ payment_big_cascade_success(C) -> make_due_date(10), make_cash(Amount) ), - ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create( - InvoiceParams, Client - ), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + ?invoice_state(Invoice = ?invoice(InvoiceID)) = hg_client_invoicing:create(InvoiceParams, Client), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), Context = #base_Content{ type = <<"application/x-erlang-binary">>, data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]}) @@ -7454,9 +6809,7 @@ payment_big_cascade_success(C) -> payer_session_info = PayerSessionInfo, context = Context }, - #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment( - InvoiceID, PaymentParams, Client - ), + #payproc_InvoicePayment{payment = Payment} = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, Client), Limit = hg_limiter_helper:maybe_uninitialized_limit( hg_limiter_helper:get_payment_limit_amount( @@ -7493,9 +6846,7 @@ payment_big_cascade_success(C) -> ] = next_changes(InvoiceID, 2, Client), ?assertMatch( - #domain_PaymentRoute{ - provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1)) - }, + #domain_PaymentRoute{provider = ?prv(?CASCADE_ID_RANGE(?PAYMENT_BIG_CASCADE_SUCCESS_ID + 1))}, RouteFinal ), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), @@ -7522,11 +6873,7 @@ payment_big_cascade_success(C) -> ), %% At the end of this scenario limit must be accounted only once. hg_limiter_helper:assert_payment_limit_amount( - ?LIMIT_ID4, - configured_limit_version(?LIMIT_ID4, C), - InitialAccountedAmount + Amount, - PaymentFinal, - Invoice + ?LIMIT_ID4, configured_limit_version(?LIMIT_ID4, C), InitialAccountedAmount + Amount, PaymentFinal, Invoice ). payment_cascade_fail_provider_error_fixture_pre(Revision, _C) -> @@ -7625,9 +6972,7 @@ payment_cascade_fail_provider_error(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7716,9 +7061,7 @@ payment_cascade_fail_ui_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID)), <<"1 fail, 2 with UI, 3 never reached">>, {candidates, [ - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID + I)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_UI_ID + I))) || I <- lists:reverse(lists:seq(1, 3)) ]} ) @@ -7729,9 +7072,7 @@ payment_cascade_fail_ui(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - preauth_3ds, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(preauth_3ds, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7742,9 +7083,7 @@ payment_cascade_fail_ui(C) -> ] = next_changes(InvoiceID, 4, Client), {_Route1, _CashFlow1, _TrxID1, Failure1} = await_cascade_triggering(InvoiceID, PaymentID, Client), - ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure1, fun({authorization_failed, {unknown, _}}) -> ok end), %% And again with UI [ ?payment_ev(PaymentID, ?route_changed(_Route2)), @@ -7753,9 +7092,7 @@ payment_cascade_fail_ui(C) -> UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client), {URL, Form} = get_post_request(UserInteraction), _ = assert_success_post_request({URL, Form}), - ok = await_payment_process_interaction_completion( - InvoiceID, PaymentID, UserInteraction, Client - ), + ok = await_payment_process_interaction_completion(InvoiceID, PaymentID, UserInteraction, Client), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(_TrxID2)))), ?payment_ev( @@ -7767,11 +7104,7 @@ payment_cascade_fail_ui(C) -> next_changes(InvoiceID, 3, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure2}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure2, fun( - {preauthorization_failed, {unknown, _}} - ) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun({preauthorization_failed, {unknown, _}}) -> ok end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -7848,14 +7181,8 @@ payment_cascade_fail_wo_route_candidates_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID)), <<"2 routes with failing providers">>, {candidates, [ - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 1)) - ), - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 2)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 1))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_ROUTE_CANDIDATES_ID + 2))) ]} ) ]). @@ -7918,9 +7245,7 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> data = #domain_Terminal{ name = <<"Brominal 1">>, description = <<"Brominal 1">>, - provider_ref = ?prv( - ?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1) - ) + provider_ref = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) } }}, {terminal, #domain_TerminalObject{ @@ -7928,9 +7253,7 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> data = #domain_Terminal{ name = <<"Not-Brominal">>, description = <<"Not-Brominal">>, - provider_ref = ?prv( - ?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2) - ) + provider_ref = ?prv(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) } }}, hg_ct_fixture:construct_payment_routing_ruleset( @@ -7938,12 +7261,10 @@ payment_cascade_fail_wo_available_attempt_limit_fixture(Revision, _C) -> <<"Main with cascading">>, {candidates, [ ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 2)) ), ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) + {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAIL_WO_AVAILABLE_ATTEMPT_LIMIT_ID + 1)) ) ]} ) @@ -7954,9 +7275,7 @@ payment_cascade_fail_wo_available_attempt_limit(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -7969,11 +7288,7 @@ payment_cascade_fail_wo_available_attempt_limit(C) -> await_cascade_triggering(InvoiceID, PaymentID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure, fun( - {preauthorization_failed, {card_blocked, _}} - ) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure, fun({preauthorization_failed, {card_blocked, _}}) -> ok end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -8039,12 +7354,8 @@ payment_cascade_failures_fixture(Revision, _C) -> ?ruleset(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID)), <<"Main with cascading">>, {candidates, [ - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 1)) - ), - ?candidate( - {constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 2)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 1))), + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_FAILURES_ID + 2))) ]} ) ]. @@ -8054,9 +7365,7 @@ payment_cascade_failures(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = make_payment_params(PaymentTool, Session, instant), hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -8067,21 +7376,13 @@ payment_cascade_failures(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), %% And again {_Route2, _CashFlow2, _TrxID2, Failure2} = await_cascade_triggering(InvoiceID, PaymentID, Client), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure2}))) = next_change(InvoiceID, Client), - ok = payproc_errors:match('PaymentFailure', Failure2, fun( - {preauthorization_failed, {card_blocked, _}} - ) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun({preauthorization_failed, {card_blocked, _}}) -> ok end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(Payment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -8153,10 +7454,7 @@ payment_cascade_deadline_failures_fixture(Revision, _C) -> ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 1)), 2000 ), - ?candidate( - {constant, true}, - ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 2)) - ) + ?candidate({constant, true}, ?trm(?CASCADE_ID_RANGE(?PAYMENT_CASCADE_DEADLINE_FAILURES_ID + 2))) ]} ) ]. @@ -8166,13 +7464,9 @@ payment_cascade_deadline_failures(C) -> Client = cfg(client, C), Amount = 42000, InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - no_preauth, ?pmt_sys(<<"visa-ref">>) - ), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)), PaymentParams = (make_payment_params(PaymentTool, Session, instant))#payproc_InvoicePaymentParams{ - processing_deadline = hg_datetime:add_time_span( - #base_TimeSpan{seconds = 2}, hg_datetime:format_now() - ) + processing_deadline = hg_datetime:add_time_span(#base_TimeSpan{seconds = 2}, hg_datetime:format_now()) }, hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client), [ @@ -8183,11 +7477,7 @@ payment_cascade_deadline_failures(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), %% And again ?payment_ev(PaymentID, ?route_changed(_Route2)) = next_change(InvoiceID, Client), @@ -8217,12 +7507,10 @@ payment_tool_contact_info_passed_to_provider(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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( @@ -8237,12 +7525,8 @@ payment_tool_contact_info_passed_to_provider(C) -> make_payment_params_with_contact_info_assertion(PmtSys) -> String = <<"STRING">>, - ContactInfo = ?contact_info( - String, String, String, String, String, String, String, String, String, String, String - ), - {PaymentTool, Session} = hg_dummy_provider:make_payment_tool( - {assert_contact_info, ContactInfo}, PmtSys - ), + ContactInfo = ?contact_info(String, String, String, String, String, String, String, String, String, String, String), + {PaymentTool, Session} = hg_dummy_provider:make_payment_tool({assert_contact_info, ContactInfo}, PmtSys), #payproc_InvoicePaymentParams{ payer = {payment_resource, #payproc_PaymentResourcePayerParams{ @@ -8486,9 +7770,7 @@ repair_invoice(InvoiceID, Changes, Action, Params, Client) -> hg_client_invoicing:repair(InvoiceID, Changes, Action, Params, Client). create_repair_scenario(fail_pre_processing) -> - Failure = payproc_errors:construct( - 'PaymentFailure', {no_route_found, {unknown, ?err_gen_failure()}} - ), + Failure = payproc_errors:construct('PaymentFailure', {no_route_found, {unknown, ?err_gen_failure()}}), {'fail_pre_processing', #'payproc_InvoiceRepairFailPreProcessing'{failure = Failure}}; create_repair_scenario(skip_inspector) -> {'skip_inspector', #'payproc_InvoiceRepairSkipInspector'{risk_score = low}}; @@ -8499,9 +7781,7 @@ create_repair_scenario(fulfill_session) -> create_repair_scenario({fulfill_session, Trx}) -> {'fulfill_session', #'payproc_InvoiceRepairFulfillSession'{trx = Trx}}; create_repair_scenario(Scenarios) when is_list(Scenarios) -> - {'complex', #'payproc_InvoiceRepairComplex'{ - scenarios = [create_repair_scenario(S) || S <- Scenarios] - }}. + {'complex', #'payproc_InvoiceRepairComplex'{scenarios = [create_repair_scenario(S) || S <- Scenarios]}}. repair_invoice_with_scenario(InvoiceID, Scenario, Client) -> hg_client_invoicing:repair_scenario(InvoiceID, create_repair_scenario(Scenario), Client). @@ -8615,25 +7895,18 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client) -> hg_invoice_helper:await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Client). await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client) -> - hg_invoice_helper:await_payment_capture_finish( - InvoiceID, PaymentID, Reason, Cost, Cart, Client - ). + hg_invoice_helper:await_payment_capture_finish(InvoiceID, PaymentID, Reason, Cost, Cart, Client). await_payment_cancel(InvoiceID, PaymentID, Reason, Client) -> [ ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_started())), - ?payment_ev( - PaymentID, - ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded())) - ), + ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_changes(InvoiceID, 3, Client), PaymentID. await_payment_process_timeout(InvoiceID, PaymentID, Client) -> - {failed, PaymentID, ?operation_timeout()} = await_payment_process_failure( - InvoiceID, PaymentID, Client - ), + {failed, PaymentID, ?operation_timeout()} = await_payment_process_failure(InvoiceID, PaymentID, Client), PaymentID. await_payment_process_failure(InvoiceID, PaymentID, Client) -> @@ -8661,10 +7934,7 @@ await_partial_manual_refund_succeeded(InvoiceID, PaymentID, RefundID, TrxInfo, C ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_created(_Refund, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_started()))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?trx_bound(TrxInfo)))), - ?payment_ev( - PaymentID, - ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) - ), + ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_status_changed(?refund_succeeded()))) ] = next_changes(InvoiceID, 5, Client), PaymentID. @@ -8688,10 +7958,7 @@ await_refund_payment_process_finish(InvoiceID, PaymentID, Client, Restarts) -> PaymentID = await_sessions_restarts(PaymentID, ?refunded(), InvoiceID, Client, Restarts), [ ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?trx_bound(_)))), - ?payment_ev( - PaymentID, - ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) - ), + ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), ?payment_ev(PaymentID, ?refund_ev(_, ?refund_status_changed(?refund_succeeded()))) ] = next_changes(InvoiceID, 3, Client), PaymentID. @@ -8700,10 +7967,7 @@ await_refund_payment_complete(InvoiceID, PaymentID, Client) -> PaymentID = await_sessions_restarts(PaymentID, ?refunded(), InvoiceID, Client, 0), [ ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?trx_bound(_)))), - ?payment_ev( - PaymentID, - ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) - ), + ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))), ?payment_ev(PaymentID, ?refund_ev(_, ?refund_status_changed(?refund_succeeded()))), ?payment_ev(PaymentID, ?payment_status_changed(?refunded())) ] = next_changes(InvoiceID, 4, Client), @@ -8711,13 +7975,9 @@ await_refund_payment_complete(InvoiceID, PaymentID, Client) -> await_sessions_restarts(PaymentID, _Target, _InvoiceID, _Client, 0) -> PaymentID; -await_sessions_restarts(PaymentID, ?refunded() = Target, InvoiceID, Client, Restarts) when - Restarts > 0 --> +await_sessions_restarts(PaymentID, ?refunded() = Target, InvoiceID, Client, Restarts) when Restarts > 0 -> [ - ?payment_ev( - PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_finished(?session_failed(_)))) - ), + ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_finished(?session_failed(_))))), ?payment_ev(PaymentID, ?refund_ev(_, ?session_ev(Target, ?session_started()))) ] = next_changes(InvoiceID, 2, Client), await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts - 1); @@ -8736,10 +7996,7 @@ await_sessions_restarts( ) ) = next_change(InvoiceID, Client), - ?payment_ev( - PaymentID, - ?session_ev(?captured(Reason, Cost, Cart, _), ?session_started()) - ) = + ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, Cart, _), ?session_started())) = next_change(InvoiceID, Client), await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts - 1); await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts) when Restarts > 0 -> @@ -8785,9 +8042,7 @@ execute_payment(InvoiceID, Params, Client) -> hg_invoice_helper:execute_payment(InvoiceID, Params, Client). execute_payment_w_cascade(InvoiceID, Params, Client, CascadeCount) when CascadeCount > 0 -> - #payproc_InvoicePayment{payment = _Payment} = hg_client_invoicing:start_payment( - InvoiceID, Params, Client - ), + #payproc_InvoicePayment{payment = _Payment} = hg_client_invoicing:start_payment(InvoiceID, Params, Client), [ ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))), ?payment_ev(PaymentID, ?shop_limit_initiated()), @@ -8815,25 +8070,15 @@ execute_payment_w_cascade(InvoiceID, Params, Client, CascadeCount) when CascadeC execute_payment_adjustment(InvoiceID, PaymentID, Params, Client) -> ?adjustment(AdjustmentID, ?adjustment_pending()) = - Adjustment = hg_client_invoicing:create_payment_adjustment( - InvoiceID, PaymentID, Params, Client - ), + Adjustment = hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, Params, Client), [ ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed())) - ), - ?payment_ev( - PaymentID, - ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) - ) + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), + ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) ] = next_changes(InvoiceID, 3, Client), AdjustmentID. -execute_payment_refund( - InvoiceID, PaymentID, #payproc_InvoicePaymentRefundParams{cash = undefined} = Params, Client -) -> +execute_payment_refund(InvoiceID, PaymentID, #payproc_InvoicePaymentRefundParams{cash = undefined} = Params, Client) -> execute_payment_refund_complete(InvoiceID, PaymentID, Params, Client); execute_payment_refund(InvoiceID, PaymentID, Params, Client) -> ?refund_id(RefundID) = hg_client_invoicing:refund_payment(InvoiceID, PaymentID, Params, Client), @@ -8843,17 +8088,12 @@ execute_payment_refund(InvoiceID, PaymentID, Params, Client) -> RefundID. execute_payment_manual_refund(InvoiceID, PaymentID, Params, Client) -> - ?refund_id(RefundID) = hg_client_invoicing:refund_payment_manual( - InvoiceID, PaymentID, Params, Client - ), + ?refund_id(RefundID) = hg_client_invoicing:refund_payment_manual(InvoiceID, PaymentID, Params, Client), [ ?payment_ev(PaymentID, ?refund_ev(RefundID, ?refund_created(_Refund, _, TrxInfo))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_started()))), ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?trx_bound(TrxInfo)))), - ?payment_ev( - PaymentID, - ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded()))) - ) + ?payment_ev(PaymentID, ?refund_ev(RefundID, ?session_ev(?refunded(), ?session_finished(?session_succeeded())))) ] = next_changes(InvoiceID, 4, Client), _ = await_refund_succeeded(InvoiceID, PaymentID, Client), RefundID. @@ -8874,20 +8114,13 @@ execute_payment_chargeback(InvoiceID, PaymentID, Params, Client) -> ?payment_ev(PaymentID, ?chargeback_ev(ChargebackID, ?chargeback_cash_flow_changed(_))) ] = next_changes(InvoiceID, 2, Client), AcceptParams = make_chargeback_accept_params(), - ok = hg_client_invoicing:accept_chargeback( - InvoiceID, PaymentID, ChargebackID, AcceptParams, Client - ), + ok = hg_client_invoicing:accept_chargeback(InvoiceID, PaymentID, ChargebackID, AcceptParams, Client), [ ?payment_ev( PaymentID, - ?chargeback_ev( - ChargebackID, ?chargeback_target_status_changed(?chargeback_status_accepted()) - ) - ), - ?payment_ev( - PaymentID, - ?chargeback_ev(ChargebackID, ?chargeback_status_changed(?chargeback_status_accepted())) + ?chargeback_ev(ChargebackID, ?chargeback_target_status_changed(?chargeback_status_accepted())) ), + ?payment_ev(PaymentID, ?chargeback_ev(ChargebackID, ?chargeback_status_changed(?chargeback_status_accepted()))), ?payment_ev(PaymentID, ?payment_status_changed(?charged_back())) ] = next_changes(InvoiceID, 3, Client), ChargebackID. @@ -8906,9 +8139,7 @@ payment_risk_score_check(Cat, C, PmtSys) -> InvoiceID1 = start_invoice(ShopID, <<"rubberduck">>, make_due_date(10), 42000, C), % Invoice PaymentParams = make_payment_params(PmtSys), - ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment( - InvoiceID1, PaymentParams, Client - ), + ?payment_state(?payment(PaymentID1)) = hg_client_invoicing:start_payment(InvoiceID1, PaymentParams, Client), ?payment_ev(PaymentID1, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID1, Client), % default low risk score... @@ -8950,15 +8181,11 @@ construct_domain_fixture() -> payment_methods = {decisions, [ #domain_PaymentMethodDecision{ - if_ = ?partycond( - ?PARTY_CONFIG_REF_DEPRIVED_1, undefined - ), + if_ = ?partycond(?PARTY_CONFIG_REF_DEPRIVED_1, undefined), then_ = {value, ordsets:new()} }, #domain_PaymentMethodDecision{ - if_ = ?partycond( - ?PARTY_CONFIG_REF_DEPRIVED_2, undefined - ), + if_ = ?partycond(?PARTY_CONFIG_REF_DEPRIVED_2, undefined), then_ = {value, ordsets:new()} }, #domain_PaymentMethodDecision{ @@ -8972,10 +8199,7 @@ construct_domain_fixture() -> ?pmt(payment_terminal, ?pmt_srv(<<"euroset-ref">>)), ?pmt(digital_wallet, ?pmt_srv(<<"qiwi-ref">>)), ?pmt(bank_card, ?bank_card_no_cvv(<<"visa-ref">>)), - ?pmt( - bank_card, - ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>) - ), + ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)), ?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>)), ?pmt(mobile, ?mob(<<"mts-ref">>)) ])} @@ -8988,8 +8212,7 @@ construct_domain_fixture() -> {condition, {payment_tool, {crypto_currency, #domain_CryptoCurrencyCondition{ - definition = - {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} + definition = {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} }}}}, then_ = {value, @@ -9200,9 +8423,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"mastercard-ref">> - ) + payment_system_is = ?pmt_sys(<<"mastercard-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(120)} @@ -9274,22 +8495,14 @@ construct_domain_fixture() -> hg_ct_fixture:construct_payment_method(?pmt(digital_wallet, ?pmt_srv(<<"qiwi-ref">>))), hg_ct_fixture:construct_payment_method(?pmt(payment_terminal, ?pmt_srv(<<"euroset-ref">>))), hg_ct_fixture:construct_payment_method(?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>))), - hg_ct_fixture:construct_payment_method( - ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)) - ), + hg_ct_fixture:construct_payment_method(?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>))), hg_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>), hg_ct_fixture:construct_proxy(?prx(2), <<"Inspector proxy">>), - hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{ - <<"risk_score">> => <<"low">> - }), - hg_ct_fixture:construct_inspector(?insp(2), <<"Skipper">>, ?prx(2), #{ - <<"risk_score">> => <<"high">> - }), - hg_ct_fixture:construct_inspector(?insp(3), <<"Fatalist">>, ?prx(2), #{ - <<"risk_score">> => <<"fatal">> - }), + hg_ct_fixture:construct_inspector(?insp(1), <<"Rejector">>, ?prx(2), #{<<"risk_score">> => <<"low">>}), + hg_ct_fixture:construct_inspector(?insp(2), <<"Skipper">>, ?prx(2), #{<<"risk_score">> => <<"high">>}), + hg_ct_fixture:construct_inspector(?insp(3), <<"Fatalist">>, ?prx(2), #{<<"risk_score">> => <<"fatal">>}), hg_ct_fixture:construct_inspector( ?insp(4), <<"Offliner">>, @@ -9347,10 +8560,7 @@ construct_domain_fixture() -> ), ?delegate( <<"Provider cascading with turnover limit">>, - {condition, - {party, #domain_PartyCondition{ - party_ref = ?PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS - }}}, + {condition, {party, #domain_PartyCondition{party_ref = ?PARTY_CONFIG_REF_WITH_SEVERAL_LIMITS}}}, ?ruleset(6) ), ?delegate(<<"Common">>, {constant, true}, ?ruleset(1)) @@ -9380,9 +8590,7 @@ construct_domain_fixture() -> ?candidate({constant, true}, ?trm(7)) ]} ), - hg_ct_fixture:construct_payment_routing_ruleset( - ?ruleset(3), <<"Prohibitions">>, {candidates, []} - ), + hg_ct_fixture:construct_payment_routing_ruleset(?ruleset(3), <<"Prohibitions">>, {candidates, []}), {payment_institution, #domain_PaymentInstitutionObject{ ref = ?pinst(1), @@ -9596,10 +8804,7 @@ construct_domain_fixture() -> ?pmt(bank_card, ?bank_card(<<"jcb-ref">>)), ?pmt(bank_card, ?bank_card_no_cvv(<<"visa-ref">>)), ?pmt(crypto_currency, ?crypta(<<"bitcoin-ref">>)), - ?pmt( - bank_card, - ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>) - ) + ?pmt(bank_card, ?token_bank_card(<<"visa-ref">>, <<"applepay-ref">>)) ])}, cash_limit = {value, @@ -9614,8 +8819,7 @@ construct_domain_fixture() -> {condition, {payment_tool, {digital_wallet, #domain_DigitalWalletCondition{ - definition = - {payment_service_is, ?pmt_srv(<<"qiwi-ref">>)} + definition = {payment_service_is, ?pmt_srv(<<"qiwi-ref">>)} }}}}, then_ = {value, [ @@ -9638,9 +8842,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = @@ -9664,9 +8866,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"mastercard-ref">> - ) + payment_system_is = ?pmt_sys(<<"mastercard-ref">>) }} }}}}, then_ = @@ -9690,9 +8890,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"jcb-ref">> - ) + payment_system_is = ?pmt_sys(<<"jcb-ref">>) }} }}}}, then_ = @@ -9716,12 +8914,8 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ), - token_service_is = ?token_srv( - <<"applepay-ref">> - ), + payment_system_is = ?pmt_sys(<<"visa-ref">>), + token_service_is = ?token_srv(<<"applepay-ref">>), tokenization_method_is = dpan }} }}}}, @@ -9744,8 +8938,7 @@ construct_domain_fixture() -> {condition, {payment_tool, {crypto_currency, #domain_CryptoCurrencyCondition{ - definition = - {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} + definition = {crypto_currency_is, ?crypta(<<"bitcoin-ref">>)} }}}}, then_ = {value, [ @@ -9772,9 +8965,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -9895,9 +9086,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(5)} @@ -9909,9 +9098,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"mastercard-ref">> - ) + payment_system_is = ?pmt_sys(<<"mastercard-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(120)} @@ -10232,9 +9419,7 @@ construct_domain_fixture() -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(12)} @@ -10371,21 +9556,13 @@ construct_domain_fixture() -> {terminal, ?terminal_obj(?trm(14), ?prv(7))}, hg_ct_fixture:construct_payment_system(?pmt_sys(<<"visa-ref">>), <<"visa payment system">>), - hg_ct_fixture:construct_payment_system( - ?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">> - ), + hg_ct_fixture:construct_payment_system(?pmt_sys(<<"mastercard-ref">>), <<"mastercard payment system">>), hg_ct_fixture:construct_payment_system(?pmt_sys(<<"jcb-ref">>), <<"jcb payment system">>), hg_ct_fixture:construct_mobile_operator(?mob(<<"mts-ref">>), <<"mts mobile operator">>), - hg_ct_fixture:construct_payment_service( - ?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">> - ), - hg_ct_fixture:construct_payment_service( - ?pmt_srv(<<"euroset-ref">>), <<"euroset payment service">> - ), + hg_ct_fixture:construct_payment_service(?pmt_srv(<<"qiwi-ref">>), <<"qiwi payment service">>), + hg_ct_fixture:construct_payment_service(?pmt_srv(<<"euroset-ref">>), <<"euroset payment service">>), hg_ct_fixture:construct_crypto_currency(?crypta(<<"bitcoin-ref">>), <<"bitcoin currency">>), - hg_ct_fixture:construct_tokenized_service( - ?token_srv(<<"applepay-ref">>), <<"applepay tokenized service">> - ) + hg_ct_fixture:construct_tokenized_service(?token_srv(<<"applepay-ref">>), <<"applepay tokenized service">>) ]. construct_term_set_for_refund_eligibility_time(Seconds) -> @@ -10500,9 +9677,7 @@ get_payment_adjustment_fixture(Revision) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(10)} @@ -10652,23 +9827,17 @@ get_cashflow_rounding_fixture(Revision, _C) -> ?cfpost( {provider, settlement}, {merchant, settlement}, - ?share_with_rounding_method( - 1, 200000, operation_amount, round_half_towards_zero - ) + ?share_with_rounding_method(1, 200000, operation_amount, round_half_towards_zero) ), ?cfpost( {system, settlement}, {provider, settlement}, - ?share_with_rounding_method( - 1, 200000, operation_amount, round_half_away_from_zero - ) + ?share_with_rounding_method(1, 200000, operation_amount, round_half_away_from_zero) ), ?cfpost( {system, settlement}, {system, subagent}, - ?share_with_rounding_method( - 1, 200000, operation_amount, round_half_away_from_zero - ) + ?share_with_rounding_method(1, 200000, operation_amount, round_half_away_from_zero) ), ?cfpost( {system, settlement}, @@ -11023,9 +10192,7 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = @@ -11049,9 +10216,7 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = @@ -11097,9 +10262,7 @@ construct_term_set_for_partial_capture_provider_permit(Revision, _C) -> {bank_card, #domain_BankCardCondition{ definition = {payment_system, #domain_PaymentSystemCondition{ - payment_system_is = ?pmt_sys( - <<"visa-ref">> - ) + payment_system_is = ?pmt_sys(<<"visa-ref">>) }} }}}}, then_ = {value, ?hold_lifetime(12)} From ccf6dab0883f75ab4efd88852592816b624186b5 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Sun, 31 Aug 2025 22:39:39 +0300 Subject: [PATCH 06/10] Revert even more format --- apps/hellgate/src/hg_accounting.erl | 4 +- apps/hellgate/src/hg_allocation.erl | 8 +- apps/hellgate/src/hg_cashflow.erl | 4 +- apps/hellgate/src/hg_cashflow_utils.erl | 9 +- apps/hellgate/src/hg_invoice.erl | 8 +- apps/hellgate/src/hg_invoice_handler.erl | 20 +- apps/hellgate/src/hg_invoice_payment.erl | 28 +-- .../src/hg_invoice_payment_chargeback.erl | 4 +- .../src/hg_invoice_payment_refund.erl | 4 +- apps/hellgate/src/hg_limiter.erl | 65 ++---- apps/hellgate/test/hg_allocation_tests.erl | 216 +++++------------- apps/hellgate/test/hg_ct_domain.hrl | 4 +- .../test/hg_invoice_template_tests_SUITE.erl | 12 +- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 17 +- .../test/hg_route_rules_tests_SUITE.erl | 8 +- 15 files changed, 116 insertions(+), 295 deletions(-) diff --git a/apps/hellgate/src/hg_accounting.erl b/apps/hellgate/src/hg_accounting.erl index 25d4c519..189db6ad 100644 --- a/apps/hellgate/src/hg_accounting.erl +++ b/apps/hellgate/src/hg_accounting.erl @@ -115,9 +115,7 @@ collect_account_map(#{ collect_external_account_map(Payment, VS, Revision, Map2). -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 -) -> +collect_merchant_account_map(PartyConfigRef, {ShopConfigRef, #domain_ShopConfig{account = Account}}, Acc) -> Acc#{ merchant => {PartyConfigRef, ShopConfigRef}, {merchant, settlement} => Account#domain_ShopAccount.settlement, diff --git a/apps/hellgate/src/hg_allocation.erl b/apps/hellgate/src/hg_allocation.erl index 3c042739..d505c144 100644 --- a/apps/hellgate/src/hg_allocation.erl +++ b/apps/hellgate/src/hg_allocation.erl @@ -85,14 +85,10 @@ assert_allocatable(_Allocation, _PaymentAllocationServiceTerms, _Party, _Shop, _ {error, allocation_not_allowed}. -spec construct_target(target_map()) -> target(). -construct_target(#{ - party_config_ref := PartyConfigRef, - shop_config_ref := ShopConfigRef -}) -> +construct_target(#{party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef}) -> ?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef). --spec calculate(allocation_prototype(), party_config_ref(), shop_config_ref(), cash()) -> - allocation(). +-spec calculate(allocation_prototype(), party_config_ref(), shop_config_ref(), cash()) -> allocation(). calculate(AllocationPrototype, PartyConfigRef, ShopConfigRef, Cost) -> FeeTarget = construct_target(#{ party_config_ref => PartyConfigRef, diff --git a/apps/hellgate/src/hg_cashflow.erl b/apps/hellgate/src/hg_cashflow.erl index 0c404ce5..986e6dce 100644 --- a/apps/hellgate/src/hg_cashflow.erl +++ b/apps/hellgate/src/hg_cashflow.erl @@ -80,9 +80,7 @@ construct_final_account(AccountType, AccountMap) -> transaction_account = construct_transaction_account(AccountType, AccountMap) }. -construct_transaction_account({merchant, MerchantFlowAccount}, #{ - merchant := {PartyConfigRef, ShopConfigRef} -}) -> +construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyConfigRef, ShopConfigRef}}) -> AccountOwner = #domain_MerchantTransactionAccountOwner{ party_ref = PartyConfigRef, shop_ref = ShopConfigRef diff --git a/apps/hellgate/src/hg_cashflow_utils.erl b/apps/hellgate/src/hg_cashflow_utils.erl index 6f929920..fad186d8 100644 --- a/apps/hellgate/src/hg_cashflow_utils.erl +++ b/apps/hellgate/src/hg_cashflow_utils.erl @@ -72,9 +72,8 @@ collect_allocation_cash_flow( fun(?allocation_trx(_ID, Target, Amount), Acc) -> ?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 - ), + {#domain_ShopConfigRef{id = ShopConfigID} = ShopConfigRef, TargetShop} = + hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision), VS1 = VS0#{ party_config_ref => PartyConfigRef, shop_id => ShopConfigID, @@ -85,9 +84,7 @@ collect_allocation_cash_flow( construct_transaction_cashflow( Amount, AllocationPaymentInstitution, - Context#{ - party => {PartyConfigRef, TargetParty}, shop => {ShopConfigRef, TargetShop} - } + Context#{party => {PartyConfigRef, TargetParty}, shop => {ShopConfigRef, TargetShop}} ) ++ Acc end, [], diff --git a/apps/hellgate/src/hg_invoice.erl b/apps/hellgate/src/hg_invoice.erl index c8c782d5..ad4822d0 100644 --- a/apps/hellgate/src/hg_invoice.erl +++ b/apps/hellgate/src/hg_invoice.erl @@ -169,17 +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_config_ref(St), get_party_config_ref(St), 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_config_ref(St), get_party_config_ref(St), 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; diff --git a/apps/hellgate/src/hg_invoice_handler.erl b/apps/hellgate/src/hg_invoice_handler.erl index 7143d37f..582b5400 100644 --- a/apps/hellgate/src/hg_invoice_handler.erl +++ b/apps/hellgate/src/hg_invoice_handler.erl @@ -36,12 +36,9 @@ handle_function_('Create', {InvoiceParams}, _Opts) -> InvoiceID = InvoiceParams#payproc_InvoiceParams.id, _ = set_invoicing_meta(InvoiceID), PartyConfigRef = InvoiceParams#payproc_InvoiceParams.party_id, - #domain_ShopConfigRef{id = ShopConfigID} = - ShopConfigRef = InvoiceParams#payproc_InvoiceParams.shop_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) - ), + {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), @@ -58,9 +55,7 @@ handle_function_('CreateWithTemplate', {Params}, _Opts) -> InvoiceID = Params#payproc_InvoiceWithTemplateParams.id, _ = set_invoicing_meta(InvoiceID), TplID = Params#payproc_InvoiceWithTemplateParams.template_id, - {_Party, {#domain_ShopConfigRef{id = ShopConfigID}, 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 = #{ @@ -106,9 +101,8 @@ handle_function_('ComputeTerms', {InvoiceID}, _Opts) -> St = get_state(InvoiceID), DomainRevision = hg_domain:head(), {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) - ), + {#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), @@ -302,9 +296,7 @@ make_invoice_params(Params) -> } = hg_invoice_template:get(TplID), DomainRevision = hg_domain:head(), {PartyConfigRef, Party} = hg_party:get_party(PartyConfigRef), - {ShopConfigRef, Shop} = assert_shop_exists( - hg_party:get_shop(ShopConfigRef, PartyConfigRef, DomainRevision) - ), + {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{ diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 7e8ef576..bc48ef3a 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -815,9 +815,7 @@ collect_partial_refund_varset(undefined) -> collect_validation_varset(St, Opts) -> Revision = get_payment_revision(St), - collect_validation_varset( - get_party_config_ref(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(PartyConfigRef, ShopObj, Payment, VS) -> Cost = #domain_Cash{currency = Currency} = get_payment_cost(Payment), @@ -827,9 +825,7 @@ collect_validation_varset(PartyConfigRef, ShopObj, Payment, VS) -> payment_tool => get_payment_tool(Payment) }. -collect_validation_varset_( - PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Currency, VS -) -> +collect_validation_varset_(PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Currency, VS) -> #domain_ShopConfig{ category = Category } = Shop, @@ -2057,9 +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_config_ref(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 = #{ @@ -2489,9 +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_config_ref(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) -> @@ -2542,9 +2534,7 @@ hold_shop_limits(Opts, St) -> 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, PartyConfigRef, ShopConfigRef, Invoice, Payment - ). + ok = hg_limiter:hold_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment). commit_shop_limits(Opts, St) -> Payment = get_payment(St), @@ -2553,9 +2543,7 @@ commit_shop_limits(Opts, St) -> 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, PartyConfigRef, ShopConfigRef, Invoice, Payment - ). + ok = hg_limiter:commit_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment). check_shop_limits(Opts, St) -> Payment = get_payment(St), @@ -2978,9 +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_config_ref(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. %% diff --git a/apps/hellgate/src/hg_invoice_payment_chargeback.erl b/apps/hellgate/src/hg_invoice_payment_chargeback.erl index 927d6c62..e89887e9 100644 --- a/apps/hellgate/src/hg_invoice_payment_chargeback.erl +++ b/apps/hellgate/src/hg_invoice_payment_chargeback.erl @@ -519,9 +519,7 @@ construct_chargeback_plan_id(State, Opts) -> genlib:to_binary(Stage) ]). -collect_validation_varset( - PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, 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 diff --git a/apps/hellgate/src/hg_invoice_payment_refund.erl b/apps/hellgate/src/hg_invoice_payment_refund.erl index c9c5d9af..73acf988 100644 --- a/apps/hellgate/src/hg_invoice_payment_refund.erl +++ b/apps/hellgate/src/hg_invoice_payment_refund.erl @@ -396,9 +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( - PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Payment, VS -) -> +collect_validation_varset(PartyConfigRef, {#domain_ShopConfigRef{id = ShopConfigID}, Shop}, Payment, VS) -> #domain_ShopConfig{ category = Category } = Shop, diff --git a/apps/hellgate/src/hg_limiter.erl b/apps/hellgate/src/hg_limiter.erl index a0af074b..72dd3d87 100644 --- a/apps/hellgate/src/hg_limiter.erl +++ b/apps/hellgate/src/hg_limiter.erl @@ -108,17 +108,13 @@ check_limits(TurnoverLimits, Invoice, Payment, Route, Iter) -> {error, {limit_overflow, IDs, Limits}} end. --spec check_shop_limits( - [turnover_limit()], party_config_ref(), shop_config_ref(), 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, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> Context = gen_limit_shop_context(Invoice, Payment), Limits = get_limit_values( - Context, - TurnoverLimits, - make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) + Context, TurnoverLimits, make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) ), try check_limits_(Limits, Context) @@ -177,21 +173,13 @@ batch_hold_limits(Context, TurnoverLimits, OperationIdSegments) -> _ = hg_limiter_client:hold_batch(LimitRequest, Context), ok. --spec hold_shop_limits( - [turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment() -) -> ok. +-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, PartyConfigRef, ShopConfigRef, Invoice, Payment - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), + ok = legacy_hold_shop_limits(Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment), ok = batch_hold_limits( - Context, - BatchTurnoverLimits, - make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) + Context, BatchTurnoverLimits, make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment) ). legacy_hold_shop_limits(Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment) -> @@ -242,9 +230,7 @@ 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_config_ref(), shop_config_ref(), invoice(), payment() -) -> ok. +-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), @@ -252,15 +238,11 @@ commit_shop_limits(TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payme ok = legacy_commit_shop_limits( Clock, Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment ), - OperationIdSegments = make_shop_operation_segments( - 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, PartyConfigRef, ShopConfigRef, 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). @@ -312,27 +294,23 @@ legacy_rollback_payment_limits(Context, TurnoverLimits, Invoice, Payment, Route, rollback(LimitChanges, get_latest_clock(), Context, Flags). -spec rollback_shop_limits( - [turnover_limit()], party_config_ref(), shop_config_ref(), invoice(), payment(), [ - handling_flag() - ] -) -> - ok. + [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 - ), + {LegacyTurnoverLimits, BatchTurnoverLimits} = split_turnover_limits_by_available_limiter_api(TurnoverLimits), ok = legacy_rollback_shop_limits( Context, LegacyTurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment, Flags ), - OperationIdSegments = make_shop_operation_segments( - PartyConfigRef, ShopConfigRef, Invoice, Payment - ), + OperationIdSegments = make_shop_operation_segments(PartyConfigRef, ShopConfigRef, Invoice, Payment), ok = batch_rollback_limits(Context, BatchTurnoverLimits, OperationIdSegments). -legacy_rollback_shop_limits( - Context, TurnoverLimits, PartyConfigRef, ShopConfigRef, Invoice, Payment, Flags -) -> +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). @@ -541,10 +519,7 @@ mk_limit_log_attributes(#limiter_LimitContext{ payment_processing = #context_payproc_Context{op = Op, invoice = CtxInvoice} }) -> #context_payproc_Invoice{ - invoice = #domain_Invoice{ - party_ref = PartyConfigRef, - shop_ref = ShopConfigRef - }, + invoice = #domain_Invoice{party_ref = PartyConfigRef, shop_ref = ShopConfigRef}, payment = #context_payproc_InvoicePayment{ payment = Payment, refund = Refund, diff --git a/apps/hellgate/test/hg_allocation_tests.erl b/apps/hellgate/test/hg_allocation_tests.erl index a7976d48..a08a901f 100644 --- a/apps/hellgate/test/hg_allocation_tests.erl +++ b/apps/hellgate/test/hg_allocation_tests.erl @@ -15,16 +15,12 @@ generic_prototype() -> Cart = ?invoice_cart([?invoice_line(<<"STRING">>, 1, ?cash(30, <<"RUB">>))]), ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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">>)) @@ -32,9 +28,7 @@ generic_prototype() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) @@ -57,38 +51,28 @@ calculate_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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) @@ -96,9 +80,7 @@ calculate_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -110,23 +92,17 @@ 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( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) ) @@ -141,25 +117,19 @@ calculate_without_generating_agg_trx_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"SHOP3">>)), ?cash(30, <<"RUB">>), ?allocation_trx_details(Cart) ) @@ -172,9 +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( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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) @@ -182,9 +150,7 @@ calculate_amount_exceeded_error_1_test() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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) @@ -192,9 +158,7 @@ calculate_amount_exceeded_error_1_test() -> ?allocation_trx_details(Cart) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) @@ -231,9 +195,7 @@ subtract_one_transaction_1_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"SHOP1">>)), ?allocation_trx_prototype_body_amount(?cash(30, <<"RUB">>)) ) ]), @@ -254,30 +216,22 @@ subtract_one_transaction_1_test() -> [ ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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) @@ -285,9 +239,7 @@ subtract_one_transaction_1_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -300,9 +252,7 @@ subtract_one_transaction_2_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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">>)) @@ -327,23 +277,17 @@ subtract_one_transaction_2_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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) @@ -351,9 +295,7 @@ subtract_one_transaction_2_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(5, <<"RUB">>) ) ], @@ -366,9 +308,7 @@ subtract_one_transaction_3_test() -> AllocationPrototype = generic_prototype(), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) @@ -393,32 +333,24 @@ subtract_one_transaction_3_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(10, <<"RUB">>) ) ], @@ -434,16 +366,12 @@ subtract_partial_transaction_test() -> ]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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">>)) @@ -451,9 +379,7 @@ subtract_partial_transaction_test() -> ?allocation_trx_details(Cart0) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) @@ -463,9 +389,7 @@ subtract_partial_transaction_test() -> ]), RefundAllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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">>))]) @@ -489,38 +413,28 @@ subtract_partial_transaction_test() -> [ ?allocation_trx( <<"1">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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) @@ -528,9 +442,7 @@ subtract_partial_transaction_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>) - ), + ?allocation_trx_target_shop(?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"SHOP0">>)), ?cash(15, <<"RUB">>) ) ], @@ -546,16 +458,12 @@ consecutive_subtract_of_partial_transaction_test() -> ]), AllocationPrototype = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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">>)) @@ -563,9 +471,7 @@ consecutive_subtract_of_partial_transaction_test() -> ?allocation_trx_details(Cart0) ), ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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) @@ -575,9 +481,7 @@ consecutive_subtract_of_partial_transaction_test() -> ]), RefundAllocationPrototype0 = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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">>))]) @@ -586,9 +490,7 @@ consecutive_subtract_of_partial_transaction_test() -> ]), RefundAllocationPrototype1 = ?allocation_prototype([ ?allocation_trx_prototype( - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY1">>), ?SHOP_CONFIG_REF(<<"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">>))]) @@ -622,30 +524,22 @@ consecutive_subtract_of_partial_transaction_test() -> [ ?allocation_trx( <<"2">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY2">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY3">>), ?SHOP_CONFIG_REF(<<"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( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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) @@ -653,9 +547,7 @@ consecutive_subtract_of_partial_transaction_test() -> ), ?allocation_trx( <<"4">>, - ?allocation_trx_target_shop( - ?PARTY_CONFIG_REF(<<"PARTY0">>), ?SHOP_CONFIG_REF(<<"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 c911c87c..383f7742 100644 --- a/apps/hellgate/test/hg_ct_domain.hrl +++ b/apps/hellgate/test/hg_ct_domain.hrl @@ -46,9 +46,7 @@ -define(cashrng(Lower, Upper), #domain_CashRange{lower = Lower, upper = Upper}). -define(prvacc(Stl), #domain_ProviderAccount{settlement = Stl}). --define(partycond(Ref, Def), - {condition, {party, #domain_PartyCondition{party_ref = Ref, 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_invoice_template_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl index 1791db6d..c0997207 100644 --- a/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_template_tests_SUITE.erl @@ -269,9 +269,9 @@ update_invalid_party_status(C) -> Client = cfg(client, 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">>)) - }), + 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(PartyConfigRef), {exception, #payproc_InvalidPartyStatus{ status = {suspension, {suspended, _}} @@ -289,9 +289,9 @@ update_invalid_shop_status(C) -> Client = cfg(client, 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">>)) - }), + 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(ShopConfigRef), {exception, #payproc_InvalidShopStatus{ status = {suspension, {suspended, _}} diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 6caaf1a6..e0258052 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1354,9 +1354,7 @@ payment_limit_overflow(C) -> ok = payproc_errors:match( 'PaymentFailure', Failure, - fun({no_route_found, {rejected, {limit_overflow, _}}}) -> - ok - end + fun({no_route_found, {rejected, {limit_overflow, _}}}) -> ok end ). -spec limit_hold_currency_error(config()) -> test_return(). @@ -6772,9 +6770,7 @@ payment_cascade_limit_overflow(C) -> ?assertNotEqual(Route1, Route2), ?assertNot(lists:member(Route1, Candidates2)), %% No route found and so we pass original failure from previous attempt - ok = payproc_errors:match('PaymentFailure', Failure2, fun({authorization_failed, {unknown, _}}) -> - ok - end), + ok = payproc_errors:match('PaymentFailure', Failure2, fun({authorization_failed, {unknown, _}}) -> ok end), %% Assert payment status IS failed ?invoice_state(?invoice_w_status(_), [?payment_state(FinalPayment)]) = hg_client_invoicing:get(InvoiceID, Client), @@ -7996,7 +7992,10 @@ await_sessions_restarts( ) ) = next_change(InvoiceID, Client), - ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost, Cart, _), ?session_started())) = + ?payment_ev( + PaymentID, + ?session_ev(?captured(Reason, Cost, Cart, _), ?session_started()) + ) = next_change(InvoiceID, Client), await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts - 1); await_sessions_restarts(PaymentID, Target, InvoiceID, Client, Restarts) when Restarts > 0 -> @@ -8074,7 +8073,9 @@ execute_payment_adjustment(InvoiceID, PaymentID, Params, Client) -> [ ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_created(Adjustment))), ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_processed()))), - ?payment_ev(PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_)))) + ?payment_ev( + PaymentID, ?adjustment_ev(AdjustmentID, ?adjustment_status_changed(?adjustment_captured(_))) + ) ] = next_changes(InvoiceID, 3, Client), AdjustmentID. diff --git a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl index abd273a5..7ee8eb55 100644 --- a/apps/hellgate/test/hg_route_rules_tests_SUITE.erl +++ b/apps/hellgate/test/hg_route_rules_tests_SUITE.erl @@ -35,9 +35,7 @@ -define(PROVIDER_MIN_ALLOWED, ?cash(1000, <<"RUB">>)). -define(PROVIDER_MIN_ALLOWED_W_EXTRA_CASH(ExtraCash), ?cash(1000 + ExtraCash, <<"RUB">>)). -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(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))). @@ -226,9 +224,7 @@ mock_party_management(SupPid) -> { ?ruleset(2), ?base_routing_rule_domain_revision, - #payproc_Varset{ - party_ref = ?party_config_ref_for_ruleset_w_no_delegates - } + #payproc_Varset{party_ref = ?party_config_ref_for_ruleset_w_no_delegates} } ) -> {ok, #domain_RoutingRuleset{ From 15f3bf9200285e90d581403b01b96ef919132ec5 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Mon, 1 Sep 2025 01:04:58 +0300 Subject: [PATCH 07/10] Some more --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 20 +++++++------------ apps/routing/src/hg_route.erl | 4 ++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index e0258052..24b53641 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -2690,7 +2690,7 @@ payment_adjustment_w_amount_success(C) -> OriginalAmount, ?merchant_to_system_share_1, ?system_to_provider_share_initial, ZeroShare ), {NewOpDiffMrc, NewOpDiffSys, NewOpDiffPrv} = compute_operation_amount_diffs( - NewAmount, ?merchant_to_system_share_1, system_to_provider_share_actual, ?system_to_external_fixed + NewAmount, ?merchant_to_system_share_1, ?system_to_provider_share_actual, ?system_to_external_fixed ), ?assertEqual( NewOpDiffMrc - OpDiffMrc, @@ -3437,21 +3437,15 @@ external_account_posting(C) -> RootUrl = cfg(root_url, C), PartyClient = cfg(party_client, C), InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)), - 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) - ), + 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 - ), + ?invoice_created(?invoice_w_status(?invoice_unpaid())) = next_change(InvoiceID, InvoicingClient), ?payment_state( ?payment(PaymentID) - ) = hg_client_invoicing:start_payment( - InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), InvoicingClient - ), + ) = hg_client_invoicing:start_payment(InvoiceID, make_payment_params(?pmt_sys(<<"visa-ref">>)), InvoicingClient), ?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending()))) = next_change(InvoiceID, InvoicingClient), {CF, Route} = await_payment_cash_flow(InvoiceID, PaymentID, InvoicingClient), 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, From e89fc648704de89632c269d35df7fb0b0773ba93 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Tue, 2 Sep 2025 01:23:39 +0300 Subject: [PATCH 08/10] Some debug info --- apps/hellgate/test/hg_limiter_helper.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/hellgate/test/hg_limiter_helper.erl b/apps/hellgate/test/hg_limiter_helper.erl index b0b8b83c..c90c704e 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}) -> From c39e71d49ee728f6807939dd6f147f5f70f35202 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Tue, 2 Sep 2025 10:25:34 +0300 Subject: [PATCH 09/10] Bump progressor --- rebar.config | 2 +- rebar.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rebar.config b/rebar.config index d42ed343..07f69d4f 100644 --- a/rebar.config +++ b/rebar.config @@ -42,7 +42,7 @@ {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"}, diff --git a/rebar.lock b/rebar.lock index ff9f28ef..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">>, @@ -35,11 +35,11 @@ 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", From f7f6b3aa3e772a6fc2d94f5e5ee1e1286acb7cc6 Mon Sep 17 00:00:00 2001 From: Rustem Shaydullin Date: Tue, 2 Sep 2025 16:31:12 +0300 Subject: [PATCH 10/10] Fix limit tests --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 18 ++++++++++++------ apps/hellgate/test/hg_limiter_helper.erl | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 24b53641..22165ebd 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -515,6 +515,7 @@ init_per_suite(C) -> ]), BaseLimitsRevision = hg_limiter_helper:init_per_suite(C), + _ = logger:error("BaseLimitsRevision: ~p", [BaseLimitsRevision]), RootUrl = maps:get(hellgate_root_url, Ret), @@ -534,7 +535,7 @@ init_per_suite(C) -> _ = 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()), + _BaseRevision = hg_domain:insert(construct_domain_fixture(BaseLimitsRevision)), ok = hg_context:save(hg_context:create()), ShopConfigRef = hg_ct_helper:create_party_and_shop( @@ -1348,6 +1349,11 @@ payment_limit_overflow(C) -> ) = create_payment(PartyConfigRef, ShopConfigRef, PaymentAmount, 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 ), @@ -8158,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 = @@ -9444,7 +9450,7 @@ construct_domain_fixture() -> #domain_TurnoverLimit{ id = ?LIMIT_ID, upper_boundary = ?LIMIT_UPPER_BOUNDARY, - domain_revision = hg_domain:head() + domain_revision = BaseLimitsRevision } ]} } @@ -9497,7 +9503,7 @@ construct_domain_fixture() -> #domain_TurnoverLimit{ id = ?LIMIT_ID2, upper_boundary = ?LIMIT_UPPER_BOUNDARY, - domain_revision = hg_domain:head() + domain_revision = BaseLimitsRevision } ]} } @@ -9542,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 c90c704e..d6953382 100644 --- a/apps/hellgate/test/hg_limiter_helper.erl +++ b/apps/hellgate/test/hg_limiter_helper.erl @@ -48,7 +48,7 @@ get_amount(#limiter_Limit{amount = Amount}) -> -spec assert_payment_limit_amount(_, _, _, _, _) -> _. assert_payment_limit_amount(LimitID, Version, AssertAmount, Payment, Invoice) -> -Result = get_payment_limit_amount(LimitID, Version, Payment, Invoice), + Result = get_payment_limit_amount(LimitID, Version, Payment, Invoice), Limit = maybe_uninitialized_limit(Result), #limiter_Limit{amount = CurrentAmount} = Limit, ?assertEqual(AssertAmount, CurrentAmount, {LimitID, Result}).