From a53f1c700f19517ef07ee8c9a29132705848dd65 Mon Sep 17 00:00:00 2001 From: Petr Kozorezov Date: Tue, 3 Apr 2018 13:47:27 +0300 Subject: [PATCH] add payment error logs (#198) --- apps/hellgate/src/hg_invoice_payment.erl | 36 ++++++++++++++++-------- rebar.lock | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/hellgate/src/hg_invoice_payment.erl b/apps/hellgate/src/hg_invoice_payment.erl index 019cddf..dfac048 100644 --- a/apps/hellgate/src/hg_invoice_payment.erl +++ b/apps/hellgate/src/hg_invoice_payment.erl @@ -1738,16 +1738,15 @@ get_log_params(?payment_started(Payment, _, _, Cashflow), _) -> event_type => invoice_payment_started }, make_log_params(Params); -get_log_params(?payment_status_changed({Status, _}), State) -> - Payment = get_payment(State), - Cashflow = get_cashflow(State), - Params = #{ - status => Status, - payment => Payment, - cashflow => Cashflow, - event_type => invoice_payment_status_changed - }, - make_log_params(Params); +get_log_params(?payment_status_changed(Status), State) -> + make_log_params( + #{ + status => Status, + payment => get_payment(State), + cashflow => get_cashflow(State), + event_type => invoice_payment_status_changed + } + ); get_log_params(_, _) -> undefined. @@ -1791,11 +1790,24 @@ make_log_params(cashflow, CashFlow) -> Reminders ), [{accounts, Accounts}]; -make_log_params(status, Status) -> - [{status, Status}]; +make_log_params(status, {StatusTag, StatusDetails}) -> + [{status, StatusTag}] ++ format_status_details(StatusDetails); make_log_params(event_type, EventType) -> [{type, EventType}]. +format_status_details(#domain_InvoicePaymentFailed{failure = Failure}) -> + [{error, list_to_binary(format_failure(Failure))}]; +format_status_details(_) -> + []. + +format_failure({operation_timeout, _}) -> + [<<"timeout">>]; +format_failure({failure, Failure}) -> + format_domain_failure(Failure). + +format_domain_failure(Failure) -> + payproc_errors:format_raw(Failure). + get_account_key({AccountParty, AccountType}) -> list_to_binary(lists:concat([atom_to_list(AccountParty), ".", atom_to_list(AccountType)])). diff --git a/rebar.lock b/rebar.lock index 4adf10b..14a7fcd 100644 --- a/rebar.lock +++ b/rebar.lock @@ -36,7 +36,7 @@ {<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.0.2">>},2}, {<<"payproc_errors">>, {git,"git@github.com:rbkmoney/payproc-errors-erlang.git", - {ref,"17e6976c6f05fc2c1adeccaff2b58b4aa99d0181"}}, + {ref,"9c720534eb88edc6ba47af084939efabceb9b2d6"}}, 0}, {<<"ranch">>,{pkg,<<"ranch">>,<<"1.4.0">>},2}, {<<"rfc3339">>,{pkg,<<"rfc3339">>,<<"0.9.0">>},0},