贝宝PDT错误4003 [英] Paypal PDT error 4003

查看:132
本文介绍了贝宝PDT错误4003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过数小时的混乱并尝试设置一个相对简单的过程,即将付款发送到www.sandbox.paypal.com,然后重定向回我网站上的页面,在查询字符串中有交易ID ,我终于实现了.

我现在收到错误消息失败错误4003".

这是我正在使用的代码.这几乎与贝宝示例相同(我所做的只是回显响应):

    <?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留下的FAQ中.

检查脚本.在 沙盒,请确保您的PDT脚本将信息回传到 www.sandbox.paypal.com.如果要在Live PayPal网站上进行测试,请确保 脚本将数据回传到www.paypal.com.目前,所有样品 实时和沙盒网站上的代码指向"实时贝宝 网站.

希望它可以帮助其他人比我更快地启动并运行.现在,我要讨论的下一个问题是令牌被返回为空而不是错误.

After many hours of messing about and trying to set up what should be the relatively simple process of sending a payment to www.sandbox.paypal.com and being redirected back to a page on my site with a transaction id in the querystring, I have finally achieved it.

I am now receiving an error message 'FAIL Error 4003'.

Here is the code I am using. It is pretty much the same as the paypal example (all I have done is echo out the responses):

    <?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.

I have made sure to confirm the email addresses for both my sandbox merchant and buyer accounts and enabled PDT.

The client is redirected correctly back to my 'thank you' page with the following querystring paramaters - ?tx=4FU63684496248523&st=Pending&amt=29.90&cc=EUR&cm=&item_number=

Has anyone else encountered this error message? If so, what are the usual causes?

解决方案

The problem was that I was sending my test http request to paypal.com rather than sandbox.paypal.com. The answer was in the FAQ left by 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.

Hope it helps someone else get up and running quicker than I did. I am now onto my next issue which is the token being returned as empty rather than an error.. sigh..

这篇关于贝宝PDT错误4003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆