简体   繁体   English

Paypal PDT错误4003

[英]Paypal PDT error 4003

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. 经过几个小时的混乱并试图建立一个相对简单的向www.sandbox.paypal.com发送付款的过程,并被重定向回到我的网站上的一个页面,在查询字符串中有一个事务ID,我有终于实现了它。

I am now receiving an error message 'FAIL Error 4003'. 我现在收到错误消息'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): 它与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.

I have made sure to confirm the email addresses for both my sandbox merchant and buyer accounts and enabled PDT. 我已确保确认我的沙箱商家和买家帐户的电子邮件地址并启用了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= 使用以下查询字符串参数将客户端正确地重定向回我的“谢谢”页面 - ?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. 问题是我将测试http请求发送到paypal.com而不是sandbox.paypal.com。 The answer was in the FAQ left by Jukebox. 答案在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. 检查脚本。在Sandbox中测试付款数据传输(PDT)时,请确保您的PDT脚本将信息发送回www.sandbox.paypal.com。 If testing on the Live PayPal site, make sure the script POSTs data back to www.paypal.com. 如果在Live PayPal站点上进行测试,请确保脚本将数据POST回www.paypal.com。 Currently, all sample code on the Live and Sandbox sites "point" back to the live PayPal site. 目前,Live和Sandbox网站上的所有示例代码都“指向”现场PayPal网站。

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.. 我现在正处理我的下一个问题,即令牌被返回为空而不是错误..叹息..

Make sure your transaction ID is not expired. 确保您的交易ID未过期。 4003 PDT error code also comes when your transaction ID is expired. 当您的交易ID过期时,也会出现4003 PDT错误代码。

Here's what solved it for me... 这就是为我解决的问题......

In the Buy Now button, I had a business email address associated with my LIVE PayPal account whereas I need to use the business email address associated with my SANDBOX PayPal account as in: 在“立即购买”按钮中,我有一个与我的LIVE PayPal帐户关联的企业电子邮件地址,而我需要使用与我的SANDBOX PayPal帐户关联的企业电子邮件地址,如下所示:

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

The value attribute needed to reflect the business email address associated with my sandbox account. 值属性需要反映与我的沙箱帐户关联的公司电子邮件地址。

By the way, here's an alternate PHP cURL version of the above script that also does the trick of eliciting a response from PayPal's sandbox: 顺便说一句,这是上面脚本的备用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']))

The Identity Token of my test seller account changed without notification. 我的测试卖家帐户的标识令牌已更改,但未通知。 Using the new (correct) Identity Token fixed the problem. 使用新的(正确的)身份令牌修复了问题。

$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']; 

}

有关Paypal PTD的更多信息,请访问: http//www.secure-ebook.com/help/payment :paypal: fail_4003

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM