2014-08-28 140 views
0

我使用以下代码将PayPal支付系统集成到我的网站,付款后,即使一切顺利,我也收到以下通知和“付款失败”。PayPal付款请求通知:未定义索引

Notice: Undefined index: item_name in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 2 

Notice: Undefined index: tx in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 3 

Notice: Undefined index: amount in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 4 

Notice: Undefined index: currency_code in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 5 

Payment Failed 

我使用下面的代码来创建付款按钮

<div class="btn"> 
<form action="<?php echo $paypal_url ?>" method="post" name="frmPayPal1"> 
<input type="hidden" name="business" value="<?php echo $paypal_id ?>"> 
<input type="hidden" name="cmd" value="_xclick"> 
<input type="hidden" name="item_name" value="20Percents (12 Credits)"> 
<input type="hidden" name="item_number" value="1"> 
<input type="hidden" name="credits" value="12"> 
<input type="hidden" name="userid" value="1"> 
<input type="hidden" name="amount" value="10"> 
<input type="hidden" name="cpp_header_image" value="http://20percents.com/wp-content/uploads/2014/06/logo-1.png"> 
<input type="hidden" name="no_shipping" value="1"> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="handling" value="0"> 
<input type="hidden" name="cancel_return" value="http://localhost/payment/cancel.php"> 
<input type="hidden" name="return" value="http://localhost/payment/success.php"> 
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> 
</form> 

而且,下面的代码来验证支付:

<?php 
$item_name   = $_GET['item_name']; // I also tried $_REQUEST['item_name']; instead 
$item_transaction = $_GET['tx']; // Paypal transaction ID 
$item_price   = $_GET['amount']; // Paypal received amount 
$item_currency  = $_GET['currency_code']; // Paypal received currency type 

$price = '10.00'; 
$currency='USD'; 

//Rechecking the product price and currency details 
if($item_price==$price && $item_currency==$currency) 
{ 
    $content = "<h1>Welcome, Guest</h1>"; 
    $content .= "<h1>Payment Successful</h1>"; 
} 
else 
{ 
    $content = "<h1>Payment Failed</h1>"; 
} 
?> 

我不知道为什么我收到这些通知,任何帮助,高度赞赏。谢谢

回答

1

你在表格中给出的方法是POST。但使用$_GET[]获取值。 变化形式

<form action="<?php echo $paypal_url ?>" method="get" name="frmPayPal1"> 

或更改

$item_name = $_GET['item_name']; 

$item_name = $_POST['item_name']; 
+0

不,不工作。仍然是同样的问题。 – lock 2014-08-28 05:52:33

+0

你改变了什么? – arunrc 2014-08-28 05:55:18

+0

尝试了两种方法,尝试更改方法来使用get函数,没有工作,并尝试post方法,并试图使用$ _post ['item_name'],这也没有工作。同样的问题 – lock 2014-08-28 05:59:26

1

按照以下步骤设置你的账户PDT:

登录到您的PayPal帐户。 单击配置文件子选项卡。 单击卖家首选项列中的网站付款首选项。 在网站付款自动退回下,点击开单选按钮。 对于返回网址,请输入您的网站上的网址,该网址将在客户付款后收到PayPal发布的交易ID。 在支付数据传输下,单击On单选按钮。 单击保存。 单击卖家首选项列中的网站付款首选项。 滚动到页面的“付款数据传输”部分查看您的PDT身份标记。