php - Paypal 支付网关集成

标签 php paypal

我正在将 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 } ?>

我做错了什么?

最佳答案

正如 Van Hoa 所建议的那样,当您将用户重定向到您的成功页面时,paypal 不会将付款信息作为参数发送。 PayPal 只会发回一个 token 和一个付款人 ID。

When redirecting the buyer back to your website from paypal.com, PayPal appends the Express Checkout transaction token and the unique PayPal buyer ID as GET parameters to your RETURN URL; these GET parameters are named token and PayerID.

PayPal docs (强调)

您可以使用返回的 token 通过 GetExpressCheckoutDetails 获取付款详细信息,并将您从 PayPal 取回的 token 传递给它。

关于php - Paypal 支付网关集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354527/

相关文章:

Paypal - 如何将定期付款与用户或交易联系起来?

php - SMTP 错误 : Failed to connect to server: Connection refused (111) with Office365

javascript - 在 PHP 中接收和发送回 json 数据

php - 基于php/mysql中的unix时间戳生成月度报告

php - 此交易无效。 Paypal PHP SDK

没有 PayPal 帐户的电子邮件的 PayPal 错误

php - Paypal REST API 不会在 Paypal 沙盒或实时网站上显示付款金额

magento - Magento 中的 PayPal 订单状态设置为 “Suspected Fraud”

php - 如何将条件附加到 Eloquent 关系查询中?

php - 检查Mysqli php列中是否存在值