From c3a0938e790eeb670f28ab20f87be400368ea5b4 Mon Sep 17 00:00:00 2001 From: Tim Lock Date: Tue, 28 Aug 2012 13:57:35 +0930 Subject: [PATCH] MDL-35092: Add proxy support to enrol/paypal IPN --- enrol/paypal/ipn.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index 2a28c245e9009..67fb06fa9973f 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -34,6 +34,7 @@ require_once("lib.php"); require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/enrollib.php'); +require_once($CFG->libdir . '/filelib.php'); /// Keep out casual intruders @@ -89,14 +90,17 @@ $plugin = enrol_get_plugin('paypal'); /// Open a connection back to PayPal to validate the data -$header = ''; -$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; -$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; -$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; +$c = new curl(); +$options = array( + 'returntransfer' => true, + 'httpheader' => array('application/x-www-form-urlencoded'), + 'timeout' => 30, +); $paypaladdr = empty($CFG->usepaypalsandbox) ? 'www.paypal.com' : 'www.sandbox.paypal.com'; -$fp = fsockopen ($paypaladdr, 80, $errno, $errstr, 30); +$location = "https://$paypaladdr/cgi-bin/webscr"; +$result = $c->post($location, $req, $options); -if (!$fp) { /// Could not open a socket to PayPal - FAIL +if (!$result) { /// Could not connect to PayPal - FAIL echo "

Error: could not access paypal.com

"; message_paypal_error_to_admin("Could not access paypal.com to verify payment", $data); die; @@ -104,12 +108,9 @@ /// Connection is OK, so now we post the data to validate it -fputs ($fp, $header.$req); - /// Now read the response and check if everything is OK. -while (!feof($fp)) { - $result = fgets($fp, 1024); +if (strlen($result) > 0) { if (strcmp($result, "VERIFIED") == 0) { // VALID PAYMENT! @@ -296,7 +297,6 @@ } } -fclose($fp); exit;