【问题标题】:Paypal IPN Variables PHP [closed]Paypal IPN 变量 PHP [关闭]
【发布时间】:2012-01-02 00:01:38
【问题描述】:

您好,我正在设置 ipn,但我对 php 非常陌生,我以为我已经弄清楚但还没有接近 :)

无论如何,我要做的就是在付款后将人名写入文本文件,然后在旁边将他们的输入写入我在按钮中创建的文本字段中,如下所示

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5ES3TSKJNLJ24">
<table style="text-align: right; width: 100%;">
<tr><td><input type="hidden" name="on0" value="Amount you'd like to donate">Amount you'd like to donate</td></tr><tr><td><select name="os0">
    <option value="Just the license">Just the license $2.99 USD</option>
    <option value="A bit more">A bit more $5.99 USD</option>
    <option value="Two bits more">Two bits more $8.99 USD</option>
    <option value="A lot more">A lot more $15.00 USD</option>
    <option value="We love you :)">We love you :) $50.00 USD</option>
</select> </td></tr>
<tr><td><input type="hidden" name="on1" value="Primary Phone Gmail">Primary Phone Gmail</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" align="right" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

我的 ipn.php 是这样的

<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following: 
// To continue posting back to https://www.paypal.com  to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify  your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."


// 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: ipnpb.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://ipnpb.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'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$payer_firstName = $_POST['first_name'];
$payer_lastName = $_POST['last_name'];
$gmail = $_POST['on1'];

//set email variables
$From_email = "From: fake@website.com";
$Subject_line = "Thanks for your purchase";

$email_msg = "\n\nThe details of your order are as follows:";
$email_msg .= "\n\n" . "Transaction ID: " .  $txn_id ;
$email_msg .= "\n" . "Payment Date: " . $payment_date;

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;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

$data = "$payer_firstName $payer_lastName $gmail";

$fh = fopen("./paypal/test.txt", "a");
fwrite($fh, $data);
fclose($fh);

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = $From_email;
$mail_To = $receiver_email;
$mail_Subject = "INVALID IPN POST";
$mail_Body = "INVALID IPN POST. The raw POST string is below.\n\n" . $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>

【问题讨论】:

  • 你为什么要检查魔术引号?此选项已被弃用,任何人都不应使用它。这会为您的代码增加额外的复杂性。
  • 我只是从贝宝复制并粘贴了示例,老实说,我不太了解 php,这就是为什么我遇到麻烦大声笑。我的 php 知识的扩展是编写一个文本文件:)
  • 更新了我的问题,希望这更简单,我要做的就是在他们付款后,只需在我服务器上的 txt 文件中的一行上写下他们的姓名和文本字段的输入。
  • 好吧,我的 ipn 现在是成功的,但是当我使用上面的脚本通过真实事务运行它时,它不会发送电子邮件或写入确实存在任何想法的文本文件?我想我已经接近了,我只是没有看到它正常工作,在我的高级变量中我有 notify_url=website.com/ipn.php 我也检查过并且存在但它不工作?

标签: php html paypal paypal-ipn


【解决方案1】:

已经想通了,运行起来花了我一整天(凌晨 3:40 开始工作),但确实在一天内学习了很多 php,哈哈,我会在几篇文章中发布我所做的

【讨论】:

  • 您能告诉我们您是如何解决这个问题的吗?目前,这个答案并不能真正帮助其他可能遇到同样问题的人。如果你这样做,那么我会重新打开你的问题。谢谢。
  • 对不起,当我对代码和网站真正陌生时,这是一个老问题,但是是的,我记得遵循本教程 micahcarrick.com/paypal-ipn-with-php.html 并且能够将其连接并工作。重点是在贝宝的网站上,您需要将按钮指向 ipn 脚本
猜你喜欢
  • 2012-08-24
  • 2011-06-08
  • 1970-01-01
  • 2012-12-05
  • 2011-06-21
  • 2012-01-26
  • 2017-02-10
  • 2014-02-26
  • 2016-03-05
相关资源
最近更新 更多