-
Notifications
You must be signed in to change notification settings - Fork 6
HG-544: shumaich chargebacks #520
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_payments
Are you sure you want to change the base?
Changes from 37 commits
9ae8b9d
6435b7e
6c950db
f01c609
f9f27ee
6c30541
b8fc370
5a4e8b5
5db1283
0807343
6638fef
d081737
2e12caf
6da85b1
59e5cfe
be2fe42
caee121
8ccaf63
fd1ec4e
239fa28
a45348e
a717600
6a975bc
9f38487
8a710aa
953bc87
43aa3ac
cf718d5
a391675
8c5a95f
d309afd
0c04b7a
a681572
2701323
35a6957
6889d5d
8658d5f
b48aca4
e7f6dde
fb00cdf
4a4f066
7dbcc1c
9510a6d
a2e7af3
45937c0
bcd4877
484569f
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 |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| -export( | ||
| [ | ||
| merge_change/2, | ||
| process_timeout/4 | ||
| process_timeout/5 | ||
| ] | ||
| ). | ||
|
|
||
|
|
@@ -54,6 +54,7 @@ | |
|
|
||
| -record(chargeback_st, { | ||
| chargeback :: undefined | chargeback(), | ||
| clock :: undefined | clock(), | ||
|
0x42 marked this conversation as resolved.
Outdated
|
||
| target_status :: undefined | status(), | ||
| cash_flow = [] :: cash_flow(), | ||
| cash_flow_plans = #{ | ||
|
|
@@ -75,12 +76,16 @@ | |
| -type opts() :: #{ | ||
| payment_state := payment_state(), | ||
| party := party(), | ||
| invoice := invoice() | ||
| invoice := invoice(), | ||
| timestamp := hg_datetime:timestamp() | ||
| }. | ||
|
|
||
| -type payment_state() :: | ||
| hg_invoice_payment:st(). | ||
|
|
||
| -type clock() :: | ||
| hg_accounting_new:clock(). | ||
|
|
||
| -type party() :: | ||
| dmsl_domain_thrift:'Party'(). | ||
|
|
||
|
|
@@ -112,7 +117,7 @@ | |
| dmsl_domain_thrift:'FinalCashFlow'(). | ||
|
|
||
| -type batch() :: | ||
| hg_accounting:batch(). | ||
| hg_accounting_new:batch(). | ||
|
|
||
| -type create_params() :: | ||
| dmsl_payment_processing_thrift:'InvoicePaymentChargebackParams'(). | ||
|
|
@@ -140,8 +145,10 @@ | |
|
|
||
| -type activity() :: | ||
| preparing_initial_cash_flow | ||
| | holding_initial_cash_flow | ||
| | updating_chargeback | ||
| | updating_cash_flow | ||
| | holding_updated_cash_flow | ||
| | finalising_accounter. | ||
|
|
||
| -spec get(state()) -> chargeback(). | ||
|
|
@@ -263,16 +270,22 @@ merge_change(?chargeback_target_status_changed(Status), State) -> | |
| set_target_status(Status, State); | ||
| merge_change(?chargeback_status_changed(Status), State) -> | ||
| set_target_status(undefined, set_status(Status, State)); | ||
| merge_change(?chargeback_clock_update(_), State) -> | ||
| State; | ||
| merge_change(?chargeback_cash_flow_changed(CashFlow), State) -> | ||
| set_cash_flow(CashFlow, State). | ||
|
|
||
| -spec process_timeout(activity(), state(), action(), opts()) -> result(). | ||
| process_timeout(preparing_initial_cash_flow, State, _Action, Opts) -> | ||
| update_cash_flow(State, hg_machine_action:new(), Opts); | ||
| process_timeout(updating_cash_flow, State, _Action, Opts) -> | ||
| -spec process_timeout(activity(), state(), payment_state(), action(), opts()) -> result(). | ||
| process_timeout(preparing_initial_cash_flow, State, _PaymentSt, _Action, Opts) -> | ||
| update_cash_flow(State, hg_machine_action:instant(), Opts); | ||
| process_timeout(holding_initial_cash_flow, State, PaymentSt, _Action, Opts) -> | ||
| hold_cash_flow(State, PaymentSt, hg_machine_action:new(), Opts); | ||
| process_timeout(updating_cash_flow, State, _PaymentSt, _Action, Opts) -> | ||
| update_cash_flow(State, hg_machine_action:instant(), Opts); | ||
| process_timeout(finalising_accounter, State, Action, Opts) -> | ||
| finalise(State, Action, Opts). | ||
| process_timeout(holding_updated_cash_flow, State, PaymentSt, _Action, Opts) -> | ||
| hold_cash_flow(State, PaymentSt, hg_machine_action:instant(), Opts); | ||
| process_timeout(finalising_accounter, State, PaymentSt, Action, Opts) -> | ||
| finalise(State, PaymentSt, Action, Opts). | ||
|
|
||
| %% Private | ||
|
|
||
|
|
@@ -340,20 +353,24 @@ do_reopen(State, PaymentState, ReopenParams = ?reopen_params(Levy, Body)) -> | |
| -spec update_cash_flow(state(), action(), opts()) -> result() | no_return(). | ||
| update_cash_flow(State, Action, Opts) -> | ||
| FinalCashFlow = build_chargeback_cash_flow(State, Opts), | ||
| UpdatedPlan = build_updated_plan(FinalCashFlow, State), | ||
| _ = prepare_cash_flow(State, UpdatedPlan, Opts), | ||
| {[?chargeback_cash_flow_changed(FinalCashFlow)], Action}. | ||
|
|
||
| -spec finalise(state(), action(), opts()) -> result() | no_return(). | ||
| finalise(#chargeback_st{target_status = Status = ?chargeback_status_pending()}, Action, _Opts) -> | ||
| -spec hold_cash_flow(state(), payment_state(), action(), opts()) -> result() | no_return(). | ||
| hold_cash_flow(State, PaymentSt, Action, Opts) -> | ||
| CashFlowPlan = get_current_plan(State), | ||
| Clock = prepare_cash_flow(get_clock(PaymentSt), State, CashFlowPlan, Opts), | ||
| {[?chargeback_clock_update(Clock)], Action}. | ||
|
|
||
| -spec finalise(state(), payment_state(), action(), opts()) -> result() | no_return(). | ||
| finalise(#chargeback_st{target_status = Status = ?chargeback_status_pending()}, _PaymentSt, Action, _Opts) -> | ||
| {[?chargeback_status_changed(Status)], Action}; | ||
| finalise(State = #chargeback_st{target_status = Status}, Action, Opts) when | ||
| finalise(State = #chargeback_st{target_status = Status}, PaymentSt, Action, Opts) when | ||
| Status =:= ?chargeback_status_rejected(); | ||
| Status =:= ?chargeback_status_accepted(); | ||
| Status =:= ?chargeback_status_cancelled() | ||
| -> | ||
| _ = commit_cash_flow(State, Opts), | ||
| {[?chargeback_status_changed(Status)], Action}. | ||
| Clock = commit_cash_flow(get_clock(PaymentSt), State, Opts), | ||
|
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. Почему в случае отмены(cancelled) не делается rollback?
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. А разве эта логика поменялась по отношению к мастеру? Если нет, то наверное лучше спросить у того, кто лучше знаком с процессом, почему так сделано |
||
| {[?chargeback_clock_update(Clock), ?chargeback_status_changed(Status)], Action}. | ||
|
|
||
| -spec build_chargeback(opts(), create_params(), revision(), timestamp()) -> chargeback() | no_return(). | ||
| build_chargeback(Opts, Params = ?chargeback_params(Levy, Body, Reason), Revision, CreatedAt) -> | ||
|
|
@@ -430,7 +447,7 @@ build_chargeback_cash_flow(State, Opts) -> | |
| PaymentInstitutionRef = get_payment_institution_ref(get_contract(Party, Shop)), | ||
| PaymentInst = hg_payment_institution:compute_payment_institution(PaymentInstitutionRef, VS, Revision), | ||
| Provider = get_route_provider(Route, Revision), | ||
| AccountMap = hg_accounting:collect_account_map(Payment, Shop, PaymentInst, Provider, VS, Revision), | ||
| AccountMap = hg_accounting_new:collect_account_map(Payment, Shop, PaymentInst, Provider, VS, Revision), | ||
| ServiceContext = build_service_cash_flow_context(State), | ||
| ProviderContext = build_provider_cash_flow_context(State, ProviderFees), | ||
| ServiceFinalCF = hg_cashflow:finalize(ServiceCashFlow, ServiceContext, AccountMap), | ||
|
|
@@ -495,14 +512,16 @@ define_body(undefined, PaymentState) -> | |
| define_body(Cash, _PaymentState) -> | ||
| Cash. | ||
|
|
||
| prepare_cash_flow(State, CashFlowPlan, Opts) -> | ||
| prepare_cash_flow(Clock, State, CashFlowPlan, Opts) -> | ||
| #{timestamp := Timestamp} = Opts, | ||
| PlanID = construct_chargeback_plan_id(State, Opts), | ||
| hg_accounting:plan(PlanID, CashFlowPlan). | ||
| hg_accounting_new:plan(PlanID, CashFlowPlan, Timestamp, Clock). | ||
|
|
||
| commit_cash_flow(State, Opts) -> | ||
| commit_cash_flow(Clock, State, Opts) -> | ||
| #{timestamp := Timestamp} = Opts, | ||
| CashFlowPlan = get_current_plan(State), | ||
| PlanID = construct_chargeback_plan_id(State, Opts), | ||
| hg_accounting:commit(PlanID, CashFlowPlan). | ||
| hg_accounting_new:commit(PlanID, CashFlowPlan, Timestamp, Clock). | ||
|
|
||
| construct_chargeback_plan_id(State, Opts) -> | ||
| {Stage, _} = get_stage(State), | ||
|
|
@@ -605,6 +624,10 @@ get_current_plan(#chargeback_st{cash_flow_plans = Plans} = State) -> | |
| #{Stage := Plan} = Plans, | ||
| Plan. | ||
|
|
||
| -spec get_clock(payment_state()) -> clock(). | ||
| get_clock(PaymentSt) -> | ||
| hg_invoice_payment:get_clock(PaymentSt). | ||
|
|
||
| -spec get_reverted_previous_stage(state()) -> [batch()]. | ||
| get_reverted_previous_stage(State) -> | ||
| case get_previous_stage(State) of | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.