【问题标题】:Paypal PDT error 4003贝宝 PDT 错误 4003
【发布时间】:2012-01-21 05:59:48
【问题描述】:

经过数小时的折腾并尝试设置一个相对简单的流程,将付款发送到 www.sandbox.paypal.com 并被重定向回我网站上的一个页面,查询字符串中包含交易 ID ,我终于实现了。

我现在收到一条错误消息“FAIL 错误 4003”。

这是我正在使用的代码。它与 paypal 示例几乎相同(我所做的只是回应响应):

    <?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$auth_token = "ZdoN6q4GLiRniR2BbOzEEF22GJOWHpVOXRtP7fAhBpvwwm5GyWcTzO_sSSO";
$req .= "&tx=$tx_token&at=$auth_token";

// post back to PayPal system to validate
$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";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) 
{
    // HTTP ERROR
    echo "HTTP Error";
} 
else 
{
    fputs ($fp, $header . $req);
    // read the body data 
    $res = '';
    $headerdone = false;
    while (!feof($fp)) 
    {
        $line = fgets ($fp, 1024);
        if (strcmp($line, "\r\n") == 0) {
            // read the header
            $headerdone = true;
        }
        else if ($headerdone)
        {
            // header has been read. now read the contents
            $res .= $line;
            echo $line;
        }
    }

        // parse the data
        $lines = explode("\n", $res);
        $keyarray = array();
        if (strcmp ($lines[0], "SUCCESS") == 0) 
        {
            for ($i=1; $i<count($lines);$i++)
            {
                list($key,$val) = explode("=", $lines[$i]);
                $keyarray[urldecode($key)] = urldecode($val);
            }
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment
            $firstname = $keyarray['first_name'];
            $lastname = $keyarray['last_name'];
            $itemname = $keyarray['item_name'];
            $amount = $keyarray['payment_gross'];

            echo ("<p><h3>Thank you for your purchase!</h3></p>");
            echo ("<b>Payment Details</b><br>\n");
            echo ("<li>Name: $firstname $lastname</li>\n");
            echo ("<li>Item: $itemname</li>\n");
            echo ("<li>Amount: $amount</li>\n");
            echo ("");
        }
        else if (strcmp ($lines[0], "FAIL") == 0) {
            echo "Failure: " . $lines[0];
            // log for manual investigation
        }

}

fclose ($fp);

?>
<br />
Thank you for your payment. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at <a href="http://www.sandbox.paypal.com/ie">www.sandbox.paypal.com/ie</a> to view details of this transaction.

我已确保确认我的沙盒商家和买家帐户的电子邮件地址并启用了 PDT。

客户端使用以下查询字符串参数正确重定向回我的“谢谢”页面 - ?tx=4FU63684496248523&amp;st=Pending&amp;amt=29.90&amp;cc=EUR&amp;cm=&amp;item_number=

有没有其他人遇到过这个错误信息?如果有,通常是什么原因?

【问题讨论】:

  • 我实际上打电话给 paypal 关于这个错误,他们给了我一个神秘的答案,说这个错误来自我的购物车中的一些错误配置(我正在使用 ubercart)。一点帮助都没有……
  • 这是另一个常见问题解答:ppmts.custhelp.com/app/answers/detail/a_id/13
  • 我正在使用一个简单的表单向贝宝提交付款请求,实际上我正在使用他们自己的代码来处理响应。我已经开发网站和应用程序很长时间了,但大部分时间都设法避开了贝宝。我很惊讶他们的文档、测试设置和一般服务有多糟糕。

标签: php paypal paypal-sandbox eclipse-pdt


【解决方案1】:

问题是我将测试 http 请求发送到 paypal.com 而不是 sandbox.paypal.com。答案在 Jukebox 留下的常见问题解答中。

检查脚本。在测试支付数据传输 (PDT) 时 沙箱,确保您的 PDT 脚本将信息回传到 www.sandbox.paypal.com。如果在 Live PayPal 网站上进行测试,请确保 该脚本将数据发布回 www.paypal.com。目前,所有样品 Live 和 Sandbox 网站上的代码“指向”实时 PayPal 网站。

希望它可以帮助其他人比我更快地启动和运行。我现在正在处理我的下一个问题,即令牌返回为空而不是错误.. 叹息..

【讨论】:

    【解决方案2】:

    确保您的交易 ID 未过期。当您的交易 ID 过期时,也会出现 4003 PDT 错误代码。

    【讨论】:

    • 您有更多关于交易 ID 何时到期的信息吗?如果你有这个问题也很容易代表:stackoverflow.com/questions/23862124/…
    • 你有多确定? AFAIK,PayPal 交易 ID 永不过期。
    【解决方案3】:

    这就是为我解决它的方法......

    在“立即购买”按钮中,我有一个与我的 LIVE PayPal 帐户关联的企业电子邮件地址,而我需要使用与我的 SANDBOX PayPal 帐户关联的企业电子邮件地址,如下所示:

    <input type="hidden" name="business" value="user@host.com">
    

    反映与我的沙盒帐户关联的企业电子邮件地址所需的值属性。

    顺便说一句,这是上述脚本的另一个 PHP cURL 版本,它也可以从 PayPal 的沙箱中获取响应:

    if (isset($_GET['tx'])) {
    
    $tx = $_GET['tx'];
    $identity_token = "INSERT_YOUR_IDENTITY_TOKEN_HERE";
    
    //echo $tx;
    
    $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    
    $nvpString="cmd=_notify-synch".
               "&tx=$tx".
               "&at=$identity_token";
    
    //echo $nvpString;
    
    //define where the data is going to
    $curl = curl_init($url);
    //tell cURL to fail if an error occurs
    curl_setopt($curl, CURLOPT_FAILONERROR, 1); 
    //allow for redirects
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    //assign the returned data to a variable
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //set the timeout
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    //use POST
    curl_setopt($curl, CURLOPT_POST, 1);
    //set the POST data
    curl_setopt($curl, CURLOPT_POSTFIELDS, $nvpString);
    //execute the transaction
    $response = curl_exec($curl);
    //show errors
    curl_error($curl);
    //close the connection
    curl_close($curl);
    
    echo '<pre>';
    print_r($response);
    echo '</pre>';
    
    }//end if (isset($_GET['tx']))
    

    【讨论】:

      【解决方案4】:

      我的测试卖家账户的身份令牌已更改,恕不另行通知。使用新的(正确的)身份令牌解决了这个问题。

      【讨论】:

        【解决方案5】:

        有关 Paypal 的 PTD 的更多信息可在此处找到: http://www.secure-ebook.com/help/payment:paypal:fail_4003

        【讨论】:

          【解决方案6】:
          $tx=$_REQUEST['tx'];
          
          $paypal_url='https://www.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx='.$tx.'&at=token here';
          
          $curl = curl_init($paypal_url);
          
          $data = array(
          
          "cmd" => "_notify-synch",
          
          "tx" => $tx,
          
          "at" => "token here"
          
          
          );                                                                    
          
          $data_string = json_encode($data); 
          
          curl_setopt ($curl, CURLOPT_HEADER, 0);
          
          curl_setopt ($curl, CURLOPT_POST, 1);
          
          curl_setopt ($curl, CURLOPT_POSTFIELDS, $data_string);
          
          curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
          
          curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
          
          curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
          
          $headers = array (
          
          'Content-Type: application/x-www-form-urlencoded',
          
          'Host: www.paypal.com',
          
          'Connection: close'
          
          );
          
          curl_setopt ($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
          
          curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers);
          
          $response = curl_exec($curl);
          
          $lines = explode("\n", $response);
          
          $keyarray = array();
          
          if (strcmp ($lines[0], "SUCCESS") == 0) {
          
          for ($i=1; $i<count($lines);$i++){
          
          list($key,$val) = explode("=", $lines[$i]);
          
          $keyarray[urldecode($key)] = urldecode($val);
          
          }
          
          
          $first_name=$keyarray['first_name'];
          
          $last_name=$keyarray['last_name'];
          
          $payment_status=$keyarray['payment_status'];
          
          $business=$keyarray['business'];
          
          $payer_email=$keyarray['payer_email'];
          
          $payment_gross=$keyarray['payment_gross'];
          
          $mc_currency=$keyarray['mc_currency']; 
          
          }
          

          【讨论】:

            猜你喜欢
            • 2018-03-18
            • 2016-04-07
            • 2021-02-12
            • 2011-01-26
            • 2016-04-12
            • 2018-12-21
            • 2012-05-16
            • 2016-06-05
            • 2015-04-30
            相关资源
            最近更新 更多