简体   繁体   English

贝宝支付网关集成

[英]paypal payment gateway integration

I am integrating paypal payment gateway in one of site.After successful payment i am redirecting it to success.php file. 我正在将paypal付款网关集成到一个site。支付成功后,我将其重定向到success.php文件。 In success.php file i have included all the insert parameters and a success message. success.php文件中,我包括了所有插入参数和一条成功消息。 It is redirecting to success.php file properly after making payment but showing payment failed message and no data is inserting to the database. 付款后,它将正确重定向到success.php文件,但显示付款失败消息,并且没有数据插入数据库。 following is my success.php page code 以下是我的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 } ?>

what i am doing wrong? 我做错了什么?

As suggested by Van Hoa, paypal does not send payment information as parameters when you redirect a user to your success page. 正如Van Hoa所建议的那样,当您将用户重定向到成功页面时,贝宝不会将付款信息作为参数发送。 PayPal will only send back a token and a payer ID. PayPal仅会发回令牌和付款人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; 当从Paypal.com将买家重定向回您的网站时,PayPal会将Express Checkout交易令牌和唯一的PayPal买家ID作为GET参数附加到您的RETURN URL; these GET parameters are named token and PayerID . 这些GET参数分别命名为tokenPayerID

PayPal docs (emphasis added) PayPal文档 (添加了重点)

You can use the returned token to get the payment details using GetExpressCheckoutDetails and passing it the token you get back from PayPal. 您可以使用返回的令牌通过GetExpressCheckoutDetails付款详细信息,并将您从PayPal取回的令牌传递给它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM