php - Paypal PDT错误4003

标签 php paypal paypal-sandbox eclipse-pdt

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

我现在收到一条错误消息“FAIL Error 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&st=Pending&amt=29.90&cc=EUR&cm=&item_number=

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

最佳答案

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

Check the script.When testing Payment Data Transfer (PDT) in the Sandbox, make sure your PDT script POSTs back information to www.sandbox.paypal.com. If testing on the Live PayPal site, make sure the script POSTs data back to www.paypal.com. Currently, all sample code on the Live and Sandbox sites "point" back to the live PayPal site.

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

关于php - Paypal PDT错误4003,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8521800/

相关文章:

php - 将照片发布到 FB 导致需要上传文件错误

php - Cassandra 还是 mysql 5?哪个对 future 有好处?

php - 来自 MySQL 和 PHP 脚本的 Paypal 定期付款

php - 将自定义 php 网站与 paypal 集成?

android - PayPal for Android 添加产品

paypal - 无法登录到 Paypal 沙箱网站( Paypal hell )

php - 优化评级数组

php - 使用 hasMany 时 Laravel Nova 404

ssl - PayPal 网站支付专业版 TLS

ruby-on-rails - 具有 Paypal 权限和 Paypal Express Checkout 的 Rails