贝宝未在贝宝成功页面中获取用户ID

时间:2020-10-18 20:07:13

标签: php paypal

我已将Paypal集成到我的自定义PHP中。一切进展顺利,并插入到数据库中,例如交易ID和金额等。但是我也想在数据库中插入UserID和付款日期。 问题是,用户ID在数据库中将为零。尝试了很多但无法解决问题。这是我的代码

此代码来自product_detail.php页面。

<form action="<?php echo PAYPAL_URL; ?>" method="post">
                                <!-- Identify your business so that you can collect the payments. -->
                                <input type="hidden" name="business" value="<?php echo PAYPAL_ID; ?>">
                                
                                <!-- Specify a Buy Now button. -->
                                <input type="hidden" name="cmd" value="_xclick">
                                
                                <!-- Specify details about the item that buyers will purchase. -->
                                <input type="hidden" name="item_name" value="<?php echo $sale_name; ?>">
                                <input type="hidden" name="buyerId" value="<?php echo $_SESSION['user'] ?>">
                                <input type="hidden" name="item_number" value="<?php echo $id; ?>">
                                <input type="hidden" name="amount" value="<?php echo $buy_price; ?>">
                                <input type="hidden" name="currency_code" value="<?php echo PAYPAL_CURRENCY; ?>">
                                
                                <!-- Specify URLs -->
                                <input type="hidden" name="return" value="<?php echo PAYPAL_RETURN_URL; ?>">
                                <input type="hidden" name="cancel_return" value="<?php echo PAYPAL_CANCEL_URL; ?>">
                                
                                <!-- Display the payment button. -->
                                <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif">
                            </form>

这是我的paypal_success.php页面代码

<?php include("include/config.php");?>
<?php 
global $con; 
// If transaction data is available in the URL 
if(!empty($_GET['item_number']) && !empty($_GET['tx']) && !empty($_GET['amt']) && !empty($_GET['cc']) && !empty($_GET['st'])){ 

    // Get transaction information from URL 
    $buyerId        = $_GET['buyerId']; 
    $item_number    = $_GET['item_number'];  
    $txn_id         = $_GET['tx'];
    $payment_date   = ('4243');     
    $payment_gross  = $_GET['amt']; 
    $currency_code  = $_GET['cc']; 
    $payment_status = $_GET['st']; 
     
    // Get product info from the database 
    $productResult  = $con->query("SELECT * FROM seller_listings WHERE id = ".$item_number); 
    $productRow     = $productResult->fetch_assoc(); 
     
    // Check if transaction data exists with the same TXN ID. 
    $prevPaymentResult = $con->query("SELECT * FROM payments WHERE txn_id = '".$txn_id."'"); 
 
    if($prevPaymentResult->num_rows > 0){ 
        $paymentRow = $prevPaymentResult->fetch_assoc(); 
        $payment_id = $paymentRow['payment_id']; 
        $payment_gross = $paymentRow['payment_gross']; 
        $payment_status = $paymentRow['payment_status']; 
    }else{ 
        // Insert tansaction data into the database 
        $insert = $con->query("INSERT INTO payments(item_number,user_id,txn_id,payment_date,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$buyerId."','".$txn_id."','".$payment_date."','".$payment_gross."','".$currency_code."','".$payment_status."')"); 
        $payment_id = $con->insert_id; 
    } 
} 
?>

1 个答案:

答案 0 :(得分:0)