diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 5a83fea5..e485f8d3 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -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(). @@ -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( @@ -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(); @@ -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(). @@ -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, diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index 21856b5e..fa500256 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -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]). @@ -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 ]}, @@ -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(), @@ -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), @@ -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). diff --git a/rebar.config b/rebar.config index 8c367d87..1983cfeb 100644 --- a/rebar.config +++ b/rebar.config @@ -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"}}}, diff --git a/rebar.lock b/rebar.lock index 0a6e64cf..1797ceff 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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",