From c673cdfee72c8548ed465aa6b0b4415160a2ce59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 1 Dec 2013 19:27:29 +0800 Subject: [PATCH] MDL-31410 always send 200 in PayPal IPN response and hide all errors --- enrol/paypal/ipn.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index 32c67ca0409..58b78939f24 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -28,6 +28,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +// Disable moodle specific debug messages and any errors in output, +// comment out when debugging or better look into error log! +define('NO_DEBUG_DISPLAY', true); require("../../config.php"); require_once("lib.php"); @@ -35,6 +38,9 @@ require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/enrollib.php'); require_once($CFG->libdir . '/filelib.php'); +// PayPal does not like when we return error messages here, +// the custom handler just logs exceptions and stops. +set_exception_handler('enrol_paypal_ipn_exception_handler'); /// Keep out casual intruders if (empty($_POST) or !empty($_GET)) { @@ -330,4 +336,20 @@ function message_paypal_error_to_admin($subject, $data) { message_send($eventdata); } +/** + * Silent exception handler. + * + * @param Exception $ex + * @return void - does not return. Terminates execution! + */ +function enrol_paypal_ipn_exception_handler($ex) { + $info = get_exception_info($ex); + $logerrmsg = "enrol_paypal IPN exception handler: ".$info->message; + if (debugging('', DEBUG_NORMAL)) { + $logerrmsg .= ' Debug: '.$info->debuginfo."\n".format_backtrace($info->backtrace, true); + } + error_log($logerrmsg); + + exit(0); +}