Skip to content

Commit 0d99453

Browse files
authored
TD-917: Fix cashflow adj from failed to capture (#135)
* fixed * fixed fmt and naming * fixed * added refund test * added minor * added refund tests for amount changed by adapter * fixed
1 parent 5accc10 commit 0d99453

File tree

3 files changed

+428
-6
lines changed

3 files changed

+428
-6
lines changed

apps/hellgate/src/hg_accounting.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ construct_balance(
281281
call_accounter(Function, Args) ->
282282
hg_woody_wrapper:call(accounter, Function, Args).
283283

284+
get_payment_cost(#domain_InvoicePayment{changed_cost = Cost}) when Cost =/= undefined ->
285+
Cost;
284286
get_payment_cost(#domain_InvoicePayment{cost = Cost}) ->
285287
Cost.
286288

apps/hellgate/src/hg_invoice_payment.erl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,13 @@ create_cash_flow_adjustment(Timestamp, Params, DomainRevision, St, Opts) ->
14811481
revision => NewRevision,
14821482
allocation => Allocation
14831483
},
1484-
NewCashFlow = calculate_cashflow(Context, Opts),
1484+
NewCashFlow =
1485+
case Payment of
1486+
#domain_InvoicePayment{status = {failed, _}} ->
1487+
[];
1488+
_ ->
1489+
calculate_cashflow(Context, Opts)
1490+
end,
14851491
AdjState =
14861492
{cash_flow, #domain_InvoicePaymentAdjustmentCashFlowState{
14871493
scenario = #domain_InvoicePaymentAdjustmentCashFlow{domain_revision = DomainRevision}
@@ -1605,17 +1611,26 @@ get_cash_flow_for_target_status({captured, Captured}, St0, Opts) ->
16051611
Route = get_route(St0),
16061612
Cost = get_captured_cost(Captured, Payment0),
16071613
Allocation = get_captured_allocation(Captured),
1608-
Payment = Payment0#domain_InvoicePayment{
1614+
Payment1 = Payment0#domain_InvoicePayment{
16091615
cost = Cost
16101616
},
1611-
Timestamp = get_payment_created_at(Payment),
1612-
St = St0#st{payment = Payment},
1613-
Revision = Payment#domain_InvoicePayment.domain_revision,
1617+
Payment2 =
1618+
case Payment1 of
1619+
#domain_InvoicePayment{changed_cost = ChangedCost} when ChangedCost =/= undefined ->
1620+
Payment1#domain_InvoicePayment{
1621+
cost = ChangedCost
1622+
};
1623+
_ ->
1624+
Payment1
1625+
end,
1626+
Timestamp = get_payment_created_at(Payment2),
1627+
St = St0#st{payment = Payment2},
1628+
Revision = Payment2#domain_InvoicePayment.domain_revision,
16141629
VS = collect_validation_varset(St, Opts),
16151630
Context = #{
16161631
provision_terms => get_provider_terminal_terms(Route, VS, Revision),
16171632
route => Route,
1618-
payment => Payment,
1633+
payment => Payment2,
16191634
timestamp => Timestamp,
16201635
varset => VS,
16211636
revision => Revision,
@@ -2982,6 +2997,8 @@ get_invoice_shop_id(#domain_Invoice{shop_id = ShopID}) ->
29822997
get_payment_id(#domain_InvoicePayment{id = ID}) ->
29832998
ID.
29842999

3000+
get_payment_cost(#domain_InvoicePayment{changed_cost = Cost}) when Cost =/= undefined ->
3001+
Cost;
29853002
get_payment_cost(#domain_InvoicePayment{cost = Cost}) ->
29863003
Cost.
29873004

0 commit comments

Comments
 (0)