Fix invoice expiration timeout set on finalized invoices (#442)

This commit is contained in:
Andrey Fadeev 2020-06-03 20:23:29 +03:00 committed by GitHub
parent 7eea076a4d
commit c2a1d07c31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -459,7 +459,7 @@ init([InvoiceTplID, PartyRevision, EncodedInvoiceParams], #{id := ID}) ->
% TODO ugly, better to roll state and events simultaneously, hg_party-like
handle_result(#{
changes => [?invoice_created(Invoice)],
action => set_invoice_timer(#st{invoice = Invoice}),
action => set_invoice_timer(hg_machine_action:new(), #st{invoice = Invoice}),
state => #st{}
}).
@ -727,8 +727,13 @@ assert_no_pending_payment(#st{activity = {payment, PaymentID}}) ->
assert_no_pending_payment(_) ->
ok.
set_invoice_timer(#st{invoice = #domain_Invoice{due = Due}}) ->
hg_machine_action:set_deadline(Due).
set_invoice_timer(Action, #st{invoice = Invoice} = St) ->
set_invoice_timer(Invoice#domain_Invoice.status, Action, St).
set_invoice_timer(?invoice_unpaid(), Action, #st{invoice = #domain_Invoice{due = Due}}) ->
hg_machine_action:set_deadline(Due, Action);
set_invoice_timer(_Status, Action, _St) ->
Action.
capture_payment(PaymentSession, Reason, undefined, Cart, Opts) when
Cart =/= undefined
@ -823,13 +828,13 @@ handle_payment_result({done, {Changes1, Action}}, PaymentID, PaymentSession, #st
?failed(_) ->
#{
changes => wrap_payment_changes(PaymentID, Changes1),
action => set_invoice_timer(St),
action => set_invoice_timer(Action, St),
state => St
};
?cancelled() ->
#{
changes => wrap_payment_changes(PaymentID, Changes1),
action => set_invoice_timer(St),
action => set_invoice_timer(Action, St),
state => St
}
end.

View File

@ -1751,7 +1751,7 @@ payment_adjustment_captured_from_failed(C) ->
Cpatured = ?captured(),
AdjustmentParams = make_status_adjustment_params(Cpatured, AdjReason = <<"manual">>),
Amount = 42000,
InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(3), Amount, C),
PaymentParams = make_scenario_payment_params([temp, temp, temp, temp]),
% start payment
?payment_state(?payment(PaymentID)) =
@ -1763,6 +1763,7 @@ payment_adjustment_captured_from_failed(C) ->
PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
{failed, PaymentID, {failure, _Failure}} =
await_payment_process_failure(InvoiceID, PaymentID, Client, 3),
[?invoice_status_changed(?invoice_cancelled(<<"overdue">>))] = next_event(InvoiceID, Client),
% get balances
PrvAccount1 = get_cashflow_account({provider, settlement}, CF1),
SysAccount1 = get_cashflow_account({system, settlement}, CF1),