2011-12-15 69 views
5

經過了數小時的搞亂並試圖設置什麼應該是相對簡單的過程,將支付發送到www.sandbox.paypal.com,並通過交易重定向回我網站的頁面id在查詢字符串中,我終於實現了。貝寶PDT錯誤4003

我現在收到一條錯誤消息'FAIL Error 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。

客戶端與下面的查詢字符串PARAMATERS重定向正確地回到我的「謝謝」網頁 - ?tx=4FU63684496248523&st=Pending&amt=29.90&cc=EUR&cm=&item_number=

有沒有其他人遇到這個問題?如果是這樣,通常的原因是什麼?

+0

我居然要求有關錯誤貝寶,他們給了我一個神祕的答案,他說,錯誤來自一些錯誤配置在我的購物車(我正在使用ubercart)。根本沒有什麼幫助...... – Jukebox 2011-12-15 18:51:13

+1

這是另一個常見問題:https://ppmts.custhelp.com/app/answers/detail/a_id/13 – Jukebox 2011-12-15 19:10:44

回答

6

問題是我正在將我的測試http請求發送到paypal.com而不是sandbox.paypal.com。答案在Jukebox留下的FAQ中。

檢查在 Sandbox中script.When測試付款數據傳輸(PDT),請確保您的PDT腳本回發信息給 www.sandbox.paypal.com。如果在Live PayPal網站上進行測試,請確保 腳本將數據發送回www.paypal.com。目前,Live和沙盒網站上的所有樣本 「點」都返回到現場PayPal 網站。

希望它能幫助別人比我更快起牀和跑步。我現在到我的下一個問題,這是令牌被返回爲空而不是錯誤..嘆息..

3

請確保您的交易ID沒有過期。當您的交易ID過期時,還會出現4003 PDT錯誤代碼。

1

這裏就是解決了這個問題對我來說...

在立即購買按鈕,我與我的LIVE的PayPal賬戶相關聯的企業電子郵件地址,而我需要用我的SANDBOX PayPal帳戶相關聯的企業電子郵件地址如:

<input type="hidden" name="business" value="[email protected]"> 

value屬性需要反映與我的沙箱帳戶關聯的企業電子郵件地址。

順便說一句,這裏是上面的腳本也不會引發來自PayPal的沙箱中的響應的伎倆的替代PHP捲曲版本:

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'])) 
0

我的測試賣家帳戶的身份標記改變,恕不另行通知。使用新的(正確的)身份令牌解決了問題。

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

}