首页 > 解决方案 > PHP - 从贝宝返回商家时未获取交易信息

问题描述

我的页面上有一个贝宝按钮,我需要在其中接收付款。我从这里下载了代码 ,一切正常,我可以转到贝宝页面,我也可以汇款和收款(我使用的是沙盒帐户)。但是,当交易完成并单击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 但没有价值。我在这里想念什么。

标签: phppaypal

解决方案



我已经解决了这个问题,它只是一些需要在 Paypal 端完成的设置及其工作,请参阅此链接
1。我需要将网站支付的自动返回更改为 ON
2。在支付数据传输下,设置为 ON
并得到结果


推荐阅读