From 0e3c586c52ad3885f6677ea1b370c609739427cd 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. --- C4/SIP/ILS.pm | 3 ++- C4/SIP/ILS/Transaction/FeePayment.pm | 23 ++++++++++++++++++++--- C4/SIP/Sip/MsgType.pm | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index f33aaee5c4..b61578a971 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -310,7 +310,8 @@ sub pay_fee { return { status => $trans, - pay_response => $trans_result->{pay_response} + pay_response => $trans_result->{pay_response}, + error => $error, }; } diff --git a/C4/SIP/ILS/Transaction/FeePayment.pm b/C4/SIP/ILS/Transaction/FeePayment.pm index 80d9698694..85d58cdc23 100644 --- a/C4/SIP/ILS/Transaction/FeePayment.pm +++ b/C4/SIP/ILS/Transaction/FeePayment.pm @@ -76,10 +76,27 @@ 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 { + if ( ref($_) eq 'Koha::Exceptions::Account::RegisterRequired' ) { + $ok = 0; + $error = q{SIP account must be associated with a register for 'fee paid' messages to succeed}; + } + 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 7ba61959a3..f24ce78c60 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -1153,6 +1153,8 @@ sub handle_fee_paid { $status = $pay_result->{status}; my $pay_response = $pay_result->{pay_response}; + $resp .= maybe_add( FID_SCREEN_MSG, $pay_result->{error}, $server ) if $pay_result->{error if $pay_result->{error}; + my $failmap = { "no_item" => "No matching item could be found", "no_checkout" => "Item is not checked out", -- 2.30.2