我希望有人能指出我正确的方向。
我在一个网站上创建了一个IPN监听器,目前它适用于订阅的人并创建他们的PIN号,将他们的登录(电子邮件和随机生成的PIN)添加到数据库而不会出现问题。然后,他们可以在收到包含详细信息的电子邮件后登录下载区域。
注册效果很好 - 但是,当他们取消订阅时,Paypal会清楚地发送通知,而IPN只是发出新的登录信息而且我不知道如何编写代码来发送“抱歉你” “离开”电子邮件并将其从数据库中删除。
非常感谢任何帮助!
以下脚本;
<?php
mysql_connect("xxxx", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
// read the post from PayPal system and add 'cmd'
$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.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) {
// PAYMENT VALIDATED & VERIFIED!
$email = $_POST['payer_email'];
$password = mt_rand(1000, 9999);
mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
$to = $email;
$subject = 'xxx Download Area | Login credentials';
$message = '
Thank you for your purchase
Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------
You can now login at xxxxx';
$headers = 'From:xxx@xxx.co.uk' . "\r\n";
mail($to, $subject, $message, $headers);
}
else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID & INVESTIGATE MANUALY!
$to = 'paypal@xxx.co.uk';
$subject = 'xxx Download Area | Invalid Payment';
$message = '
Dear xxx,
A payment has been made for the Download area on xxx.co.uk but is flagged as INVALID.
Please verify the payment manually and contact the buyer.
Please contact xxx at xxx on xxx if you need additional help, the buyers email is below;
Buyer Email: '.$email.'
';
$headers = 'From:noreply@xxx.co.uk' . "\r\n";
mail($to, $subject, $message, $headers);
}
}
fclose ($fp);
}
?>
答案 0 :(得分:2)
只需添加一个开关,检查与ipn一起发送的txn_type的类型。这只是我的头脑,但试一试.....
$email = $_POST['payer_email'];
switch ($_POST['txn_type']) {
case 'web_accept':
//you received a payment such as a buy now button
//so now lets do things such as trigger a call to a
//function to create an email or add POST vars to a database
$this->createUser($email, $password);
$this->createEmail($email, $password);
break;
case 'subscr_signup':
//This shows that someone has subscribed using a subscribe button
//We can do anything here such as increase the users access level
break;
case 'subscr_payment':
//payment for a subscribed user has just been made
//do something such as send them a conformation email
break;
case 'subscr_eot':
//this is a End Of Terms meaning that the subscriber either canceled or
//paypal could not process the payment due to the user not having the funds
//lets remove them from our database and send them an email
$this->removeUser($email);
break;
case 'subscr_cancel':
//Here the user canceled their account so lets remove them and send an email
$this->removeUser($email);
break;
}
function createEmail($email, $password)
{
$to = $email;
$subject = 'xxx Download Area | Login credentials';
$message = '
Thank you for your purchase
Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------
You can now login at xxxxx';
$headers = 'From:xxx@xxx.co.uk' . "\r\n";
mail($to, $subject, $message, $headers);
}
function createUser($email, $password)
{
mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
}
沿着这些方向的东西应至少让你朝着正确的方向前进。