-
Notifications
You must be signed in to change notification settings - Fork 6
HG-544: shumaich payments #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: HG-544/ft/shumaich
Are you sure you want to change the base?
Changes from 27 commits
f442a23
60fa8c1
6475e7f
7fe1bc8
7606445
93f7e06
2ddb2e0
c9b2b97
6f0aa4d
66b8dc9
bf0f00e
8e97457
90fa3ed
16f5d00
d669de8
cdebb46
8e92d77
72dd5c4
9722940
00ba190
6a329cb
ce29448
a95b8c5
eb16417
ab8d363
ceee1fb
89d0097
71c1b8e
5868efd
de705af
e9799d6
1dcca57
4577567
5b10855
1734ddc
af22bce
ac47ab3
ccc2568
e7f7d71
67656b3
06f5d93
dc9c896
d23a389
a9e3a8d
a1ffcd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 :: undefined | hg_accounting_new:clock() | ||
| }). | ||
|
|
||
| -record(refund_st, { | ||
|
|
@@ -1879,11 +1880,12 @@ 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:hold( | ||
| Clock = hg_accounting_new:hold( | ||
| construct_payment_plan_id(Invoice, Payment), | ||
| {1, FinalCashflow} | ||
| {1, FinalCashflow}, | ||
| Timestamp | ||
| ), | ||
| Events = [?cash_flow_changed(FinalCashflow)], | ||
| Events = [?cash_flow_changed(FinalCashflow), ?payment_clock_update(Clock)], | ||
| case hg_limiter:check_limits(TurnoverLimits, Invoice, Payment) of | ||
| {ok, _} -> | ||
| {next, {Events, hg_machine_action:set_timeout(0, Action)}}; | ||
|
|
@@ -1972,7 +1974,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, | ||
|
|
@@ -1981,15 +1983,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)}}. | ||
|
|
||
| %% | ||
|
|
||
|
|
@@ -2128,22 +2132,22 @@ process_result({payment, processing_accounter}, Action, St) -> | |
| process_result({payment, processing_failure}, Action, St = #st{failure = Failure}) -> | ||
| NewAction = hg_machine_action:set_timeout(0, Action), | ||
| _ = rollback_payment_limits(St), | ||
| _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 = | ||
| 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, | ||
|
|
@@ -2545,11 +2549,13 @@ 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}) -> | ||
|
0x42 marked this conversation as resolved.
|
||
| #{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). | ||
|
|
||
| get_cashflow_plan(St = #st{partial_cash_flow = PartialCashFlow}) when PartialCashFlow =/= undefined -> | ||
| [ | ||
|
|
@@ -2891,8 +2897,7 @@ 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 | ||
| }; | ||
| {payment, processing_capture} -> | ||
| St#st{ | ||
|
|
@@ -2902,6 +2907,36 @@ 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) -> | ||
| _ = validate_transition( | ||
| [ | ||
| {payment, S} | ||
| || S <- [ | ||
| cash_flow_building, | ||
| 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} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем выносить определение activity на этот этап? Почему clock обновляется только для cash_flow_build и processing_capture а для остальных игнорируется?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, кажется вполне можно обойтись и без этого |
||
| }; | ||
| {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}; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что будет после этой строчки если мы упадем, сделаем ретрай. И вызовем второй раз hold, Clock вернется другой? Это будет один и тот же hold или разные?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, что эта ситуация не будет отличаться от текущей. Clock - время последней известной операции для сущности, идемпотентность оно не обеспечивает.