1
我讀了一些答案試圖解決我的問題,但沒有奏效。下面的代碼是從https://github.com/Quixotix/PHP-PayPal-IPNPaypal IPN PHP腳本沒有插入數據庫
我已經這樣做:
- 集IPN的URL在貝寶(不是localhost);
- 刪除「完成」條件;
- 刪除「txn_id」等條件試圖使其工作;
這些嘗試都不適用於我,即使我使用ipn模擬器。
<?php
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
// intantiate the IPN listener
include('PHP-PayPal-IPN-master/ipnlistener.php');
$listener = new IpnListener();
// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;
// try to process the IPN POST
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
} catch (Exception $e) {
error_log($e->getMessage());
exit(0);
}
if ($verified) {
$errmsg = ' <br/>'; // stores errors from fraud checks
// 1. Make sure the payment status is "Completed"
if ($_POST['payment_status'] != 'Completed') {
//simply ignore any IPN that is not completed
exit(0);
}
// 2. Make sure seller email matches your primary account email.
if ($_POST['receiver_email'] != '[email protected]') {
$errmsg .= "'receiver_email' does not match: ";
$errmsg .= $_POST['receiver_email']."\n";
}
// 3. Make sure the amount(s) paid match
if ($_POST['mc_gross'] != '10') {
$errmsg .= "'mc_gross' does not match: ";
$errmsg .= $_POST['mc_gross']."\n";
}
// 4. Make sure the currency code matches
if ($_POST['mc_currency'] != 'USD') {
$errmsg .= "'mc_currency' does not match: ";
$errmsg .= $_POST['mc_currency']."\n";
}
// 5. Ensure the transaction is not a duplicate.
include_once("../includes/psl-config.php");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$txn_id = mysqli_real_escape_string($mysqli, $_POST['txn_id']);
$sql = "SELECT COUNT(*) FROM paypal WHERE txn_id = '$txn_id'";
$r = mysqli_query($mysqli, $sql);
if (!$r) {
error_log(mysqli_error($mysqli));
exit(0);
}
$exists = $r;
if ($exists) {
$errmsg .= "'txn_id' has already been processed: ".$_POST['txn_id']."\n";
} */
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$body .= $listener->getTextReport();
mail('[email protected]', 'IPN Fraud Warning', $body);
} else {
// add this order to a table of completed orders
if (isset($_POST['item_number'])) {
$item_number = $_POST['item_number'];
}
if($stmt = $mysqli->prepare("INSERT INTO paypal (item_number) VALUES (?)")){
$stmt->bind_param('s', $item_number);
$stmt->execute();
}else{
$errmsg .= "Error trying to insert into DB<br/>";
error_log(mysqli_error($mysqli));
}
// free user ads here
}
} else {
// manually investigate the invalid IPN
mail('[email protected]', 'Invalid IPN', $listener->getTextReport());
}
?>
我一直在收到欺詐電子郵件。有時它給我帶來了txn_id已經被處理了,但是如果沒有任何東西被插入到數據庫中,它如何檢查呢?
你爲什麼不嘗試獲得IPN的RAW POST,然後看看你的評價(S)是/是「失敗」還是「落空」。 – EdSF