php - PayPal IPN 无效进程

标签 php curl paypal

我使用 Oscommerce v2.3.3.4 并使用 PayPal Website Payments Standard 模块设置了一年多。它工作正常,直到上个月我收到了很多标题相同的电子邮件:PayPal IPN Invalid Process mentioned the standard_ipn.php failing。下面是代码:

> <?php /*   $Id$
> 
>   osCommerce, Open Source E-Commerce Solutions  
> http://www.oscommerce.com
> 
>   Copyright (c) 2010 osCommerce
> 
>   Released under the GNU General Public License
> */
> 
>   chdir('../../../../');   require('includes/application_top.php');
> 
>   if (!defined('MODULE_PAYMENT_PAYPAL_STANDARD_STATUS') ||
> (MODULE_PAYMENT_PAYPAL_STANDARD_STATUS  != 'True')) {
>     exit;   }
> 
>   $parameters = 'cmd=_notify-validate';
> 
>   reset($HTTP_POST_VARS);   while (list($key, $value) =
> each($HTTP_POST_VARS)) {
>     $parameters .= '&' . $key . '=' . urlencode(stripslashes($value));   }
> 
>   if (MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER == 'Live') {
>     $server = 'www.paypal.com';   } else {
>     $server = 'www.sandbox.paypal.com';   }
> 
>   $fsocket = false;   $curl = false;   $result = false;
> 
>   if ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://' . $server,
> 443, $errno, $errstr, 30)) ) {
>     $fsocket = true;   } elseif (function_exists('curl_exec')) {
>     $curl = true;   } elseif ($fp = @fsockopen($server, 80, $errno, $errstr, 30)) {
>     $fsocket = true;   }
> 
>   if ($fsocket == true) {
>     $header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n" .
>               'Host: ' . $server . "\r\n" .
>               'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
>               'Content-Length: ' . strlen($parameters) . "\r\n" .
>               'Connection: close' . "\r\n\r\n";
> 
>     @fputs($fp, $header . $parameters);
> 
>     $string = '';
>     while (!@feof($fp)) {
>       $res = @fgets($fp, 1024);
>       $string .= $res;
> 
>       if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
>         $result = $res;
> 
>         break;
>       }
>     }
> 
>     @fclose($fp);   } elseif ($curl == true) {
>     $ch = curl_init();
> 
>     curl_setopt($ch, CURLOPT_URL, 'https://' . $server . '/cgi-bin/webscr');
>     curl_setopt($ch, CURLOPT_POST, true);
>     curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
>     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>     curl_setopt($ch, CURLOPT_HEADER, false);
>     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
>     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
> 
>     $result = curl_exec($ch);
> 
>     curl_close($ch);   }
> 
>   if ($result == 'VERIFIED') {
>     if (isset($HTTP_POST_VARS['invoice']) && is_numeric($HTTP_POST_VARS['invoice']) && ($HTTP_POST_VARS['invoice']
> > 0)) {
>       $order_query = tep_db_query("select orders_status, currency, currency_value from " . TABLE_ORDERS . " where orders_id = '" .
> $HTTP_POST_VARS['invoice'] . "' and customers_id = '" .
> (int)$HTTP_POST_VARS['custom'] . "'");
>       if (tep_db_num_rows($order_query) > 0) {
>         $order = tep_db_fetch_array($order_query);
> 
>         if ($order['orders_status'] == MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID) {
>           $sql_data_array = array('orders_id' => $HTTP_POST_VARS['invoice'],
>                                   'orders_status_id' => MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID,
>                                   'date_added' => 'now()',
>                                   'customer_notified' => '0',
>                                   'comments' => '');
> 
>           tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
> 
> 
>           tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID :
> (int)DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where
> orders_id = '" . (int)$HTTP_POST_VARS['invoice'] . "'");
>         }
> 
>         $total_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" .
> $HTTP_POST_VARS['invoice'] . "' and class = 'ot_total' limit 1");
>         $total = tep_db_fetch_array($total_query);
> 
>         $comment_status = $HTTP_POST_VARS['payment_status'] . ' (' . ucfirst($HTTP_POST_VARS['payer_status']) . '; ' .
> $currencies->format($HTTP_POST_VARS['mc_gross'], false,
> $HTTP_POST_VARS['mc_currency']) . ')';
> 
>         if ($HTTP_POST_VARS['payment_status'] == 'Pending') {
>           $comment_status .= '; ' . $HTTP_POST_VARS['pending_reason'];
>         } elseif ( ($HTTP_POST_VARS['payment_status'] == 'Reversed') || ($HTTP_POST_VARS['payment_status'] == 'Refunded') ) {
>           $comment_status .= '; ' . $HTTP_POST_VARS['reason_code'];
>         }
> 
>         if ($HTTP_POST_VARS['mc_gross'] != number_format($total['value'] * $order['currency_value'],
> $currencies->get_decimal_places($order['currency']))) {
>           $comment_status .= '; PayPal transaction value (' . tep_output_string_protected($HTTP_POST_VARS['mc_gross']) . ') does not
> match order value (' . number_format($total['value'] *
> $order['currency_value'],
> $currencies->get_decimal_places($order['currency'])) . ')';
>         }
> 
>         $sql_data_array = array('orders_id' => $HTTP_POST_VARS['invoice'],
>                                 'orders_status_id' => (MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID > 0 ?
> (int)MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID :
> (int)DEFAULT_ORDERS_STATUS_ID),
>                                 'date_added' => 'now()',
>                                 'customer_notified' => '0',
>                                 'comments' => 'PayPal IPN Verified [' . $comment_status . ']');
> 
>         tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
>       }
>     }   } else {
>     if (tep_not_null(MODULE_PAYMENT_PAYPAL_STANDARD_DEBUG_EMAIL)) {
>       $email_body = '$HTTP_POST_VARS:' . "\n\n";
> 
>       reset($HTTP_POST_VARS);
>       while (list($key, $value) = each($HTTP_POST_VARS)) {
>         $email_body .= $key . '=' . $value . "\n";
>       }
> 
>       $email_body .= "\n" . '$HTTP_GET_VARS:' . "\n\n";
> 
>       reset($HTTP_GET_VARS);
>       while (list($key, $value) = each($HTTP_GET_VARS)) {
>         $email_body .= $key . '=' . $value . "\n";
>       }
> 
>       tep_mail('', MODULE_PAYMENT_PAYPAL_STANDARD_DEBUG_EMAIL, 'PayPal IPN Invalid Process', $email_body, STORE_OWNER,
> STORE_OWNER_EMAIL_ADDRESS);
>     }   }
> 
>   require('includes/application_bottom.php'); ?>

我已经通过 IPN 模拟器进行了测试,但没有发现任何错误,但仍然收到错误邮件。任何人请帮助。

最佳答案

寻找线

if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
  $result = $res;

  break;           
}

并将其替换为

if (strstr($res,'VERIFIED')) {
  $result = 'VERIFIED';

   break;
 }

关于php - PayPal IPN 无效进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21461728/

相关文章:

javascript - 使用 AJAX 从自定义页面上的按钮中删除所有购物车商品

PHP脚本求给定数字的平方根错误

php - 如何在 Zend\Db (Zend Framework 2) 中处理多对多关系

php - curl_exec() 将目标内容输出到页面?

curl - 400 错误。需要收件人地址。 curl

paypal - 您如何将 Paypal IPN 确认连接到用户?

php - 在 Php 中通过 ACH 进行 Paypal 定期付款

magento - 修改 Magento PayPal PayFlow Pro 响应消息

php - 从所有迁移文件 symfony 学说生成一个迁移?

php - 将 cookie 与 CURL 结合使用