我正在将paypal支付网关整合到一个网站中。成功付款后,我将其重定向到success.php
文件。在success.php
文件中,我已包含所有插入参数和成功消息。它在付款后正确地重定向到success.php
文件,但显示付款失败消息,并且没有数据插入数据库。以下是我的success.php
网页代码
<?php
include 'dbConfig.php';
//Get payment information from PayPal
$item_number = $_GET['item_number'];
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];
//Get product price from database
$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 } ?>
我做错了什么?
答案 0 :(得分:0)
正如Van Hoa所建议的,当您将用户重定向到成功页面时,paypal不会将付款信息作为参数发送。 PayPal只会发回令牌和付款人ID。
将买家从paypal.com重定向回您的网站时, PayPal会附加Express Checkout交易令牌和唯一身份 PayPal买家ID作为您的RETURN URL的GET参数; 这些GET参数名为令牌和 PayerID 。
PayPal docs(强调补充)
您可以使用返回的令牌使用GetExpressCheckoutDetails
获取付款详细信息,并将您从PayPal返回的令牌传递给它。