Bug 16757 - Add ability to pay fee by id for SIP2
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 16 Jun 2016 14:50:44 +0000 (14:50 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 31 Mar 2017 13:56:36 +0000 (13:56 +0000)
The SIP protocol allows for a Fee Paid message to specify a fee
identifier in the CG field. While this field is read and passed to
C4::SIP::ILS::pay_fee, it is not passed along to
C4::SIP::ILS::Transaction::FeePayment::pay and is thus not used. We
should enable this functionality in Koha now that accountlines each have
a unique identifier that can be passed along to the payment requestor
via the AV field line items added by bug 14512.

Test Plan:
1) Create a fee in Koha
2) Ensure your SIP2 server is running and configured correctly
3) Send a 37 Fee Paid message to Koha's SIP server with the
   accountlines_id for that fee in the CG fee identifier field,
   along with the other required fields.
4) Note that specific fee was paid in Koha

Signed-off-by: Rhonda Kuiper <kuiper@roundrocktexas.gov>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/SIP/ILS.pm
C4/SIP/ILS/Transaction/FeePayment.pm

index 7a40777..dba0ccb 100644 (file)
@@ -247,13 +247,11 @@ sub end_patron_session {
 }
 
 sub pay_fee {
-    my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type,
-       $pay_type, $fee_id, $trans_id, $currency) = @_;
+    my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency) = @_;
     my $trans;
 
     $trans = C4::SIP::ILS::Transaction::FeePayment->new();
 
-
     $trans->transaction_id($trans_id);
     my $patron;
     $trans->patron($patron = C4::SIP::ILS::Patron->new($patron_id));
@@ -261,8 +259,8 @@ sub pay_fee {
         $trans->screen_msg('Invalid patron barcode.');
         return $trans;
     }
-    $trans->pay($patron->{borrowernumber},$fee_amt, $pay_type);
-    $trans->ok(1);
+    my $ok =$trans->pay($patron->{borrowernumber},$fee_amt, $pay_type, $fee_id);
+    $trans->ok($ok);
 
     return $trans;
 }
index 17d8f09..042f07e 100644 (file)
@@ -21,10 +21,11 @@ use strict;
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Koha::Account;
-use parent qw(C4::SIP::ILS::Transaction);
+use Koha::Account::Lines;
 
+use parent qw(C4::SIP::ILS::Transaction);
 
-our $debug   = 0;
+our $debug = 0;
 
 my %fields = ();
 
@@ -45,8 +46,26 @@ sub pay {
     my $borrowernumber = shift;
     my $amt            = shift;
     my $type           = shift;
+    my $fee_id         = shift;
+
     warn("RECORD:$borrowernumber::$amt");
-    Koha::Account->new( { patron_id => $borrowernumber } )->pay( { amount => $amt, sip => $type } );
+
+    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
+
+    if ($fee_id) {
+        my $fee = Koha::Account::Lines->find($fee_id);
+        if ( $fee && $fee->amountoutstanding == $amt ) {
+            $account->pay( { amount => $amt, sip => $type, lines => [$fee] } );
+            return 1;
+        }
+        else {
+            return 0;
+        }
+    }
+    else {
+        $account->pay( { amount => $amt, sip => $type } );
+        return 1;
+    }
 }
 
 #sub DESTROY {