2011-07-21 141 views
3

我有以下按鈕後,我使用了支付寶交易:貝寶沙盒支付問題

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
     <input type="hidden" name="cmd" value="_xclick"> 
     <input type="hidden" name="business" value="[email protected]"> 
     <input type="hidden" name="item_name" value="Item description"> 
     <input type="hidden" name="item_number" value="1"> 
     <input type="hidden" name="amount" value="00.30"> 
     <input type="hidden" name="no_shipping" value="1"> 
     <input type="hidden" name="no_note" value="1"> 
     <input type="hidden" name="currency_code" value="USD"> 
     <input type="hidden" name="lc" value="US"> 
     <input type="hidden" name="bn" value="PP-BuyNowBF"> 
     <input type="hidden" name="return" value="website.com/index.php" /> 
     <input type="hidden" name="cancel_return" value="website.com/index.php" /> 
     <input type="hidden" name="rm" value="2"> 
     <input type="hidden" name="notify_url" value="website.com/ipn/ipn.php"> 
     <input type="hidden" name="custom" value="user_id"> 
     <input type="submit" value="upgrade" /> 
    </form> 

和ipn.php

<?php 
include_once 'config.php'; 
// read the post from PayPal system and add 'cmd' 
$req = 'cmd=_notify-validate'; 

foreach ($_POST as $key => $value) { 
$value = urlencode(stripslashes($value)); 
$req .= "&$key=$value"; 
} 

// 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 
// assign posted variables to local variables 
$item_name = $_POST['item_name']; 
$item_number = $_POST['item_number']; 
$payment_status = $_POST['payment_status']; 
$payment_amount = $_POST['mc_gross']; 
$payment_currency = $_POST['mc_currency']; 
$txn_id = $_POST['txn_id']; 
$receiver_email = $_POST['receiver_email']; 
$payer_email = $_POST['payer_email']; 

if (!$fp) { 
// HTTP ERROR 
} else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
     $res = fgets ($fp, 1024); 
     if (strcmp ($res, "VERIFIED") == 0) { 
      // 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 
      mysql_query("UPDATE table SET column='1' WHERE column2='13'"); 
     } 
     else if (strcmp ($res, "INVALID") == 0) { 
      // log for manual investigation 
     } 
    } 
fclose ($fp); 
} 
?> 

下面的代碼當我點擊升級按鈕,並支付,它沒有顯示我返回到網站按鈕...但有一個回到[email protected]按鈕,它有10秒的延遲,並帶我回到我的網站...雖然它彈出警告關於加密數據,我不知道它是什麼。

而且我在ipn.php使用查詢不execute.I甚至不知道,如果去ipn.php。

回答

0

關於回去「[email protected]」,這可能如果您指定的電子郵件不會映射到貝寶沙箱帳戶發生。也許你在按鈕中使用真實的電子郵件而不是沙箱帳戶電子郵件?

另一種可能性是,在「[email protected]」你的測試帳戶不是企業帳戶。如果你有一個商業賬戶,它應該反映你的公司名稱。

至於不能接受的IPN,沙盒並不總是準時,互穿網絡交付,如果在所有做大量的工作。我實際上建議您嘗試使用Express Checkout而不是網站付款標準進行集成。 Express Checkout最初有點混亂,但在嘗試瞭解之後很容易實現。這就是我認爲是最好的文檔說明快速結賬是如何工作的:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECSimpleIntegration

當你準備潛入實現你應該看看這裏:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference

的好處關於使用Express Checkout而不是依靠IPN的一點是,當用戶返回您的網站時,您可以計算出付款狀態,而且您不必等待IPN出現。

有了快速結賬,你還可以得到一個定製的「名牌」來覆蓋你的業務名稱,以便您可以用不同的「品牌」在不同的網站上使用相同的接收PayPal帳戶。

祝你好運!

+0

其實我使用非沙箱帳戶[email protected],然後我改成了我的沙箱企業電子郵件和創建新的個人作爲一個買方...然後我進入了我的買家的登錄信息,以購買物品,仍然沒有執行ipn.php頁面,它似乎沒有去那裏... 此刻我想堅持IPN,因爲它看起來很簡單。 謝謝 – fxuser

+0

我明白了。如果你想堅持使用IPN,那麼你應該在https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session上看看他們的IPN測試人員 - 如果這樣做,那麼你可以排除你的ipn.php作爲問題的根源,但如果它不起作用,那麼不幸的是,你不會知道問題是否與貝寶不發送IPN – nioq

+0

我選擇快速結帳,我不知道這是我必須選擇正確的項目,但它傳遞了消息:「IPN已成功發送。」 – fxuser