有没有人与贝宝IPN?我从PayPalTech.com获得了一些示例代码,并进行了编辑以适应我的需求。基本上所有我想要工作的是在订单完成后发送给客户的电子邮件。我编辑了PHP代码以适合我的需求,但由于某种原因,它现在不再适用了。最初的代码只是为了回复来自IPN的所有php变量,并在发送给我自己的电子邮件中结束它。这是我迄今为止的代码。PayPal帮助IPN在交易后发送电子邮件
<?php
// 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";
// If testing on Sandbox use:
// $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
//transaction ID
$txn_id = $_POST['txn_id'];
//ATEKDesign
$business = $_POST['business'];
//payer email
$payer_email = $_POST['payer_email'];
//create payer name
$payer_firstname = $_POST['first_name'];
$payer_lastname = $_POST['last_name'];
$payer_name = $payer_firstname . " " . $payer_lastname;
//create payer address
$name = $_POST['address_name'];
$street = $_POST['address_street'];
$city = $_POST['address_city'];
$state = $_POST['address_state'];
$zip = $_POST['address_zip'];
$address = "$name \n $street \n $city $state $zip";
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$mail_From = "From: [email protected]";
$mail_To = "[email protected]";
$mail_Subject = "VERIFIED IPN";
$mail_Body = "Hello $payer_ name , thank you for purchasing the $item_name from $buisness , your order ID is as follows: $txn_id; . \n We will be using $payer_email to contact you and will be sending you item to $address";
$emailtext = blank;
mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);
}
你能解释一下哪些工作不正常吗?你有错误吗?邮件没有被发送?编程是否进入发送邮件的if块? – Jrod 2011-06-14 17:20:44
正如代码示例中的注释所述,在测试时应使用Sandbox设置Paypal开发人员帐户,以便您可以安全地在代码上测试假Paypal事务。您可能遇到的一个问题是您的代码正在接触到产品Paypal服务器。 我还假定你有最后的'else'和'while'块的右括号,并且它们在上面的例子中被省略了。 – Mattygabe 2011-06-14 18:26:42