【发布时间】:2019-08-20 01:22:14
【问题描述】:
我的页面上有一个 paypal 按钮,我需要在其中接收付款。我从HERE 下载了代码,一切正常,我可以转到贝宝页面,我也可以汇款和收款(我使用的是沙盒帐户)。
然而,当交易完成并点击Return to merchant 它显示我Payment has failed。我有$_GET['variable'] 可以访问不同的交易信息。
这是我的“success.php”页面代码:
<?php
include_once("db_connect.php");
/*include './db_config.php';*/
//Store transaction information into database from PayPal
$item_number = $_GET['item_number'];
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];
echo $txn_id;
//Get product price to store into database
$sql = "SELECT * FROM products WHERE id = '$item_number'";
$resultset = mysqli_query($conn, $sql) or die("database error:".
mysqli_error($conn));
$row = mysqli_fetch_assoc($resultset);
if(!empty($txn_id) && $payment_gross == $row['price']){
//Insert tansaction data into the database
mysqli_query($conn, "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 = mysqli_insert_id($conn);
?>
<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
}
?>
如您所见,我尝试 ECHO txn_id 但没有价值。 我在这里错过了什么。
【问题讨论】:
-
使用
echo $_REQUEST查看 PayPal 向您的回调 URL 发送的值。这可以帮助您找到解决方案。 -
我放了它,只返回
Array没有其他值 -
抱歉,请使用
print_r而不是echo,请告诉我您收到的回复。