Bug 15907 - Remove use of makepayment in opac/opac-account-pay-paypal-return.pl
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 24 Feb 2016 15:56:52 +0000 (15:56 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 12 Jan 2017 13:42:47 +0000 (13:42 +0000)
Test Plan:
1) Apply this patch
2) Make a payment via PayPal in sandbox mode
3) Note the payment succeeds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Bug 15907 [QA Followup] - Simplify code and call pay() only once

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
opac/opac-account-pay-paypal-return.pl

index 77b50d8..eb870cc 100755 (executable)
@@ -93,11 +93,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";