-
Bug
-
Resolution: Fixed
-
Major
-
2.1, 2.4.7, 2.5.3, 2.6, 2.7
-
Any
-
MOODLE_21_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
-
MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
-
w50_
MDL-31410_m27_paypalipn -
Easy
-
-
3
-
BACKEND Sprint 7
The below issue includes the resolution. It merely needs to be marked as fixed and merged in to the main development branch.
The ipn.php script, that is a part of the Paypal enrolment method, makes calls to a function "message_send" that can cause the entire PayPal enrolment method to fail.
The ipn script is called by PayPal when a payment has been processed. Paypal calls the script and passes various tokens regarding the transaction. The ipn script:
1) Opens a handle for the paypal connection
2) Evaluates the received tokens and validates them
3) Enrols a student accordingly
4) Notifies the student, instructors & admins via a call to "message_send()"
5) Closes the connection from paypal
Various people have been reporting that their paypal enrolments work fine for a while, but they start getting these IPN failure warning messages from Paypal. In their IPN history in Paypal, they see a list of failed transactions where the server (moodle) response was a 404.
What's happening for these people, is the 4th step above is failing. The ipn script dies as a product of message_send() failing and the PHP server process would seem to time out and cause the web server to return a 404 to paypal. Since step 3 has been completed, end users of moodle are getting what they need from the plugin. However Paypal doesn't tolerate the 404 responses for long and automatically disables IPN messaging after a while - causing paypal enrolments to fail entirely.
The solution I'm proposing is really simple. I've modified ipn.php to use a wrapper function for message_send that puts the call in try-catch block. This insulates the execution of ipn.php from whatever message_send failures ruining the whole experience. I believe resolving the issue in message_send is another matter (and may merely be a misconfiguration thing - though myself and others do have systems that send us emails successfully, guess those situations aren't depending on the same function).
I've attached my modified version of ipn.php below. I hope it is immediately merged in to the main development branch as this is probably affecting even more people than have been complaining about it.
This issue has been observed by me personally across a wide range of 2.x Moodle installations. I've avoided fixing it myself and have just run on weekly builds hoping someone else would fix it. But push came to shove thus I fixed it myself.