MDL-35092: Add proxy support to enrol/paypal IPN

This commit is contained in:
Tim Lock
2012-09-04 10:55:09 +08:00
committed by Aparup Banerjee
parent 519fb0b878
commit c3a0938e79
+11 -11
View File
@@ -34,6 +34,7 @@ require("../../config.php");
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 @@ if (! $plugin_instance = $DB->get_record("enrol", array("id"=>$data->instanceid,
$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 "<p>Error: could not access paypal.com</p>";
message_paypal_error_to_admin("Could not access paypal.com to verify payment", $data);
die;
@@ -104,12 +108,9 @@ if (!$fp) { /// Could not open a socket to PayPal - FAIL
/// 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 @@ while (!feof($fp)) {
}
}
fclose($fp);
exit;