Bug 28606: Remove $DEBUG and $ENV{DEBUG}
[koha.git] / C4 / SIP / ILS / Transaction / FeePayment.pm
1 package C4::SIP::ILS::Transaction::FeePayment;
2
3 use warnings;
4 use strict;
5
6 # Copyright 2011 PTFS-Europe Ltd.
7 #
8 # This file is part of Koha.
9 #
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.
14 #
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.
19 #
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>.
22
23 use Koha::Account;
24 use Koha::Account::Lines;
25
26 use parent qw(C4::SIP::ILS::Transaction);
27
28 my %fields = ();
29
30 sub new {
31     my $class = shift;
32     my $self  = $class->SUPER::new();
33
34     foreach ( keys %fields ) {
35         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
36     }
37
38     @{$self}{ keys %fields } = values %fields;    # copying defaults into object
39     return bless $self, $class;
40 }
41
42 sub pay {
43     my $self                 = shift;
44     my $borrowernumber       = shift;
45     my $amt                  = shift;
46     my $sip_type             = shift;
47     my $fee_id               = shift;
48     my $is_writeoff          = shift;
49     my $disallow_overpayment = shift;
50     my $register_id          = shift;
51
52     my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
53
54     my $account = Koha::Account->new( { patron_id => $borrowernumber } );
55
56     if ($disallow_overpayment) {
57         return { ok => 0 } if $account->balance < $amt;
58     }
59
60     if ($fee_id) {
61         my $fee = Koha::Account::Lines->find($fee_id);
62         if ( $fee ) {
63             my $pay_response = $account->pay(
64                 {
65                     amount       => $amt,
66                     type         => $type,
67                     payment_type => 'SIP' . $sip_type,
68                     lines        => [$fee],
69                     interface    => C4::Context->interface
70                 }
71             );
72             return {
73                 ok           => 1,
74                 pay_response => $pay_response
75             };
76         }
77         else {
78             return {
79                 ok => 0
80             };
81         }
82     }
83     else {
84         my $pay_response = $account->pay(
85             {
86                 amount        => $amt,
87                 type          => $type,
88                 payment_type  => 'SIP' . $sip_type,
89                 interface     => C4::Context->interface,
90                 cash_register => $register_id
91             }
92         );
93         return {
94             ok           => 1,
95             pay_response => $pay_response
96         };
97     }
98 }
99
100 #sub DESTROY {
101 #}
102
103 1;
104 __END__
105