收不到 PayPal IPN 回调
Posted
技术标签:
【中文标题】收不到 PayPal IPN 回调【英文标题】:Not receiving PayPal IPN callback 【发布时间】:2017-12-15 02:55:24 【问题描述】:这是我的付款表单和成功页面,用于获取付款并将付款数据存储到我的数据库中。 付款表格工作正常,但success.php 页面未从贝宝获取任何数据。我已经在 paypal 帐户中添加了 IPN 和自动返回 url,但它不起作用。请有人帮助我。
<?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 ?>
为获得付款而唱歌并且工作正常,但我没有收到 IPN 消息和我的数据库中的任何数据?
<!-- begin snippet: js hide: false console: true babel: false -->
<?php
//Include db configuration file
include 'dbConfig.php';
//Set useful variables for paypal form
$paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
$paypalID = 'mybusiness@demo.com'; //Business Email
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PayPal Standard Payment Gateway Integration by CodexWorld</title>
</head>
<body>
<?php
//Fetch products from the database
$results = $db->query("SELECT * FROM products");
while($row = $results->fetch_assoc())
?>
<img src="images/<?php echo $row['image']; ?>"/>
<br/>Name: <?php echo $row['name']; ?>
<br/>Price: <?php echo $row['price']; ?>
<form action="<?php echo $paypalURL; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="<?php echo $paypalID; ?>">
<!-- 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 $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='https://example.com/paypal_integration_php/cancel.php'>
<input type='hidden' name='return' value='https://example.com/paypal_integration_php/success.php'>
<input type='hidden' name='notify_url' value='https://example.com/paypal_integration_php/ipn.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" >
<img border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<?php ?>
</body>
</html>
【问题讨论】:
【参考方案1】:Brother 使用$_REQUEST
方法而不是$_GET
方法来获取您的交易详情。希望对你有帮助
【讨论】:
数据可以来自$_GET
或$_POST
,使用$_REQUEST
表示你不确定它来自哪里。
是的,你是对的@MatteoTassinari,但我几天前尝试了相同的代码,我遇到了同样的问题,但是当我将 $_request 放在 $_GEt 的位置时,它会正常工作。这就是我给出这个答案的原因。希望它能帮助他摆脱困境。
如果你从$_REQUEST
而不是$_GET
获取数据,那么数据可能在$_POST
。
感谢@MatteoTassinari 提供的有用信息。【参考方案2】:
您使用的代码更有可能用于 PDT 功能,而不是用于 IPN。请查看以下页面以获取 IPN 的示例代码。
https://github.com/paypal/ipn-code-samples
此外,您可以查看以下页面以比较这两个功能及其详细信息。
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/
【讨论】:
以上是关于收不到 PayPal IPN 回调的主要内容,如果未能解决你的问题,请参考以下文章