该表格工作正常,并从贝宝(Paypal)返回所有详细信息,但只有user_name我没有进入成功页面,我也想为该表格中的字段添加内容,但不返回,只有我正在获取item_name,item_number,金额和货币代码.so,请告诉我如何在success.php页面中获取user_name。
<form action="<?php echo $paypal_link; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="<?php echo $paypal_username; ?>">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="first_name" value="arif">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://localhost/PHP-PayPalDemo-master/paypal_cancel.php'>
<input type='hidden' name='return' value='http://localhost/PHP-PayPalDemo-master/paypal_success.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
答案 0 :(得分:0)
<?php
include 'connection.php';
print_r($_GET);
die();
//here i got that result only
//Array ( [amt] => 10.00 [cc] => USD [item_name] => Product1 [item_number] => 1 [st] => Completed [tx] => 23024871HW419281C )
//save Trasaction information form PayPal
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];
$item_number = $_GET['item_number'];
//Get product price
$productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
$productRow = $productResult->fetch_assoc();
$productPrice = $productRow['price'];
if(!empty($txn_id) && $payment_gross == $productPrice){
//Check if payment data exists with the same TXN ID.
$prevPaymentResult = $db->query("SELECT payment_id FROM payments WHERE txn_id = '".$txn_id."'");
if($prevPaymentResult->num_rows > 0){
$paymentRow = $prevPaymentResult->fetch_assoc();
$last_insert_id = $paymentRow['payment_id'];
}else{
//Insert tansaction data into the database
$insert = $db->query("INSERT INTO payments(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
$last_insert_id = $db->insert_id;
}
?>
<h1>Your payment has been successful.</h1>
<h1>Your Payment ID - <?php echo $last_insert_id; ?>.</h1>
<?php
}else{
?>
<h1>Your payment has failed.</h1>
<?php
}
?>
我的success.php页面