Paypal IPN Variables PHP


Paypal IPN Variables PHP

嗨,我正在设置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);
}
?>

已经弄清楚了,我花了一整天的时间(凌晨3:40才开始工作),但我在一天内学了很多php,我将在几个

中发布我所做的。