未收到PayPal IPN回拨

时间:2017-07-11 07:18:18

标签: php mysql paypal paypal-sandbox paypal-ipn

这是我的付款表单和成功页面,用于获取付款并将付款数据存储到我的数据库。 付款表单工作正常但success.php页面没有从paypal获取任何数据。我已经在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" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<?php } ?>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

您使用的代码更可能是用于PDT功能,而不是用于IPN。请查看下面的页面,了解IPN的示例代码。

https://github.com/paypal/ipn-code-samples

此外,您可以查看下面的页面,了解这两个功能的比较及其详细信息。

https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/

答案 1 :(得分:-2)

Brother使用$_REQUEST方法代替$_GET方法获取交易详情。希望它能帮助你