Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion apps/hellgate/src/hg_invoice_payment.erl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
-type adjustment_params() :: dmsl_payproc_thrift:'InvoicePaymentAdjustmentParams'().
-type adjustment_state() :: dmsl_domain_thrift:'InvoicePaymentAdjustmentState'().
-type adjustment_status_change() :: dmsl_domain_thrift:'InvoicePaymentAdjustmentStatusChange'().
-type adjustment_transaction_info() :: dmsl_domain_thrift:'InvoicePaymentAdjustmentTransactionInfo'().
-type target() :: dmsl_domain_thrift:'TargetInvoicePaymentStatus'().
-type session_target_type() :: 'processed' | 'captured' | 'cancelled' | 'refunded'.
-type risk_score() :: hg_inspector:risk_score().
Expand Down Expand Up @@ -1398,7 +1399,9 @@ create_adjustment(Timestamp, Params, St, Opts) ->
{cash_flow, #domain_InvoicePaymentAdjustmentCashFlow{domain_revision = DomainRevision}} ->
create_cash_flow_adjustment(Timestamp, Params, DomainRevision, St, Opts);
{status_change, Change} ->
create_status_adjustment(Timestamp, Params, Change, St, Opts)
create_status_adjustment(Timestamp, Params, Change, St, Opts);
{transaction_info, Change} ->
create_transaction_info_adjustment(Timestamp, Params, Change, St)
end.

-spec create_cash_flow_adjustment(
Expand Down Expand Up @@ -1498,6 +1501,35 @@ create_status_adjustment(Timestamp, Params, Change, St, Opts) ->
St
).

-spec create_transaction_info_adjustment(
hg_datetime:timestamp(),
adjustment_params(),
adjustment_transaction_info(),
st()
) -> {adjustment(), result()}.
create_transaction_info_adjustment(Timestamp, Params, Change, St) ->
#domain_InvoicePaymentAdjustmentTransactionInfo{} = Change,
#domain_InvoicePayment{
status = Status,
domain_revision = DomainRevision
} = get_payment(St),
ok = assert_adjustment_payment_status(Status),
AdjState =
{transaction_info, #domain_InvoicePaymentAdjustmentTransactionInfoState{
scenario = Change
}},
%% Transaction info adjustment does not affect cash flow.
construct_adjustment(
Timestamp,
Params,
DomainRevision,
[],
[],
AdjState,
[],
St
).

-spec maybe_get_domain_revision(undefined | hg_domain:revision()) -> hg_domain:revision().
maybe_get_domain_revision(undefined) ->
hg_domain:head();
Expand Down Expand Up @@ -1761,6 +1793,13 @@ get_adjustment_cashflow(#domain_InvoicePaymentAdjustment{new_cash_flow = Cashflo
}}
}).

-define(adjustment_transaction_info(Trx), #domain_InvoicePaymentAdjustment{
state =
{transaction_info, #domain_InvoicePaymentAdjustmentTransactionInfoState{
scenario = #domain_InvoicePaymentAdjustmentTransactionInfo{trx = Trx}
}}
}).

%%

-spec process_signal(timeout, st(), opts()) -> machine_result().
Expand Down Expand Up @@ -3697,6 +3736,8 @@ merge_adjustment_change(?adjustment_created(Adjustment), undefined) ->
merge_adjustment_change(?adjustment_status_changed(Status), Adjustment) ->
Adjustment#domain_InvoicePaymentAdjustment{status = Status}.

apply_adjustment_effects(?adjustment_transaction_info(Trx), St) ->
set_trx(Trx, St);
apply_adjustment_effects(Adjustment, St) ->
apply_adjustment_effect(
status,
Expand Down
46 changes: 46 additions & 0 deletions apps/hellgate/test/hg_invoice_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
-export([payment_adjustment_failed_from_captured/1]).
-export([payment_adjustment_change_amount_and_captured/1]).
-export([payment_adjustment_change_amount_and_refund_all/1]).
-export([payment_adjustment_transaction_info_success/1]).
-export([status_adjustment_of_partial_refunded_payment/1]).
-export([registered_payment_adjustment_success/1]).
-export([invalid_payment_w_deprived_party/1]).
Expand Down Expand Up @@ -351,6 +352,7 @@ groups() ->
payment_adjustment_failed_from_captured,
payment_adjustment_change_amount_and_captured,
payment_adjustment_change_amount_and_refund_all,
payment_adjustment_transaction_info_success,
status_adjustment_of_partial_refunded_payment,
registered_payment_adjustment_success
]},
Expand Down Expand Up @@ -691,6 +693,7 @@ init_per_testcase(Name, C) when
Name == payment_adjustment_failed_from_captured;
Name == payment_adjustment_change_amount_and_captured;
Name == payment_adjustment_change_amount_and_refund_all;
Name == payment_adjustment_transaction_info_success;
Name == registered_payment_adjustment_success
->
Revision = hg_domain:head(),
Expand Down Expand Up @@ -3234,6 +3237,40 @@ payment_adjustment_change_amount_and_refund_all(C) ->
maps:get(own_amount, SysAccount2) - maps:get(own_amount, SysAccount1)
).

-spec payment_adjustment_transaction_info_success(config()) -> test_return().
payment_adjustment_transaction_info_success(C) ->
Client = cfg(client, C),
InvoiceID = start_invoice(<<"rubberduck">>, make_due_date(10), 100000, C),
PaymentParams = make_payment_params(?pmt_sys(<<"visa-ref">>)),
NewTrx = ?trx_info(<<"adjusted-trx-id">>, #{<<"rrn">> => <<"adjusted-rrn">>}),
AdjustmentParams = make_transaction_info_adjustment_params(NewTrx, AdjReason = <<"fix trx">>),
?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
?invalid_payment_status(?pending()) =
hg_client_invoicing:create_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client),
PaymentID = await_payment_started(InvoiceID, PaymentID, Client),
{_CF, _Route} = await_payment_cash_flow(InvoiceID, PaymentID, Client),
PaymentID = await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
PaymentID = await_payment_process_finish(InvoiceID, PaymentID, Client),
PaymentID = await_payment_capture(InvoiceID, PaymentID, Client),
#payproc_InvoicePayment{last_transaction_info = OriginalTrx} =
hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client),
?assertMatch(#domain_TransactionInfo{}, OriginalTrx),
?assertNotEqual(NewTrx, OriginalTrx),
CashFlowBefore = get_payment_cashflow_mapped(InvoiceID, PaymentID, Client),
AdjustmentID = execute_payment_adjustment(InvoiceID, PaymentID, AdjustmentParams, Client),
#domain_InvoicePaymentAdjustment{
reason = AdjReason,
state =
{transaction_info, #domain_InvoicePaymentAdjustmentTransactionInfoState{
scenario = #domain_InvoicePaymentAdjustmentTransactionInfo{trx = NewTrx}
}},
new_cash_flow = [],
old_cash_flow_inverse = []
} = hg_client_invoicing:get_payment_adjustment(InvoiceID, PaymentID, AdjustmentID, Client),
#payproc_InvoicePayment{last_transaction_info = NewTrx} =
hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client),
?assertEqual(CashFlowBefore, get_payment_cashflow_mapped(InvoiceID, PaymentID, Client)).

-spec status_adjustment_of_partial_refunded_payment(config()) -> test_return().
status_adjustment_of_partial_refunded_payment(C) ->
Client = cfg(client, C),
Expand Down Expand Up @@ -8099,6 +8136,15 @@ make_status_adjustment_params(Status, Reason) ->
}}
}.

make_transaction_info_adjustment_params(Trx, Reason) ->
#payproc_InvoicePaymentAdjustmentParams{
reason = Reason,
scenario =
{transaction_info, #domain_InvoicePaymentAdjustmentTransactionInfo{
trx = Trx
}}
}.

make_due_date(LifetimeSeconds) ->
hg_invoice_helper:make_due_date(LifetimeSeconds).

Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {tag, "v1.1.2"}}},
{scoper, {git, "https://github.com/valitydev/scoper.git", {tag, "v1.1.0"}}},
{thrift, {git, "https://github.com/valitydev/thrift_erlang.git", {tag, "v1.0.0"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.38"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.40"}}},
{exrates_proto, {git, "https://github.com/valitydev/exrates-proto.git", {branch, "master"}}},
{payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}},
{mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"c529750144dea43ada113436762ee1e340f5503d"}},
{ref,"b07c077bb2f1f36394417450a37b08e5cfeac462"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt-client.git",
Expand Down
Loading