From f442a232e5851e78483dfaf9b2e9a1ffdc7f2e34 Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 03:33:23 +0300 Subject: [PATCH 01/26] add clock update event --- apps/hellgate/include/payment_events.hrl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/hellgate/include/payment_events.hrl b/apps/hellgate/include/payment_events.hrl index 2d696ea75..8adc8cb1b 100644 --- a/apps/hellgate/include/payment_events.hrl +++ b/apps/hellgate/include/payment_events.hrl @@ -33,6 +33,10 @@ {invoice_payment_cash_flow_changed, #payproc_InvoicePaymentCashFlowChanged{cash_flow = CashFlow}} ). +-define(payment_clock_update(Clock), + {invoice_payment_clock_update, #payproc_InvoicePaymentClockUpdate{clock = Clock}} +). + -define(payment_status_changed(Status), {invoice_payment_status_changed, #payproc_InvoicePaymentStatusChanged{status = Status}} ). From 60fa8c12c3d6c80b28035b0719f4338c5df804da Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 03:33:59 +0300 Subject: [PATCH 02/26] add clock to state --- apps/hellgate/src/hg_invoice_payment.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 8aa68dc2b..e9f7ff577 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -148,7 +148,8 @@ capture_params :: undefined | capture_params(), failure :: undefined | failure(), timings :: undefined | hg_timings:t(), - latest_change_at :: undefined | hg_datetime:timestamp() + latest_change_at :: undefined | hg_datetime:timestamp(), + clock :: hg_accounting_new:clock() }). -record(refund_st, { From 6475e7f11ac5b1c549bbe23b3242ca2dc06cf22f Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 04:16:57 +0300 Subject: [PATCH 03/26] update payment tests --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 67 ++++++++++++++----- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 8a8faa228..4b77ef282 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -996,7 +996,10 @@ processing_deadline_reached_test(C) -> PaymentID = start_payment(InvoiceID, PaymentParams, Client), PaymentID = await_sessions_restarts(PaymentID, ?processed(), InvoiceID, Client, 0), [?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure}))] = next_event(InvoiceID, Client), - [?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure})))] = next_event(InvoiceID, Client), + [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), + ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) + ] = next_event(InvoiceID, Client), ok = payproc_errors:match( 'PaymentFailure', Failure, @@ -1242,7 +1245,8 @@ payment_w_crypto_currency_success(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CF)) + ?payment_ev(PaymentID, ?cash_flow_changed(CF)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), ?cash(PayCash, <<"RUB">>) = get_cashflow_volume({provider, settlement}, {merchant, settlement}, CF), ?cash(40, <<"RUB">>) = get_cashflow_volume({system, settlement}, {provider, settlement}, CF), @@ -1266,7 +1270,8 @@ payment_bank_card_category_condition(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CF)) + ?payment_ev(PaymentID, ?cash_flow_changed(CF)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), ?cash(200, <<"RUB">>) = get_cashflow_volume({merchant, settlement}, {system, settlement}, CF). @@ -1283,7 +1288,8 @@ payment_w_mobile_commerce(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), [ @@ -1306,7 +1312,8 @@ payment_suspend_timeout_failure(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), [ @@ -1314,6 +1321,7 @@ payment_suspend_timeout_failure(C) -> ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_event(InvoiceID, Client). @@ -1540,7 +1548,8 @@ payment_risk_score_check(C) -> % low risk score... % ...covered with high risk coverage terminal ?payment_ev(PaymentID1, ?route_changed(?route(?prv(1), ?trm(1)))), - ?payment_ev(PaymentID1, ?cash_flow_changed(_)) + ?payment_ev(PaymentID1, ?cash_flow_changed(_)), + ?payment_ev(PaymentID1, ?payment_clock_update(_)) ] = next_event(InvoiceID1, Client), [ ?payment_ev(PaymentID1, ?session_ev(?processed(), ?session_started())) @@ -1558,7 +1567,8 @@ payment_risk_score_check(C) -> % high risk score... % ...covered with the same terminal ?payment_ev(PaymentID2, ?route_changed(?route(?prv(1), ?trm(1)))), - ?payment_ev(PaymentID2, ?cash_flow_changed(_)) + ?payment_ev(PaymentID2, ?cash_flow_changed(_)), + ?payment_ev(PaymentID2, ?payment_clock_update(_)) ] = next_event(InvoiceID2, Client), [ ?payment_ev(PaymentID2, ?session_ev(?processed(), ?session_started())) @@ -1650,7 +1660,8 @@ payment_adjustment_success(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CF1)) + ?payment_ev(PaymentID, ?cash_flow_changed(CF1)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) @@ -2184,7 +2195,8 @@ external_account_posting(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CF)) + ?payment_ev(PaymentID, ?cash_flow_changed(CF)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, InvoicingClient), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) @@ -2217,7 +2229,12 @@ terminal_cashflow_overrides_provider(C) -> _ = next_event(InvoiceID, InvoicingClient), _ = hg_client_invoicing:start_payment(InvoiceID, make_payment_params(), InvoicingClient), _ = next_event(InvoiceID, InvoicingClient), - [_, _, ?payment_ev(PaymentID, ?cash_flow_changed(CF))] = next_event(InvoiceID, InvoicingClient), + [ + _, + _, + ?payment_ev(PaymentID, ?cash_flow_changed(CF)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) + ] = next_event(InvoiceID, InvoicingClient), _ = next_event(InvoiceID, InvoicingClient), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, InvoicingClient), PaymentID = await_payment_capture(InvoiceID, PaymentID, InvoicingClient), @@ -3458,6 +3475,7 @@ start_chargeback_partial_capture(C, Cost, Partial, CBParams) -> ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash), ?session_started())) ] = next_event(InvoiceID, Client), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, 0, Cash), @@ -4199,6 +4217,7 @@ payment_hold_partial_capturing(C) -> ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash), ?session_started())) ] = next_event(InvoiceID, Client), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, 0, Cash). @@ -4218,6 +4237,7 @@ payment_hold_partial_capturing_with_cart(C) -> ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash, Cart), ?session_started())) ] = next_event(InvoiceID, Client), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, 0, Cash, Cart). @@ -4237,6 +4257,7 @@ payment_hold_partial_capturing_with_cart_missing_cash(C) -> ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash, Cart), ?session_started())) ] = next_event(InvoiceID, Client), PaymentID = await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, 0, Cash, Cart). @@ -4309,7 +4330,8 @@ rounding_cashflow_volume(C) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CF)) + ?payment_ev(PaymentID, ?cash_flow_changed(CF)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client), @@ -4632,6 +4654,7 @@ payment_with_offsite_preauth_failed(C) -> ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) ] = next_event(InvoiceID, 8000, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_event(InvoiceID, 8000, Client), ok = payproc_errors:match('PaymentFailure', Failure, fun({authorization_failed, _}) -> ok end), @@ -4688,7 +4711,8 @@ repair_skip_inspector_succeeded(C) -> % we send low risk score in create repair... ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(?route(?prv(2), ?trm(7)))), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) @@ -4718,6 +4742,7 @@ repair_fail_session_succeeded(C) -> ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_event(InvoiceID, Client). @@ -4764,7 +4789,8 @@ repair_complex_succeeded_first(C) -> % we send low risk score in create repair... ?payment_ev(PaymentID, ?risk_score_changed(low)), ?payment_ev(PaymentID, ?route_changed(?route(?prv(2), ?trm(7)))), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), [ ?payment_ev(PaymentID, ?session_ev(?processed(), ?session_started())) @@ -4794,6 +4820,7 @@ repair_complex_succeeded_second(C) -> ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure}))) ] = next_event(InvoiceID, Client). @@ -5222,7 +5249,8 @@ start_payment(InvoiceID, PaymentParams, Client) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID. @@ -5244,7 +5272,8 @@ await_payment_cash_flow(InvoiceID, PaymentID, Client) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(CashFlow)) + ?payment_ev(PaymentID, ?cash_flow_changed(CashFlow)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), CashFlow. @@ -5308,6 +5337,7 @@ await_payment_partial_capture(InvoiceID, PaymentID, Reason, Cash, Client, Restar ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash), ?session_started())) ] = next_event(InvoiceID, Client), await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, Restarts, Cash). @@ -5363,6 +5393,7 @@ await_payment_process_failure(InvoiceID, PaymentID, Client, Restarts, Target) -> ?payment_ev(PaymentID, ?payment_rollback_started(Failure)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?failed(Failure))) ] = next_event(InvoiceID, Client), {failed, PaymentID, Failure}. @@ -5505,7 +5536,8 @@ make_payment_and_get_revision(InvoiceID, Client) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()), PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client, 0), @@ -5580,7 +5612,8 @@ payment_risk_score_check(Cat, C) -> % default low risk score... ?payment_ev(PaymentID1, ?risk_score_changed(low)), ?payment_ev(PaymentID1, ?route_changed(?route(?prv(2), ?trm(7)))), - ?payment_ev(PaymentID1, ?cash_flow_changed(_)) + ?payment_ev(PaymentID1, ?cash_flow_changed(_)), + ?payment_ev(PaymentID1, ?payment_clock_update(_)) ] = next_event(InvoiceID1, Client), [ ?payment_ev(PaymentID1, ?session_ev(?processed(), ?session_started())) From 7fe1bc861e8947be95ce95e6ecd1b67ee0473f0a Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 04:17:17 +0300 Subject: [PATCH 04/26] add shumaich clock handling --- apps/hellgate/src/hg_invoice_payment.erl | 71 +++++++++++++++++++----- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index e9f7ff577..da497ed77 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1887,11 +1887,12 @@ process_cash_flow_building(Route, VS, Payment, Revision, Opts, Events0, Action) Timestamp = get_payment_created_at(Payment), FinalCashflow = calculate_cashflow(Route, Payment, Timestamp, VS, Revision, Opts), Invoice = get_invoice(Opts), - _Clock = hg_accounting:hold( + Clock = hg_accounting_new:hold( construct_payment_plan_id(Invoice, Payment), - {1, FinalCashflow} + {1, FinalCashflow}, + Timestamp ), - Events1 = Events0 ++ [?route_changed(Route), ?cash_flow_changed(FinalCashflow)], + Events1 = Events0 ++ [?route_changed(Route), ?cash_flow_changed(FinalCashflow), ?payment_clock_update(Clock)], {next, {Events1, hg_machine_action:set_timeout(0, Action)}}. %% @@ -1970,7 +1971,7 @@ process_adjustment_cashflow(ID, _Action, St) -> {done, {Events, hg_machine_action:new()}}. process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, capture_params = CaptureParams}) -> - Opts = get_opts(St), + #{timestamp := Timestamp} = Opts = get_opts(St), #payproc_InvoicePaymentCaptureParams{ reason = Reason, cash = Cost, @@ -1979,15 +1980,17 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap Invoice = get_invoice(Opts), Payment = get_payment(St), Payment2 = Payment#domain_InvoicePayment{cost = Cost}, - _Clock = hg_accounting:plan( + NewClock = hg_accounting_new:plan( construct_payment_plan_id(Invoice, Payment2), [ {2, hg_cashflow:revert(get_cashflow(St))}, {3, FinalCashflow} - ] + ], + Timestamp, + St#st.clock ), Events = start_session(?captured(Reason, Cost, Cart)), - {next, {Events, hg_machine_action:set_timeout(0, Action)}}. + {next, {[?payment_clock_update(NewClock) | Events], hg_machine_action:set_timeout(0, Action)}}. %% @@ -2127,8 +2130,8 @@ process_result({payment, processing_accounter}, Action, St) -> {done, {[?payment_status_changed(Target)], NewAction}}; process_result({payment, processing_failure}, Action, St = #st{failure = Failure}) -> NewAction = hg_machine_action:set_timeout(0, Action), - _Clocks = rollback_payment_cashflow(St), - {done, {[?payment_status_changed(?failed(Failure))], NewAction}}; + Clock = rollback_payment_cashflow(St), + {done, {[?payment_clock_update(Clock), ?payment_status_changed(?failed(Failure))], NewAction}}; process_result({payment, finalizing_accounter}, Action, St) -> Target = get_target(St), _Clocks = @@ -2488,11 +2491,17 @@ try_request_interaction(undefined) -> try_request_interaction(UserInteraction) -> [?interaction_requested(UserInteraction)]. -commit_payment_cashflow(St) -> - hg_accounting:commit(construct_payment_plan_id(St), get_cashflow_plan(St)). +% commit_payment_cashflow(St) -> +% hg_accounting:commit(construct_payment_plan_id(St), get_cashflow_plan(St)). +commit_payment_cashflow(St = #st{clock = Clock}) -> + #{timestamp := Timestamp} = get_opts(St), + hg_accounting_new:commit(construct_payment_plan_id(St), get_cashflow_plan(St), Timestamp, Clock). -rollback_payment_cashflow(St) -> - hg_accounting:rollback(construct_payment_plan_id(St), get_cashflow_plan(St)). +% rollback_payment_cashflow(St) -> +% hg_accounting:rollback(construct_payment_plan_id(St), get_cashflow_plan(St)). +rollback_payment_cashflow(St = #st{clock = Clock}) -> + #{timestamp := Timestamp} = get_opts(St), + hg_accounting_new:rollback(construct_payment_plan_id(St), get_cashflow_plan(St), Timestamp, Clock). get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when PartialCashFlow =/= undefined -> [ @@ -2832,8 +2841,8 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S case Activity of {payment, cash_flow_building} -> St#st{ - cash_flow = Cashflow, - activity = {payment, processing_session} + cash_flow = Cashflow + % activity = {payment, processing_session} }; {payment, processing_capture} -> St#st{ @@ -2843,6 +2852,38 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S _ -> St end; +merge_change(Change = ?payment_clock_update(Clock), #st{activity = Activity} = St, Opts) -> + % erlang:display(Activity), + _ = validate_transition( + [ + {payment, S} + || S <- [ + cash_flow_building, + % processing_capture, + processing_session, + processing_failure, + finalizing_accounter, + updating_accounter + ] + ], + Change, + St, + Opts + ), + case Activity of + {payment, cash_flow_building} -> + St#st{ + clock = Clock, + activity = {payment, processing_session} + }; + {payment, processing_capture} -> + St#st{ + clock = Clock, + activity = {payment, updating_accounter} + }; + _ -> + St + end; merge_change(Change = ?rec_token_acquired(Token), #st{} = St, Opts) -> _ = validate_transition([{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts), St#st{recurrent_token = Token}; From 7606445410024fb585c8568a9f4faf1f72c6398e Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 04:39:46 +0300 Subject: [PATCH 05/26] update invoice adjustment tests --- apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl index 3f3b9fb7b..cc688e03b 100644 --- a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl @@ -869,7 +869,8 @@ start_payment(InvoiceID, PaymentParams, Client) -> [ ?payment_ev(PaymentID, ?risk_score_changed(_)), ?payment_ev(PaymentID, ?route_changed(_)), - ?payment_ev(PaymentID, ?cash_flow_changed(_)) + ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)) ] = next_event(InvoiceID, Client), PaymentID. From 93f7e06b37bd261704aa0a30d4fe6af5b4faddef Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 04:55:43 +0300 Subject: [PATCH 06/26] fix invoice adjustment tests --- apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl index cc688e03b..f97a3a172 100644 --- a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl @@ -931,6 +931,7 @@ await_payment_partial_capture(InvoiceID, PaymentID, Reason, Cash, Client, Restar ?payment_ev(PaymentID, ?cash_flow_changed(_)) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cash), ?session_started())) ] = next_event(InvoiceID, Client), await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, Restarts, Cash). From 2ddb2e0f2f1ac29e72a9f0851ae72df9dacf551e Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 11:27:55 +0300 Subject: [PATCH 07/26] fix format --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 4b77ef282..23bfe76a4 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -4832,10 +4832,10 @@ consistent_account_balances(C) -> Party = hg_client_party:get(PartyClient), Shops = maps:values(Party#domain_Party.shops), _ = [ - { + { consistent_account_balance(AccountID, Shop), consistent_account_balance_new(AccountID, Shop) - } + } || #domain_Shop{account = ShopAccount} = Shop <- Shops, #domain_ShopAccount{settlement = AccountID1, guarantee = AccountID2} <- [ShopAccount], AccountID <- [AccountID1, AccountID2] From c9b2b977173ee1820877587f608623b0f19eef1a Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 12:05:27 +0300 Subject: [PATCH 08/26] type fix --- apps/hellgate/src/hg_invoice_payment.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index da497ed77..711b825ba 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -149,7 +149,7 @@ failure :: undefined | failure(), timings :: undefined | hg_timings:t(), latest_change_at :: undefined | hg_datetime:timestamp(), - clock :: hg_accounting_new:clock() + clock :: undefined | hg_accounting_new:clock() }). -record(refund_st, { From 8e97457f240bd0db440aa74e7b5ae18ba2b46948 Mon Sep 17 00:00:00 2001 From: Roman Pushkov Date: Mon, 30 Nov 2020 19:09:44 +0300 Subject: [PATCH 09/26] export clock type --- apps/hellgate/src/hg_accounting_new.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/hellgate/src/hg_accounting_new.erl b/apps/hellgate/src/hg_accounting_new.erl index edf16af98..a3809aa4d 100644 --- a/apps/hellgate/src/hg_accounting_new.erl +++ b/apps/hellgate/src/hg_accounting_new.erl @@ -54,6 +54,7 @@ -type revision() :: hg_domain:revision(). -export_type([batch/0]). +-export_type([clock/0]). -type account() :: #{ account_id => account_id(), From 16f5d00c8d1beb091178cae1d646b06c963f6c98 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Tue, 6 Jul 2021 18:10:27 +0300 Subject: [PATCH 10/26] fix shumpune-shumaich proxy --- apps/hellgate/src/hg_invoice_payment.erl | 8 -------- apps/hellgate/test/hg_ct_helper.erl | 2 +- docker-compose.sh | 16 +++++++--------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index f10ed230f..583be8ad9 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1769,7 +1769,6 @@ process_timeout({payment, Step}, Action, St) when Step =:= processing_session orelse Step =:= finalizing_session -> - _ = erlang:display({processing_session, St}), process_session(Action, St); process_timeout({payment, Step}, Action, St) when Step =:= processing_failure orelse @@ -1881,17 +1880,14 @@ process_cash_flow_building(Action, St) -> TurnoverLimits = get_turnover_limits(ProviderTerms), ok = hg_limiter:hold_payment_limits(TurnoverLimits, Invoice, Payment), FinalCashflow = calculate_cashflow(Route, Payment, MerchantTerms, ProviderTerms, VS1, Revision, Opts), - _ = erlang:display({process_cash_flow_building, St}), Clock = hg_accounting_new:hold( construct_payment_plan_id(Invoice, Payment), {1, FinalCashflow}, Timestamp ), - _ = erlang:display({clock, Clock}), Events = [?cash_flow_changed(FinalCashflow), ?payment_clock_update(Clock)], case hg_limiter:check_limits(TurnoverLimits, Invoice, Payment) of {ok, _} -> - _ = erlang:display({limits_checked, Events}), {next, {Events, hg_machine_action:set_timeout(0, Action)}}; {error, {limit_overflow, _}} -> Failure = failure( @@ -2877,21 +2873,18 @@ merge_change(Change = ?risk_score_changed(RiskScore), #st{} = St, Opts) -> activity = {payment, routing} }; merge_change(Change = ?route_changed(Route), St, Opts) -> - erlang:display({merge_change, route_changed}), _ = validate_transition({payment, routing}, Change, St, Opts), St#st{ route = Route, activity = {payment, cash_flow_building} }; merge_change(Change = ?payment_capture_started(Params), #st{} = St, Opts) -> - erlang:display({merge_change, payment_capture_started}), _ = validate_transition([{payment, S} || S <- [flow_waiting]], Change, St, Opts), St#st{ capture_params = Params, activity = {payment, processing_capture} }; merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = St0, Opts) -> - erlang:display({merge_change, cash_flow_changed, Activity}), _ = validate_transition( [ {payment, S} @@ -2920,7 +2913,6 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S St end; merge_change(Change = ?payment_clock_update(Clock), #st{activity = Activity} = St, Opts) -> - erlang:display({merge_change, payment_clock_update, Activity}), _ = validate_transition( [ {payment, S} diff --git a/apps/hellgate/test/hg_ct_helper.erl b/apps/hellgate/test/hg_ct_helper.erl index ee0578ccc..0f87fb534 100644 --- a/apps/hellgate/test/hg_ct_helper.erl +++ b/apps/hellgate/test/hg_ct_helper.erl @@ -134,7 +134,7 @@ start_app(hellgate = AppName) -> }}, {services, #{ accounter => <<"http://shumway:8022/shumpune">>, - accounter_new => <<"http://shumway:8022/shumaich">>, + accounter_new => <<"http://shumaich:8022/shumaich">>, automaton => <<"http://machinegun:8022/v1/automaton">>, customer_management => #{ url => <<"http://hellgate:8022/v1/processing/customer_management">>, diff --git a/docker-compose.sh b/docker-compose.sh index e1df35c97..f90b112d1 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -59,7 +59,7 @@ services: condition: service_healthy shumway: - image: dr2.rbkmoney.com/rbkmoney/shumway:658c9aec229b5a70d745a49cb938bb1a132b5ca2 + image: dr2.rbkmoney.com/rbkmoney/shumway:2f7d381d36ec69cfc90c77996f7e82b79d89e80b hostname: shumway container_name: shumway ports: @@ -70,16 +70,17 @@ services: "spring.datasource.username": "postgres", "spring.datasource.password": "postgres", "management.metrics.export.statsd.enabled": "false", - "service.shumaich.url": "http://shumaich:8033/shumaich" + "service.shumaich.url": "http://shumaich:8022/shumaich" }' depends_on: - postgres - shumaich healthcheck: - test: "curl http://localhost:8022/" - interval: 5s - timeout: 1s - retries: 20 + test: "exit 0" + #test: "curl http://localhost:8022/" + #interval: 5s + #timeout: 1s + #retries: 20 zookeeper: image: confluentinc/cp-zookeeper:5.0.1 @@ -138,11 +139,8 @@ services: hostname: shumaich container_name: shumaich restart: on-failure - ports: - - "8033:8033" environment: SPRING_APPLICATION_JSON: '{ - "server.port": "8033", "rocksdb.name": "shumaich", "rocksdb.dir": "/temp/rocksdb", "kafka.bootstrap-servers": "broker:9092", From d669de8a9af7764baa7a7fad1926e097a2772830 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 7 Jul 2021 17:16:09 +0300 Subject: [PATCH 11/26] fix tests, fix accounter link --- apps/hellgate/test/hg_ct_helper.erl | 2 +- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 1 + docker-compose.sh | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/hellgate/test/hg_ct_helper.erl b/apps/hellgate/test/hg_ct_helper.erl index 0f87fb534..ee0578ccc 100644 --- a/apps/hellgate/test/hg_ct_helper.erl +++ b/apps/hellgate/test/hg_ct_helper.erl @@ -134,7 +134,7 @@ start_app(hellgate = AppName) -> }}, {services, #{ accounter => <<"http://shumway:8022/shumpune">>, - accounter_new => <<"http://shumaich:8022/shumaich">>, + accounter_new => <<"http://shumway:8022/shumaich">>, automaton => <<"http://machinegun:8022/v1/automaton">>, customer_management => #{ url => <<"http://hellgate:8022/v1/processing/customer_management">>, diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index e31ab6883..a2ec5922d 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -5134,6 +5134,7 @@ await_payment_rollback(InvoiceID, PaymentID, Client) -> ] = next_event(InvoiceID, Client), [ ?payment_ev(PaymentID, ?cash_flow_changed(_)), + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure})) ] = next_event(InvoiceID, Client), Failure. diff --git a/docker-compose.sh b/docker-compose.sh index f90b112d1..81932382a 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -43,6 +43,7 @@ services: volumes: - ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml - ./test/machinegun/cookie:/opt/machinegun/etc/cookie + - ./test/log/machinegun:/var/log/machinegun healthcheck: test: "curl http://localhost:8022/" interval: 5s From 8e92d77030f7dde280a3dc401c6c36587ec19b6e Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 12 Jul 2021 15:14:44 +0300 Subject: [PATCH 12/26] formatting --- apps/hellgate/src/hg_invoice_payment.erl | 6 ------ apps/hellgate/test/hg_invoice_tests_SUITE.erl | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 583be8ad9..f1cd69160 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -2549,14 +2549,10 @@ rollback_refund_limits(RefundSt, St) -> TurnoverLimits = get_turnover_limits(ProviderTerms), hg_limiter:rollback_refund_limits(TurnoverLimits, Invoice, Payment, Refund). -% commit_payment_cashflow(St) -> -% hg_accounting:commit(construct_payment_plan_id(St), get_cashflow_plan(St)). commit_payment_cashflow(St = #st{clock = Clock}) -> #{timestamp := Timestamp} = get_opts(St), hg_accounting_new:commit(construct_payment_plan_id(St), get_cashflow_plan(St), Timestamp, Clock). -% rollback_payment_cashflow(St) -> -% hg_accounting:rollback(construct_payment_plan_id(St), get_cashflow_plan(St)). rollback_payment_cashflow(St = #st{clock = Clock}) -> #{timestamp := Timestamp} = get_opts(St), hg_accounting_new:rollback(construct_payment_plan_id(St), get_cashflow_plan(St), Timestamp, Clock). @@ -2902,7 +2898,6 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S {payment, cash_flow_building} -> St#st{ cash_flow = Cashflow - % activity = {payment, processing_session} }; {payment, processing_capture} -> St#st{ @@ -2918,7 +2913,6 @@ merge_change(Change = ?payment_clock_update(Clock), #st{activity = Activity} = S {payment, S} || S <- [ cash_flow_building, - % processing_capture, processing_session, processing_failure, finalizing_accounter, diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 2392cefdb..878161048 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -415,9 +415,9 @@ groups() -> -spec init_per_suite(config()) -> config(). init_per_suite(C) -> - %%_ = dbg:tracer(), - %%_ = dbg:p(all, c), - %%_ = dbg:tpl({'hg_invoice_payment', 'merge_change', '_'}, x), + % _ = dbg:tracer(), + % _ = dbg:p(all, c), + % _ = dbg:tpl({'hg_invoice_payment', 'p', '_'}, x), CowboySpec = hg_dummy_provider:get_http_cowboy_spec(), {Apps, Ret} = hg_ct_helper:start_apps([ From 00ba190c7d321f91b5160df7b12193650213fbd2 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 12 Jul 2021 18:30:55 +0300 Subject: [PATCH 13/26] update accounter get_balance --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index f20fa709a..30866c14f 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1396,13 +1396,13 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertMatch(#{max_available_amount := 40110}, hg_ct_helper:get_balance(SettlementID)), + ?assertMatch(#{max_available_amount := 40110}, hg_accounting_new: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_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_ct_helper:get_balance(SettlementID)), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), ?assertException( error, {{woody_error, _}, _}, @@ -1424,14 +1424,14 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_ct_helper:get_balance(SettlementID)), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_ct_helper:get_balance(SettlementID)), + ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), ?assertException( error, {{woody_error, _}, _}, From 6a329cbc5fdfdb8d92e17f3493a7fbbe8236001f Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 12 Jul 2021 18:36:34 +0300 Subject: [PATCH 14/26] run formatter --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 30866c14f..25a1cf6bf 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1402,7 +1402,10 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_started())) ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting_new:get_balance(SettlementID) + ), ?assertException( error, {{woody_error, _}, _}, @@ -1424,14 +1427,20 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting_new:get_balance(SettlementID) + ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ ?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _)), ?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started())) ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), - ?assertMatch(#{min_available_amount := 0, max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := 0, max_available_amount := 40110}, + hg_accounting_new:get_balance(SettlementID) + ), ?assertException( error, {{woody_error, _}, _}, From ce294488607027e5ef316f45abb9c344b7a87115 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 12 Jul 2021 19:38:57 +0300 Subject: [PATCH 15/26] revert for old get_balance --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 25a1cf6bf..370e6a052 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1396,7 +1396,7 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertMatch(#{max_available_amount := 40110}, hg_accounting_new:get_balance(SettlementID)), + ?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())) @@ -1404,7 +1404,7 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> timeout = next_event(InvoiceID, Client), ?assertMatch( #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting_new:get_balance(SettlementID) + hg_accounting:get_balance(SettlementID) ), ?assertException( error, @@ -1429,7 +1429,7 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch( #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting_new:get_balance(SettlementID) + hg_accounting:get_balance(SettlementID) ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ @@ -1439,7 +1439,7 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> timeout = next_event(InvoiceID, Client), ?assertMatch( #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting_new:get_balance(SettlementID) + hg_accounting:get_balance(SettlementID) ), ?assertException( error, From a95b8c5e1672fdf877021bf2bfad6e510d9380be Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 14 Jul 2021 17:26:53 +0300 Subject: [PATCH 16/26] save accounter clock on capture/cancel --- apps/hellgate/src/hg_invoice_payment.erl | 8 ++++---- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 20 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index f1cd69160..69a926b63 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -2136,18 +2136,18 @@ process_result({payment, processing_failure}, Action, St = #st{failure = Failure {done, {[?payment_clock_update(Clock), ?payment_status_changed(?failed(Failure))], NewAction}}; process_result({payment, finalizing_accounter}, Action, St) -> Target = get_target(St), - _Clocks = + AccounterClock = case Target of ?captured() -> - commit_payment_limits(St), + _LimiterClock = commit_payment_limits(St), commit_payment_cashflow(St); ?cancelled() -> - rollback_payment_limits(St), + _LimiterClock = rollback_payment_limits(St), rollback_payment_cashflow(St) end, check_recurrent_token(St), NewAction = get_action(Target, Action, St), - {done, {[?payment_status_changed(Target)], NewAction}}; + {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; process_result({refund_failure, ID}, Action, St) -> RefundSt = try_get_refund_state(ID, St), Failure = RefundSt#refund_st.failure, diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 370e6a052..05ccfa3e5 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1396,15 +1396,18 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> InvoiceID = start_invoice(ShopID, <<"rubberduck">>, make_due_date(1000), Amount, C), PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), - ?assertMatch(#{max_available_amount := 40110}, hg_accounting:get_balance(SettlementID)), + ?assertMatch( + #{min_available_amount := -1890, max_available_amount := 42000}, + hg_accounting_new: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_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), ?assertMatch( - #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting:get_balance(SettlementID) + #{min_available_amount := -1890, max_available_amount := 42000}, + hg_accounting_new:get_balance(SettlementID) ), ?assertException( error, @@ -1428,8 +1431,8 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch( - #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting:get_balance(SettlementID) + #{min_available_amount := -1890, max_available_amount := 42000}, + hg_accounting_new:get_balance(SettlementID) ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), [ @@ -1438,8 +1441,8 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), ?assertMatch( - #{min_available_amount := 0, max_available_amount := 40110}, - hg_accounting:get_balance(SettlementID) + #{min_available_amount := -1890, max_available_amount := 42000}, + hg_accounting_new:get_balance(SettlementID) ), ?assertException( error, @@ -1466,6 +1469,7 @@ repair_failed_cancel(InvoiceID, PaymentID, Reason, Client) -> ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_event(InvoiceID, Client), PaymentID. @@ -5219,6 +5223,7 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, Restarts, Cos ?payment_ev(PaymentID, ?session_ev(Target, ?session_finished(?session_succeeded()))) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(Target)), ?invoice_status_changed(?invoice_paid()) ] = next_event(InvoiceID, Client), @@ -5232,6 +5237,7 @@ await_payment_cancel(InvoiceID, PaymentID, Reason, Client) -> ?payment_ev(PaymentID, ?session_ev(?cancelled_with_reason(Reason), ?session_finished(?session_succeeded()))) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(?cancelled_with_reason(Reason))) ] = next_event(InvoiceID, Client), PaymentID. From eb164178157b614aa856e8d5c623b5ca1c57bfa8 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 14 Jul 2021 17:43:36 +0300 Subject: [PATCH 17/26] fix adjustment SUITE --- apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl index 2d3ca74ef..7b798ba08 100644 --- a/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_adjustment_tests_SUITE.erl @@ -966,6 +966,7 @@ await_payment_capture_finish(InvoiceID, PaymentID, Reason, Client, Restarts, Cos ?payment_ev(PaymentID, ?session_ev(Target, ?session_finished(?session_succeeded()))) ] = next_event(InvoiceID, Client), [ + ?payment_ev(PaymentID, ?payment_clock_update(_)), ?payment_ev(PaymentID, ?payment_status_changed(Target)), ?invoice_status_changed(?invoice_paid()) ] = next_event(InvoiceID, Client), From 89d009752ae9add4c50dcf9d1086be82268da61b Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 21 Jul 2021 12:03:22 +0300 Subject: [PATCH 18/26] rollback docker-compose --- docker-compose.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docker-compose.sh b/docker-compose.sh index 81932382a..31d3db890 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -43,7 +43,6 @@ services: volumes: - ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml - ./test/machinegun/cookie:/opt/machinegun/etc/cookie - - ./test/log/machinegun:/var/log/machinegun healthcheck: test: "curl http://localhost:8022/" interval: 5s @@ -77,11 +76,13 @@ services: - postgres - shumaich healthcheck: + # FIXME: dirty trick, hangs in "health: staring" otherwise + # used to be fine test: "exit 0" - #test: "curl http://localhost:8022/" - #interval: 5s - #timeout: 1s - #retries: 20 + # test: "curl http://localhost:8022/" + # interval: 5s + # timeout: 1s + # retries: 20 zookeeper: image: confluentinc/cp-zookeeper:5.0.1 From 71c1b8e6f610f4a2a928435e8616112be501b778 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Thu, 29 Jul 2021 16:44:57 +0300 Subject: [PATCH 19/26] fix clock update change merging --- apps/hellgate/src/hg_invoice_payment.erl | 25 ++++++------------------ 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 69a926b63..9ae92bd7c 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -2897,7 +2897,8 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S case Activity of {payment, cash_flow_building} -> St#st{ - cash_flow = Cashflow + cash_flow = Cashflow, + activity = {payment, processing_session} }; {payment, processing_capture} -> St#st{ @@ -2907,36 +2908,22 @@ merge_change(Change = ?cash_flow_changed(Cashflow), #st{activity = Activity} = S _ -> St end; -merge_change(Change = ?payment_clock_update(Clock), #st{activity = Activity} = St, Opts) -> +merge_change(Change = ?payment_clock_update(Clock), #st{} = St, Opts) -> _ = validate_transition( [ {payment, S} || S <- [ - cash_flow_building, processing_session, + updating_accounter, processing_failure, - finalizing_accounter, - updating_accounter + finalizing_accounter ] ], Change, St, Opts ), - case Activity of - {payment, cash_flow_building} -> - St#st{ - clock = Clock, - activity = {payment, processing_session} - }; - {payment, processing_capture} -> - St#st{ - clock = Clock, - activity = {payment, updating_accounter} - }; - _ -> - St - end; + St#st{clock = Clock}; merge_change(Change = ?rec_token_acquired(Token), #st{} = St, Opts) -> _ = validate_transition([{payment, processing_session}, {payment, finalizing_session}], Change, St, Opts), St#st{recurrent_token = Token}; From e9799d6234ef8fe5aeed36c13e81ef2a881167f2 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 20 Sep 2021 18:57:13 +0300 Subject: [PATCH 20/26] use new hg_accounting_new api --- apps/hellgate/src/hg_invoice_payment.erl | 49 +++++++++++++++--------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 9ae92bd7c..aa0b2ca6e 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1880,7 +1880,7 @@ process_cash_flow_building(Action, St) -> TurnoverLimits = get_turnover_limits(ProviderTerms), ok = hg_limiter:hold_payment_limits(TurnoverLimits, Invoice, Payment), FinalCashflow = calculate_cashflow(Route, Payment, MerchantTerms, ProviderTerms, VS1, Revision, Opts), - Clock = hg_accounting_new:hold( + {ok, Clock} = hg_accounting_new:hold( construct_payment_plan_id(Invoice, Payment), {1, FinalCashflow}, Timestamp @@ -1983,7 +1983,7 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap Invoice = get_invoice(Opts), Payment = get_payment(St), Payment2 = Payment#domain_InvoicePayment{cost = Cost}, - NewClock = hg_accounting_new:plan( + {ok, NewClock} = hg_accounting_new:plan( construct_payment_plan_id(Invoice, Payment2), [ {2, hg_cashflow:revert(get_cashflow(St))}, @@ -2130,24 +2130,27 @@ process_result({payment, processing_accounter}, Action, St) -> NewAction = get_action(Target, Action, St), {done, {[?payment_status_changed(Target)], NewAction}}; process_result({payment, processing_failure}, Action, St = #st{failure = Failure}) -> - NewAction = hg_machine_action:set_timeout(0, Action), - _ = rollback_payment_limits(St), - Clock = rollback_payment_cashflow(St), - {done, {[?payment_clock_update(Clock), ?payment_status_changed(?failed(Failure))], NewAction}}; + case rollback_payment_cashflow(St) of + {ok, AccounterClock} -> + _ = rollback_payment_limits(St), + NewAction = hg_machine_action:set_timeout(0, Action), + {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(?failed(Failure))], NewAction}}; + {error, not_ready} -> + %% Accounter was not ready, retry + {next, {[], hg_machine_action:set_timeout(0, Action)}} + end; process_result({payment, finalizing_accounter}, Action, St) -> Target = get_target(St), - AccounterClock = - case Target of - ?captured() -> - _LimiterClock = commit_payment_limits(St), - commit_payment_cashflow(St); - ?cancelled() -> - _LimiterClock = rollback_payment_limits(St), - rollback_payment_cashflow(St) - end, - check_recurrent_token(St), - NewAction = get_action(Target, Action, St), - {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; + case finalize_payment_accounter(Target, St) of + {ok, AccounterClock} -> + _ = finalize_payment_limiter(Target, St), + _ = check_recurrent_token(St), + NewAction = get_action(Target, Action, St), + {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; + {error, not_ready} -> + %% Accounter was not ready, retry + {next, {[], hg_machine_action:set_timeout(0, Action)}} + end; process_result({refund_failure, ID}, Action, St) -> RefundSt = try_get_refund_state(ID, St), Failure = RefundSt#refund_st.failure, @@ -2242,6 +2245,16 @@ process_payment_session_callback(Payload, State) -> erlang:raise(error, Reason, StackTrace) end. +finalize_payment_accounter(?captured(), St) -> + commit_payment_cashflow(St); +finalize_payment_accounter(?cancelled(), St) -> + rollback_payment_cashflow(St). + +finalize_payment_limiter(?captured(), St) -> + commit_payment_limits(St); +finalize_payment_limiter(?cancelled(), St) -> + rollback_payment_limits(St). + check_recurrent_token(#st{ payment = #domain_InvoicePayment{id = ID, make_recurrent = true}, recurrent_token = undefined From 1dcca57e09b8d523cd855a39c6e47fd5fd9bed84 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Mon, 20 Sep 2021 19:38:54 +0300 Subject: [PATCH 21/26] fix tests --- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 05ccfa3e5..8ff528896 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -1397,7 +1397,7 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> PaymentParams = make_scenario_payment_params([good, fail, good], {hold, capture}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch( - #{min_available_amount := -1890, max_available_amount := 42000}, + {ok, #{min_available_amount := -1890, max_available_amount := 42000}}, hg_accounting_new:get_balance(SettlementID) ), ok = hg_client_invoicing:cancel_payment(InvoiceID, PaymentID, <<"cancel">>, Client), @@ -1406,7 +1406,7 @@ payment_error_in_cancel_session_does_not_cause_payment_failure(C) -> ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), ?assertMatch( - #{min_available_amount := -1890, max_available_amount := 42000}, + {ok, #{min_available_amount := -1890, max_available_amount := 42000}}, hg_accounting_new:get_balance(SettlementID) ), ?assertException( @@ -1431,7 +1431,7 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> PaymentParams = make_scenario_payment_params([good, fail, good], {hold, cancel}), PaymentID = process_payment(InvoiceID, PaymentParams, Client), ?assertMatch( - #{min_available_amount := -1890, max_available_amount := 42000}, + {ok, #{min_available_amount := -1890, max_available_amount := 42000}}, hg_accounting_new:get_balance(SettlementID) ), ok = hg_client_invoicing:capture_payment(InvoiceID, PaymentID, <<"capture">>, Client), @@ -1441,7 +1441,7 @@ payment_error_in_capture_session_does_not_cause_payment_failure(C) -> ] = next_event(InvoiceID, Client), timeout = next_event(InvoiceID, Client), ?assertMatch( - #{min_available_amount := -1890, max_available_amount := 42000}, + {ok, #{min_available_amount := -1890, max_available_amount := 42000}}, hg_accounting_new:get_balance(SettlementID) ), ?assertException( From 5b10855a63caa8c1307528615bf0d8bcd88813e0 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Tue, 21 Sep 2021 17:30:41 +0300 Subject: [PATCH 22/26] add some logging --- apps/hellgate/src/hg_invoice_payment.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index aa0b2ca6e..64cbb36ca 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -2136,7 +2136,7 @@ process_result({payment, processing_failure}, Action, St = #st{failure = Failure NewAction = hg_machine_action:set_timeout(0, Action), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(?failed(Failure))], NewAction}}; {error, not_ready} -> - %% Accounter was not ready, retry + _ = logger:warning("Accounter was not ready, retrying"), {next, {[], hg_machine_action:set_timeout(0, Action)}} end; process_result({payment, finalizing_accounter}, Action, St) -> @@ -2148,7 +2148,7 @@ process_result({payment, finalizing_accounter}, Action, St) -> NewAction = get_action(Target, Action, St), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; {error, not_ready} -> - %% Accounter was not ready, retry + _ = logger:warning("Accounter was not ready, retrying"), {next, {[], hg_machine_action:set_timeout(0, Action)}} end; process_result({refund_failure, ID}, Action, St) -> From af22bcee4ae74d7ae1c78a21a59f7b86609d8481 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 22 Sep 2021 15:46:51 +0300 Subject: [PATCH 23/26] account for :plan actually being not ready --- apps/hellgate/src/hg_invoice_payment.erl | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 64cbb36ca..eb8ec21ac 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1983,17 +1983,24 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap Invoice = get_invoice(Opts), Payment = get_payment(St), Payment2 = Payment#domain_InvoicePayment{cost = Cost}, - {ok, NewClock} = hg_accounting_new:plan( - construct_payment_plan_id(Invoice, Payment2), - [ - {2, hg_cashflow:revert(get_cashflow(St))}, - {3, FinalCashflow} - ], - Timestamp, - St#st.clock - ), - Events = start_session(?captured(Reason, Cost, Cart)), - {next, {[?payment_clock_update(NewClock) | Events], hg_machine_action:set_timeout(0, Action)}}. + case + hg_accounting_new:plan( + construct_payment_plan_id(Invoice, Payment2), + [ + {2, hg_cashflow:revert(get_cashflow(St))}, + {3, FinalCashflow} + ], + Timestamp, + St#st.clock + ) + of + {ok, NewClock} -> + Events = start_session(?captured(Reason, Cost, Cart)), + {next, {[?payment_clock_update(NewClock) | Events], hg_machine_action:set_timeout(0, Action)}}; + {error, not_ready} -> + _ = logger:warning("Accounter was not ready, retrying"), + {next, {[], hg_machine_action:set_timeout(0, Action)}} + end. %% From ac47ab34769deba89a2a12034be655cf8382bab1 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 22 Sep 2021 16:50:21 +0300 Subject: [PATCH 24/26] switch to resource unavailable for accounter retries --- apps/hellgate/src/hg_invoice_payment.erl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index eb8ec21ac..616e703b5 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1998,8 +1998,7 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap Events = start_session(?captured(Reason, Cost, Cart)), {next, {[?payment_clock_update(NewClock) | Events], hg_machine_action:set_timeout(0, Action)}}; {error, not_ready} -> - _ = logger:warning("Accounter was not ready, retrying"), - {next, {[], hg_machine_action:set_timeout(0, Action)}} + woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) end. %% @@ -2143,8 +2142,7 @@ process_result({payment, processing_failure}, Action, St = #st{failure = Failure NewAction = hg_machine_action:set_timeout(0, Action), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(?failed(Failure))], NewAction}}; {error, not_ready} -> - _ = logger:warning("Accounter was not ready, retrying"), - {next, {[], hg_machine_action:set_timeout(0, Action)}} + woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) end; process_result({payment, finalizing_accounter}, Action, St) -> Target = get_target(St), @@ -2155,8 +2153,7 @@ process_result({payment, finalizing_accounter}, Action, St) -> NewAction = get_action(Target, Action, St), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; {error, not_ready} -> - _ = logger:warning("Accounter was not ready, retrying"), - {next, {[], hg_machine_action:set_timeout(0, Action)}} + woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) end; process_result({refund_failure, ID}, Action, St) -> RefundSt = try_get_refund_state(ID, St), From 67656b31d3cd7767cac5986b8134a36abd6a0549 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Thu, 23 Sep 2021 14:55:46 +0300 Subject: [PATCH 25/26] avoid resource_unavailable when not necessary --- apps/hellgate/src/hg_invoice_payment.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 616e703b5..eb8ec21ac 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1998,7 +1998,8 @@ process_accounter_update(Action, St = #st{partial_cash_flow = FinalCashflow, cap Events = start_session(?captured(Reason, Cost, Cart)), {next, {[?payment_clock_update(NewClock) | Events], hg_machine_action:set_timeout(0, Action)}}; {error, not_ready} -> - woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) + _ = logger:warning("Accounter was not ready, retrying"), + {next, {[], hg_machine_action:set_timeout(0, Action)}} end. %% @@ -2142,7 +2143,8 @@ process_result({payment, processing_failure}, Action, St = #st{failure = Failure NewAction = hg_machine_action:set_timeout(0, Action), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(?failed(Failure))], NewAction}}; {error, not_ready} -> - woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) + _ = logger:warning("Accounter was not ready, retrying"), + {next, {[], hg_machine_action:set_timeout(0, Action)}} end; process_result({payment, finalizing_accounter}, Action, St) -> Target = get_target(St), @@ -2153,7 +2155,8 @@ process_result({payment, finalizing_accounter}, Action, St) -> NewAction = get_action(Target, Action, St), {done, {[?payment_clock_update(AccounterClock), ?payment_status_changed(Target)], NewAction}}; {error, not_ready} -> - woody_error:raise(system, {external, resource_unavailable, <<"Accounter was not ready">>}) + _ = logger:warning("Accounter was not ready, retrying"), + {next, {[], hg_machine_action:set_timeout(0, Action)}} end; process_result({refund_failure, ID}, Action, St) -> RefundSt = try_get_refund_state(ID, St), From a1ffcd716d47020456ddc6e5fccf6e6c1daeddb1 Mon Sep 17 00:00:00 2001 From: Kehitt Date: Wed, 6 Oct 2021 13:48:27 +0300 Subject: [PATCH 26/26] fix deleted hold/3 --- apps/hellgate/src/hg_invoice_payment.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index eb8ec21ac..e74c98757 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1883,7 +1883,8 @@ process_cash_flow_building(Action, St) -> {ok, Clock} = hg_accounting_new:hold( construct_payment_plan_id(Invoice, Payment), {1, FinalCashflow}, - Timestamp + Timestamp, + undefined ), Events = [?cash_flow_changed(FinalCashflow), ?payment_clock_update(Clock)], case hg_limiter:check_limits(TurnoverLimits, Invoice, Payment) of