PayPal Express recurring notifications don't work for test transaction
I set up a PayPal Express payment processor and a contribution page to take donations, both recurring and one-off. When taking one-off donations, everything worked as expected. However, for recurring donations, the initial contribution remained pending and PayPal IPN reported a 500 error.
I managed to track down the issue to the handlePaymentExpress() method in the CRM/Core/Payment/PayPalProIPN.php file.
At around line 578, it does this:
$result = civicrm_api3('contribution', 'getsingle', array('invoice_id' => $input['invoice']));
Unfortunately, this only works for live contributions. I fixed this by changing where it retrieves the recurring contribution from
$contributionRecur = civicrm_api3('contribution_recur', 'getsingle', array( 'return' => 'contact_id, id', 'invoice_id' => $input['invoice'], ));
to
$contributionRecur = civicrm_api3('contribution_recur', 'getsingle', array( 'return' => 'contact_id, id, is_test, payment_processor_id', 'invoice_id' => $input['invoice'], ));
and changed line 578 to
$result = civicrm_api3('contribution', 'getsingle', array('invoice_id' => $input['invoice'], 'contribution_test' => $contributionRecur['is_test']));
However, the contribution still remained pending. The other error was a few lines further down:
$paymentProcessorID = self::getPayPalPaymentProcessorID();
This returned the wrong processor id, so I changed it to do this
$paymentProcessorID = $contributionRecur['payment_processor_id'];
I have no idea if these changes will break anything else, but they seem to work for me
Regards,
Carl