Koha/C4/SIP/ILS/Transaction/FeePayment.pm
Andrew Isherwood a2449a81be
Bug 23051: (follow-up) Add renewal feedback and move code to subroutines and test
Rebasing was a nightmare, so I'm squashing the sign off follow-ups to
ease the pain with any future rebases

Includes:

Bug 23051: (follow-up) Refactor renewal code
As per Nick's first point in comment #20, the code that tests for
renewability and renews items has been refactored into it's own
function.

Bug 23051: (follow-up) Provide feedback
For renewals that fail when a fine is being paid off, this patch causes
any errors to be passed back to the template for display.
Addresses the second point in Nick's comment #20

Bug 23051: (follow-up) Fix unit tests
As raised by Nick in comment #35

Bug 23051: (follow-up) Fix/improve feedback
This follow up patch addresses the following parts of Nick's feedback in
comment #35:
- it would be nice to get feedback on what was successfully renewed as well
- In general I think I would prefer to see 'ok' and 'not_ok' returned as
a single 'renewal_results' array
- There is no listing of errors if I use the 'pay' button on an
individual fine

Bug 23051: (follow-up) Refactor methods
This follow up patch addresses the following parts of Nick's feedback in
comment #35:
- I don't really like that the functions are internal functions and then
exported
- I think the pref description should highlight that if 'RenewalPeriodBase'
is set to due date, there may be doubled charges

Bug 23051: (follow-up) Add SIP summary
This follow up patch addresses the following parts of Nick's feedback in
comment #35:
- Ideally SIP would get feedback in a screen message

Bug 23051: (follow-up) Renewing in OPAC
This follow up patch addresses the following parts of Nick's feedback in
comment #35:
- I am also not sure about the code path if a patron paid fines on the
opac (via paypal etc.) but renewals are not allowed on the opac.

We've introduced the syspref RenewAccruingItemInOpac (default is off)
which, when enabled, will cause items attached to fines that are paid
off in the OPAC (via payment plugins), to be automatically renewed.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-03-06 10:03:34 +00:00

107 lines
2.7 KiB
Perl

package C4::SIP::ILS::Transaction::FeePayment;
use warnings;
use strict;
# Copyright 2011 PTFS-Europe Ltd.
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Koha::Account;
use Koha::Account::Lines;
use parent qw(C4::SIP::ILS::Transaction);
our $debug = 0;
my %fields = ();
sub new {
my $class = shift;
my $self = $class->SUPER::new();
foreach ( keys %fields ) {
$self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
}
@{$self}{ keys %fields } = values %fields; # copying defaults into object
return bless $self, $class;
}
sub pay {
my $self = shift;
my $borrowernumber = shift;
my $amt = shift;
my $sip_type = shift;
my $fee_id = shift;
my $is_writeoff = shift;
my $disallow_overpayment = shift;
my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
warn("RECORD:$borrowernumber::$amt");
my $account = Koha::Account->new( { patron_id => $borrowernumber } );
if ($disallow_overpayment) {
return { ok => 0 } if $account->balance < $amt;
}
if ($fee_id) {
my $fee = Koha::Account::Lines->find($fee_id);
if ( $fee ) {
my $pay_response = $account->pay(
{
amount => $amt,
type => $type,
payment_type => 'SIP' . $sip_type,
lines => [$fee],
interface => C4::Context->interface
}
);
return {
ok => 1,
pay_response => $pay_response
};
}
else {
return {
ok => 0
};
}
}
else {
my $pay_response = $account->pay(
{
amount => $amt,
type => $type,
payment_type => 'SIP' . $sip_type,
interface => C4::Context->interface
}
);
return {
ok => 1,
pay_response => $pay_response
};
}
}
#sub DESTROY {
#}
1;
__END__