ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / opac / opac-account-pay-paypal-return.pl
index 742f5ae..76f6d21 100755 (executable)
@@ -17,8 +17,7 @@
 # with Koha; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-use strict;
-use warnings;
+use Modern::Perl;
 use utf8;
 
 use CGI;
@@ -29,9 +28,9 @@ use URI;
 use C4::Auth;
 use C4::Output;
 use C4::Accounts;
-use C4::Members;
 use Koha::Acquisition::Currencies;
 use Koha::Database;
+use Koha::Patrons;
 
 my $cgi = new CGI;
 
@@ -93,11 +92,20 @@ if ( $response->is_success ) {
     if ( $params{ACK} eq "Success" ) {
         $amount = $params{PAYMENTINFO_0_AMT};
 
-        my $accountlines_rs = Koha::Database->new()->schema()->resultset('Accountline');
-        foreach my $accountlines_id ( @accountlines ) {
-            my $accountline = $accountlines_rs->find( $accountlines_id );
-            makepayment( $accountlines_id, $borrowernumber, undef, $accountline->amountoutstanding, undef, undef, 'PayPal' );
-        }
+        my $account = Koha::Account->new( { patron_id => $borrowernumber } );
+        my @lines = Koha::Account::Lines->search(
+            {
+                accountlines_id => { -in => \@accountlines }
+            }
+        );
+
+        $account->pay(
+            {
+                amount => $amount,
+                lines  => \@lines,
+                note   => 'PayPal'
+            }
+        );
     }
     else {
        $error = "PAYPAL_ERROR_PROCESSING";
@@ -108,8 +116,9 @@ else {
     $error = "PAYPAL_UNABLE_TO_CONNECT";
 }
 
+my $patron = Koha::Patrons->find( $borrowernumber );
 $template->param(
-    borrower    => GetMemberDetails($borrowernumber),
+    borrower    => $patron->unblessed,
     accountview => 1
 );