2011-12-15 25 views
5

Sau nhiều giờ làm phiền và cố gắng thiết lập quy trình tương đối đơn giản để gửi thanh toán đến www.sandbox.paypal.com và được chuyển hướng trở lại trang trên trang web của tôi bằng giao dịch id trong chuỗi truy vấn, cuối cùng tôi đã đạt được nó.Lỗi PDT Paypal 4003

Tôi hiện đang nhận được thông báo lỗi 'FAIL Error 4003'.

Đây là mã tôi đang sử dụng. Đó là khá nhiều giống như ví dụ paypal (tất cả những gì đã làm được echo ra các câu trả lời):

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

Tôi đã thực hiện chắc chắn để xác nhận địa chỉ email cho cả hai tài khoản thương gia và người mua trong sandbox của tôi và kích hoạt PDT.

Các khách hàng được chuyển hướng một cách chính xác trở lại 'cảm ơn' trang của tôi với paramaters chuỗi truy vấn sau đây - ?tx=4FU63684496248523&st=Pending&amt=29.90&cc=EUR&cm=&item_number=

Đã có người khác gặp phải thông báo lỗi này? Nếu vậy, nguyên nhân thông thường là gì?

+0

Tôi thực sự gọi là paypal về lỗi đó và họ đã cho tôi một câu trả lời khó hiểu, nói rằng các lỗi xuất phát từ một số cấu hình sai trong giỏ hàng của tôi (Tôi đang sử dụng ubercart). Không hữu ích chút nào ... – Jukebox

+1

Đây là một Câu hỏi thường gặp khác để đưa vào danh sách kết hợp: https://ppmts.custhelp.com/app/answers/detail/a_id/13 – Jukebox

+1

Tôi đang sử dụng biểu mẫu đơn giản để gửi yêu cầu thanh toán đến paypal và am thực sự sử dụng mã riêng của họ để xử lý phản hồi. Tôi đã phát triển các trang web và ứng dụng trong một thời gian khá dài nhưng đã cố gắng tránh xa paypal trong hầu hết thời gian. Tôi kinh ngạc như thế nào xấu tài liệu của họ, thiết lập thử nghiệm và dịch vụ chung là. – TGuimond

Trả lời

6

Vấn đề là tôi đã gửi yêu cầu http thử nghiệm của tôi đến paypal.com chứ không phải là sandbox.paypal.com. Câu trả lời nằm trong câu hỏi thường gặp của Jukebox.

Kiểm tra script.When Chuyển thử nghiệm thanh toán dữ liệu (PDT) trong Sandbox, hãy chắc chắn bạn PDT kịch bản POSTS lại thông tin để www.sandbox.paypal.com. Nếu thử nghiệm trên trang web Live PayPal, hãy đảm bảo tập lệnh POSTs dữ liệu trở lại www.paypal.com. Hiện tại, tất cả các mẫu mã trên các trang web Live và Sandbox "điểm" trở lại trang web PayPal trực tiếp.

Hy vọng nó giúp người khác bắt đầu và chạy nhanh hơn tôi. Bây giờ tôi đang gặp vấn đề tiếp theo của mình, đó là mã thông báo được trả lại dưới dạng trống hơn là lỗi .. sigh ..

3

Đảm bảo ID giao dịch của bạn không hết hạn. 4003 Mã lỗi PDT cũng xuất hiện khi ID giao dịch của bạn hết hạn.

+0

Bạn có thêm thông tin nào về thời điểm ID giao dịch hết hạn không? Dễ dàng đại diện cho câu hỏi này nếu bạn có: http://stackoverflow.com/questions/23862124/paypal-pdt-transaction-id-expiration-period –

+0

bạn chắc chắn là như thế nào? AFAIK, id giao dịch PayPal không bao giờ hết hạn. – Vimalnath

1

Đây là những gì giải quyết nó cho tôi ...

Trong nút Mua ngay, tôi đã có một địa chỉ email công việc liên quan đến tài khoản PayPal WEBCAM tôi trong khi tôi cần phải sử dụng địa chỉ email công việc liên quan đến tài khoản PayPal Sandbox của tôi như trong:

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

thuộc tính giá trị cần thiết để phản ánh địa chỉ email công việc liên quan đến tài khoản sandbox của tôi.

Bằng cách này, đây là một phiên bản PHP cURL thay thế của kịch bản trên đã làm công tác trick của gợi ra những phản hồi từ sandbox của 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'])) 
0

The Identity Token of tài khoản thử nghiệm bán của tôi thay đổi mà không cần thông báo. Sử dụng Mã thông báo nhận dạng mới (chính xác) đã khắc phục được sự cố.

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

}