Bug 23051: (follow-up) Add renewal feedback and move code to subroutines and test
[koha.git] / C4 / SIP / ILS / Transaction / FeePayment.pm
blob152c17610e416d1710f685a7f475ca8f61fd5f27
1 package C4::SIP::ILS::Transaction::FeePayment;
3 use warnings;
4 use strict;
6 # Copyright 2011 PTFS-Europe Ltd.
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Koha::Account;
24 use Koha::Account::Lines;
26 use parent qw(C4::SIP::ILS::Transaction);
28 our $debug = 0;
30 my %fields = ();
32 sub new {
33 my $class = shift;
34 my $self = $class->SUPER::new();
36 foreach ( keys %fields ) {
37 $self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
40 @{$self}{ keys %fields } = values %fields; # copying defaults into object
41 return bless $self, $class;
44 sub pay {
45 my $self = shift;
46 my $borrowernumber = shift;
47 my $amt = shift;
48 my $sip_type = shift;
49 my $fee_id = shift;
50 my $is_writeoff = shift;
51 my $disallow_overpayment = shift;
53 my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
55 warn("RECORD:$borrowernumber::$amt");
57 my $account = Koha::Account->new( { patron_id => $borrowernumber } );
59 if ($disallow_overpayment) {
60 return { ok => 0 } if $account->balance < $amt;
63 if ($fee_id) {
64 my $fee = Koha::Account::Lines->find($fee_id);
65 if ( $fee ) {
66 my $pay_response = $account->pay(
68 amount => $amt,
69 type => $type,
70 payment_type => 'SIP' . $sip_type,
71 lines => [$fee],
72 interface => C4::Context->interface
75 return {
76 ok => 1,
77 pay_response => $pay_response
80 else {
81 return {
82 ok => 0
86 else {
87 my $pay_response = $account->pay(
89 amount => $amt,
90 type => $type,
91 payment_type => 'SIP' . $sip_type,
92 interface => C4::Context->interface
95 return {
96 ok => 1,
97 pay_response => $pay_response
102 #sub DESTROY {
106 __END__