From 6b31c23572be078b222c0409fbb9c5bb91bf9ef1 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 12 May 2011 15:05:28 -0400 Subject: [PATCH] Make it work, in the most basic way. Still a lot of work to do, like adding cc payments, but it can pay bills with cash and doesn't crash when doing so. Signed-off-by: Jason Stephenson --- Open-ILS/src/perlmods/lib/OpenILS/SIP.pm | 9 +-- .../src/perlmods/lib/OpenILS/SIP/Transaction.pm | 2 +- .../lib/OpenILS/SIP/Transaction/FeePayment.pm | 83 +++++++++++----------- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm index e79f90d4be..a309db7c78 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm @@ -14,6 +14,7 @@ use OpenILS::SIP::Transaction; use OpenILS::SIP::Transaction::Checkout; use OpenILS::SIP::Transaction::Checkin; use OpenILS::SIP::Transaction::Renew; +use OpenILS::SIP::Transaction::FeePayment; use OpenSRF::System; use OpenILS::Utils::Fieldmapper; @@ -412,13 +413,13 @@ sub pay_fee { my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency) = @_; - my $xact = OpenILS::SIP::Transaction::FeePayment->new(authtoken => $self->authtoken); + my $xact = OpenILS::SIP::Transaction::FeePayment->new(authtoken => $self->{authtoken}); my $patron = $self->find_patron($patron_id); if (!$patron) { - $xact->screen_msg("Invalid Patron Barcode '$patron_id'"); - $xact->ok(0); - return $xact; + $xact->screen_msg("Invalid Patron Barcode '$patron_id'"); + $xact->ok(0); + return $xact; } $xact->patron($patron); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction.pm index eeb9fafc80..a4813cb147 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction.pm @@ -18,7 +18,7 @@ my %fields = ( item => undef, desensitize => 0, alert => '', - transation_id => undef, + transaction_id => undef, sip_fee_type => '01', # Other/Unknown fee_amount => undef, sip_currency => 'CAD', diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/FeePayment.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/FeePayment.pm index 0f36b6d7c1..03894e6703 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/FeePayment.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/FeePayment.pm @@ -35,7 +35,7 @@ sub new { my $element; foreach $element (keys %fields) { - $self->{_permitted}->{$element} = $fields{$element}; + $self->{_permitted}->{$element} = $fields{$element}; } @{$self}{keys %fields} = values %fields; @@ -44,55 +44,56 @@ sub new { sub do_fee_payment { my $self = shift; - my $results = $U->simplereq('open-ils.actor', 'open-ils.actor.user.transactions.history.have_balance', $self->{authtoken}, $self->patron->id); + my $results = $U->simplereq('open-ils.actor', 'open-ils.actor.user.transactions.history.have_balance', $self->{authtoken}, $self->patron->internal_id); if (ref $results eq 'ARRAY') { - my $bill; - my $payment = $self->fee_amount; - foreach $bill (@{$results}) { - if (!$self->transaction_id) { - if ($bill->balance_owed >= $payment) { - $self->pay_bill($bill->id, $payment); - $payment = 0; - } - else { - $self->pay_bill($bill->id, $bill->balance_owed); - $payment -= $bill->balance_owed; - } - last unless ($payment); - } - elsif ($self->transaction_id == $bill->id) { - $self->pay_bill($bill->id, $payment); - $payment = 0; - last; - } - } - if ($payment == $self->fee_amount) { - $self->ok(0); - if (!$self->transaction_id) { - $self->screen_msg("Payment failed: you have no bills."); - } - else { - $self->screen_msg("Payment failed: transaction " + $self->transaction_id + " not found."); - } - } - else { - $self->ok(1); - } + syslog('LOG_INFO', scalar @$results . " bills found for " . $self->patron->internal_id); + my $bill; + my $payment = $self->fee_amount; + foreach $bill (@{$results}) { + syslog('LOG_INFO', 'bill '. $bill->id . ' amount ' . $bill->balance_owed); + if (!$self->transaction_id) { + if ($bill->balance_owed >= $payment) { + $self->pay_bill($bill->id, $payment); + $payment = 0; + } + else { + $self->pay_bill($bill->id, $bill->balance_owed); + $payment -= $bill->balance_owed; + } + last unless ($payment); + } + elsif ($self->transaction_id == $bill->id) { + $self->pay_bill($bill->id, $payment); + $payment = 0; + last; + } + } + if ($payment == $self->fee_amount) { + $self->ok(0); + if (!$self->transaction_id) { + $self->screen_msg("Payment failed: you have no bills."); + } + else { + $self->screen_msg("Payment failed: transaction " + $self->transaction_id + " not found."); + } + } + else { + $self->ok(1); + } } else { - $self->ok(0); - $self->screen_msg($results->{descr}); + $self->ok(0); + $self->screen_msg($results->{descr}); } } sub pay_bill { - my ($bill, $amount) = @_; - my $user = $self->patron; + my ($self, $bill, $amount) = @_; + my $user = $self->patron->{user}; my $r = $U->simplereq('open-ils.circ', 'open-ils.circ.money.payment', $self->{authtoken}, - { payment_type => "cash_payment", userid => $user->id, note => "via SIP2", - payments => [[$bill, $amount ]]}, $user->last_xact_id); - $self->patron->last_xact_id($r->last_xact_id) if ($r->last_xact_id); + { payment_type => "cash_payment", userid => $user->id, note => "via SIP2", + payments => [[$bill, $amount ]]}, $user->last_xact_id); } -- 2.11.0