[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/extras/ -> ipncheck.php (source)

   1  <?php
   2  /**

   3   * ipncheck.php diagnostic tool

   4   *

   5   * @package utility

   6   * @copyright Copyright 2007 Zen Cart Development Team

   7   * @copyright Portions Copyright 2003 osCommerce

   8   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   9   * @version $Id: ipncheck.php 6541 2007-07-01 19:43:02Z drbyte $

  10   */
  11  
  12  
  13  define('MODULE_PAYMENT_PAYPAL_HANDLER', 'www.paypal.com/cgi-bin/webscr');
  14  $_POST['ipn_mode'] = 'communication_test';
  15  //$_POST['test_ipn'] = 1;

  16  define('ENABLE_SSL','true');
  17  define('CURL_PROXY_REQUIRED', 'False');
  18  define('CURL_PROXY_SERVER_DETAILS', '');
  19  
  20  
  21  echo 'IPNCHECK.PHP - Version 1.0';
  22  echo '<br /><br />';
  23  
  24      $info = '';
  25      $header = '';
  26      $scheme = 'http://';
  27      if (ENABLE_SSL == 'true') $scheme = 'https://';
  28      //Parse url

  29      $web = parse_url($scheme . (defined('MODULE_PAYMENT_PAYPAL_HANDLER') ? MODULE_PAYMENT_PAYPAL_HANDLER : 'www.paypal.com/cgi-bin/webscr'));
  30      if (isset($_POST['test_ipn']) && $_POST['test_ipn'] == 1) {
  31        $web = parse_url($scheme . 'www.sandbox.paypal.com/cgi-bin/webscr');
  32      }
  33      //build post string

  34      $postdata = '';
  35      $postback = '';
  36      $postback_array = array();
  37      foreach($_POST as $key=>$value) {
  38        $postdata .= $key . "=" . urlencode(stripslashes($value)) . "&";
  39        $postback .= $key . "=" . urlencode(stripslashes($value)) . "&";
  40        $postback_array[$key] = $value;
  41      }
  42      $postback .= "cmd=_notify-validate";
  43      $postback_array['cmd'] = "_notify-validate";
  44  
  45      if ($postdata == '=&') {
  46        echo nl2br('IPN FATAL ERROR :: No POST data to process -- Bad IPN data');
  47        die('<br />aborted');
  48      }
  49      $postdata_array = $_POST;
  50      ksort($postdata_array);
  51  
  52      //echo nl2br('IPN INFO - POST VARS received (sorted): ' . "\n" . stripslashes(urldecode(print_r($postdata_array, true))));

  53      if (sizeof($postdata_array) == 0) die('Nothing to process. Please return to home page.');
  54  
  55        //Set the port number

  56        if($web['scheme'] == "https") {
  57          $web['port']="443";  $ssl = "ssl://";
  58        } else {
  59          $web['port']="80";   $ssl = "";
  60        }
  61        $proxy = $web;
  62        if (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '') {
  63          $proxy = parse_url($scheme . CURL_PROXY_SERVER_DETAILS);
  64        }
  65  
  66        //Post Data

  67        if (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '') {
  68          $header  = "POST " . $ssl . $web[host] . $web[path] . " HTTP/1.1\r\n";
  69          $header .= "Host: $proxy[host]\r\n";
  70        } else {
  71          $header  = "POST $web[path] HTTP/1.1\r\n";
  72          $header .= "Host: $web[host]\r\n";
  73        }
  74        $header .= "Content-type: application/x-www-form-urlencoded\r\n";
  75        $header .= "Content-length: " . strlen($postback) . "\r\n";
  76        $header .= "Connection: close\r\n\r\n";
  77  
  78        echo nl2br('IPN TESTING - POSTING to PayPal via: <strong>' . $ssl . $proxy['host'] . ':' . $proxy['port'] . "</strong>\n\n");
  79  
  80        //Create paypal connection

  81        $fp=fsockopen($ssl . $proxy['host'], $proxy['port'], $errnum, $errstr, 30);
  82  
  83        if(!$fp) {
  84          echo nl2br('IPN FATAL ERROR :: Could not establish fsockopen. ' . "\n" . 'Host Details = ' . $ssl . $proxy['host'] . ':' . $proxy['port'] . ' (' . $errnum . ') ' . $errstr . "\n" . (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '' ? "\n" . $ssl . $web[host] . $web[path] : '') . "\n Trying again without SSL ...\n\n");
  85          $fp=fsockopen($proxy['host'], 80, $errnum, $errstr, 30);
  86        }
  87        if(!$fp) {
  88          echo nl2br('IPN FATAL ERROR :: Could not establish fsockopen. ' . "\n" . 'Host Details = ' . $ssl . $proxy['host'] . ':' . $proxy['port'] . ' (' . $errnum . ') ' . $errstr . "\n" . (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '' ? "\n" . $ssl . $web[host] . $web[path] : ''));
  89       }
  90  
  91        fputs($fp, $header . $postback . "\r\n\r\n");
  92        $header_data = '';
  93        //loop through the response from the server

  94        while(!feof($fp)) {
  95          $line = @fgets($fp, 1024);
  96          if (strcmp($line, "\r\n") == 0) {
  97            // this is a header row

  98            $headerdone = true;
  99            $header_data .= $line;
 100          } else if ($headerdone) { 
 101            // header has been read. now read the contents

 102            $info[] = $line;
 103          }
 104        }
 105        //close fp - we are done with it

 106        fclose($fp);
 107        //break up results into a string

 108        $info = implode("", $info);
 109  
 110      $status = (strstr($info,'VERIFIED')) ? 'VERIFIED' : (strstr($info,'SUCCESS')) ? 'SUCCESS' : (strstr($info,'INVALID')) ? 'RESPONSE RECEIVED - Communications OKAY' : 'FAILED';
 111  
 112      echo nl2br('IPN TESTING - Confirmation/Validation response: <strong>' .$status . "</strong>\n<!--" . $info . '-->');
 113  
 114  echo "<br><br>Script finished.";
 115  
 116  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics