コード例 #1
0
 /**
  * Validate the PayPal IPN by posting back the data sent from PayPal.
  * 
  * Create a request that contains exactly the same IPN variables and values in the 
  * same order, preceded with cmd=_notify-validate.
  */
 public function validate($rawPost)
 {
     $isValid = false;
     Cart66Common::log("Validate PayPal Post Data: \n" . print_r($rawPost, true));
     // Looking for local test IPNs
     if (isset($rawPost['test_ipn']) && $rawPost['test_ipn'] == '66') {
         $isValid = true;
     } else {
         $postdata = '';
         foreach ($rawPost as $i => $v) {
             $postdata .= $i . '=' . urlencode(stripslashes($v)) . '&';
         }
         $postdata .= 'cmd=_notify-validate';
         Cart66Common::log("PayPal Validation Post Back: {$postdata}");
         $web = parse_url(Cart66Common::getPayPalUrl());
         if ($web['scheme'] == 'https') {
             $web['port'] = 443;
             $ssl = 'ssl://';
         } else {
             $web['port'] = 80;
             $ssl = '';
         }
         $fp = @fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
         if (!$fp) {
             $socketError = "Socket error --> " . $ssl . $web['host'] . ' -- ' . $web['port'] . ' -- ' . $errnum . ' -- ' . $errstr . ' -- 30';
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] PayPal IPN Validation Socket Error: {$socketError}");
             echo "IPN Socket Failure: {$socketError}";
         } else {
             fputs($fp, "POST " . $web['path'] . " HTTP/1.1\r\n");
             fputs($fp, "Host: " . $web['host'] . "\r\n");
             fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
             fputs($fp, "Content-length: " . strlen($postdata) . "\r\n");
             fputs($fp, "Connection: close\r\n\r\n");
             fputs($fp, $postdata . "\r\n\r\n");
             while (!feof($fp)) {
                 $info[] = @fgets($fp, 1024);
             }
             fclose($fp);
             $infoString = implode(',', $info);
             if (eregi('VERIFIED', $infoString)) {
                 // PayPal Verification Success'
                 $isValid = true;
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] PayPal IPN Validation succeeded: {$infoString}");
             } else {
                 // PayPal Verification Failed
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] PayPal Validation failed: {$infoString}");
             }
         }
     }
     return $isValid;
 }
コード例 #2
0
 public function __construct()
 {
     $paypalUrl = Cart66Common::getPayPalUrl();
     Cart66Common::log("Constructing PayPal Gateway for IPN using URL: {$paypalUrl}");
 }