我已将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;
}
}
?>
答案 0 :(得分:0)
buyerId不是HTML Payments Standard variable,请尝试custom
您使用的集成不是一个,也不是两个,而是过了三代;基本上是20岁你为什么要用这个?而是使用v2 REST API和JavaScript SDK批准流程。这是批准的前端:https://developer.paypal.com/demo/checkout/#/pattern/server 您需要在服务器上使用两条相应的路由来调用v2 / checkout / orders API,一条用于“设置交易”,一条用于“捕获交易”,documented here。