From a0484a907527f9e77e8d3911c12411c14003a615 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Tue, 14 Mar 2023 07:06:21 -0400 Subject: [PATCH] Bug 33216: Catch and handle RegisterRequired exceptions for SIP fee paid messages If registers are being used in Koha, they are required. If a SIP account has no register and a fee paid message is sent, the SIP server crashes and the client never gets a response. It would be much better if Koha would response with 38 response where "payment accepted" is N, and an AF field stating that the SIP account needs to be associated with a register. Test Plan: 1) Enable UseCashRegisters, set RequireCashRegister to "always require a cash register". Do *not* set a cash register for the SIP account you will be testing with. 2) Using the SIP cli tester, send a fee paid message for a patron owing fees. 3) Note the lack of a SIP response 4) Apply this patch 5) Restart the SIP server 6) Repeat step 2, you should now get a SIP response with the error message in it! Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 0411bf0573708327a9c0271f4d01c2996641bb3f) Signed-off-by: Jacob O'Mara (cherry picked from commit c6610d5ed97c03a090039606aecfe7f5d6917876) Signed-off-by: Lucas Gass (cherry picked from commit 175dd2871c2ac00997cad13e0dba215688e85baa) Signed-off-by: Arthur Suzuki --- C4/SIP/ILS.pm | 3 ++- C4/SIP/ILS/Transaction/FeePayment.pm | 26 +++++++++++++++++++++++--- C4/SIP/Sip/MsgType.pm | 1 + 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index 145fe89aac..503009f298 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -279,7 +279,8 @@ sub pay_fee { return { status => $trans, - pay_response => $trans_result->{pay_response} + pay_response => $trans_result->{pay_response}, + error => $trans_result->{error}, }; } diff --git a/C4/SIP/ILS/Transaction/FeePayment.pm b/C4/SIP/ILS/Transaction/FeePayment.pm index 80d9698694..a9fae17da9 100644 --- a/C4/SIP/ILS/Transaction/FeePayment.pm +++ b/C4/SIP/ILS/Transaction/FeePayment.pm @@ -20,6 +20,8 @@ use strict; # You should have received a copy of the GNU General Public License # along with Koha; if not, see . +use Try::Tiny; + use Koha::Account; use Koha::Account::Lines; @@ -76,10 +78,28 @@ sub pay { }; } } - my $pay_response = $account->pay($pay_options); + + my $ok = 1; + my $pay_response; + my $error; + try { + $pay_response = $account->pay($pay_options); + } + catch { + $ok = 0; + + if ( ref($_) =~ /^Koha::Exceptions/ ) { + $error = $_->description; + } + else { + $_->rethrow; + } + }; + return { - ok => 1, - pay_response => $pay_response + ok => $ok, + pay_response => $pay_response, + error => $error, }; } diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 2152bd1539..c42a9166d3 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -1182,6 +1182,7 @@ sub handle_fee_paid { $resp .= add_field( FID_INST_ID, $inst_id, $server ); $resp .= add_field( FID_PATRON_ID, $patron_id, $server ); $resp .= maybe_add( FID_TRANSACTION_ID, $status->transaction_id, $server ); + $resp .= maybe_add( FID_SCREEN_MSG, $pay_result->{error}, $server ); $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); -- 2.39.5