Skip to content

Commit

Permalink
MDL-35092: Add proxy support to enrol/paypal IPN
Browse files Browse the repository at this point in the history
  • Loading branch information
tlock authored and Aparup Banerjee committed Sep 4, 2012
1 parent 519fb0b commit c3a0938
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions enrol/paypal/ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,27 +90,27 @@
$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;
}

/// 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!


Expand Down Expand Up @@ -296,7 +297,6 @@
}
}

fclose($fp);
exit;


Expand Down

0 comments on commit c3a0938

Please sign in to comment.