2 # An object to handle fee payment
5 package OpenILS::SIP::Transaction::FeePayment;
10 use POSIX qw(strftime);
13 use OpenILS::SIP::Transaction;
14 use OpenILS::SIP::Msg qw/:const/;
15 use Sys::Syslog qw(syslog);
17 use OpenILS::Application::AppUtils;
18 my $U = 'OpenILS::Application::AppUtils';
21 our @ISA = qw(OpenILS::SIP::Transaction);
23 # Most fields are handled by the Transaction superclass
25 sip_payment_type => undef,
27 patron_password => undef,
33 my $self = $class->SUPER::new(@_);
35 foreach my $element (keys %fields) {
36 $self->{_permitted}->{$element} = $fields{$element};
39 @{$self}{keys %fields} = values %fields;
40 return bless $self, $class;
45 my $results = $U->simplereq('open-ils.actor', 'open-ils.actor.user.transactions.history.have_balance', $self->{authtoken}, $self->patron->internal_id);
46 if (ref $results eq 'ARRAY') {
47 syslog('LOG_INFO', scalar @$results . " bills found for " . $self->patron->internal_id);
48 my $payment = $self->fee_amount;
49 foreach my $bill (@{$results}) {
50 syslog('LOG_INFO', 'bill '. $bill->id . ' amount ' . $bill->balance_owed);
51 if (!$self->transaction_id) {
52 if ($bill->balance_owed >= $payment) {
53 $self->pay_bill($bill->id, $payment);
57 $self->pay_bill($bill->id, $bill->balance_owed);
58 $payment -= $bill->balance_owed;
60 last unless ($payment);
62 elsif ($self->transaction_id == $bill->id) {
63 $self->pay_bill($bill->id, $payment);
68 if ($payment == $self->fee_amount) {
70 if (!$self->transaction_id) {
71 $self->screen_msg("Payment failed: you have no bills.");
74 $self->screen_msg("Payment failed: transaction " + $self->transaction_id + " not found.");
83 $self->screen_msg($results->{descr});
88 my ($self, $bill, $amount) = @_;
89 my $user = $self->patron->{user};
90 my $r = $U->simplereq('open-ils.circ', 'open-ils.circ.money.payment', $self->{authtoken},
91 { payment_type => "cash_payment", userid => $user->id, note => "via SIP2",
92 payments => [[$bill, $amount ]]}, $user->last_xact_id);