hier mein test-ipn-script:
Nun wird das Geld auf den Sandbox-paypal-account überwiesen, allerdings...ist der Zahlungsstatus: "wird geprüft" . Wieso? Desweitern findet kein Eintrag in die DB statt, wie im script vorgesehen, wieso? auch bekomme ich keine email´s auf meinen email-account, kann mir da jmd helfen? lg
PHP:
define('SECURE', true);
include "connect_to_mysql.php";
// read the data send by PayPal
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$errors = array();
// PAYMENT VALID
// Check payment status
if ($_POST['payment_status'] != 'Completed') {
$errors[] .= "Payment not completed";
}
// Check seller e-mail
if ($_POST['receiver_email'] != '[email protected]') {
$errors[] .= "Incorrect seller e-mail";
}
// Compare the amount received on PayPal with the price you charged for the product or service
if ($_POST['mc_gross'] != '100.00') {
$errors[] .= "Incorrect product price";
}
// Check the currency code
if ($_POST['mc_currency'] != 'USD') {
$errors[] .= "Incorrect currency code";
}
// Check transaction id
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$mc_gross = $_POST['mc_gross'];
$row = mysqli_query($mysqli, "SELECT `txn_id` from `trans` where `txn_id` = $txn_id");
$num = mysqli_num_rows($row);
if($num == 0) {
// Transaction not processed, store it in the database´
$insert = mysqli_query($mysqli, "INSERT INTO `trans`(`txn_id`, `payer_email`, `mc_gross`)
VALUES('".$txn_id."', '".$payer_email."', '".$mc_gross."')");
$message = "Transaction processed";
mail('email', 'IPN Fraud Warning', $message, $headers);
} elseif($num >= 1) {
$message = "Transaction already prozessed";
mail('email', 'IPN Fraud Warning', $message, $headers);
}
if (count($errors) > 0) {
// IPN data is incorrect - possible fraud
// It is a good practice to send the transaction details to your e-mail and investigate manually
$message = "paypal invalid";
mail('email', 'IPN', $message, $headers);
} else {
// PayPal payment is valid
// Process order here
$message = "paypal valid";
mail('email', 'IPN', $message, $headers);
}
} else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID
$message = "payment invalid";
mail('email', 'IPN', $message, $headers);
}
}
fclose ($fp);
}