Reputation: 201
I am running IPN on my dayz server to automatically take care of donations and distribute whatever goodies the person has bought. There is one problem though...I have added a custom field called "Player ID" and it is required that they fill it out because it is used later in a database entry. My shopping.php page looks like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="Alice Pack">
<input type="hidden" name="item_number" value="300">
<input type="hidden" name="amount" value="0.10">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<table>
<tr><td><input type="hidden" name="on0" value="Player Unique ID">Player Unique ID</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
</table>
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
now, I see that the input field is named "os0" so I tried mysql_real_escape_string($_POST['os0'])
and it is returning nothing.
Here is my IPN.php:
<?php
mysql_connect("dbhost", "dbuser", "dbpass") or die(mysql_error());
mysql_select_db("db") 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) {
$id = mysql_real_escape_string($_POST['item_number']);
$uniqueid = mysql_real_escape_string($_POST['os0']);
// PAYMENT VALIDATED & VERIFIED!
mysql_query("INSERT INTO cust_loadout_profile (cust_loadout_id, unique_id) VALUES ('$id', '$uniqueid')");
$to = '[email protected]';
$subject = 'Download Area | Login Credentials';
$message = '
Thank you for your purchase
Your account information
-------------------------
Email: '.$id.'
Password: '.$password.'
-------------------------
SUCCESS
You can now login at http://yourdomain.com/PayPal/';
$headers = 'From:[email protected]' . "\r\n";
mail($to, $subject, $message, $headers);
}
else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID & INVESTIGATE MANUALY!
$to = '[email protected]';
$subject = 'Download Area | Login Credentials';
$message = '
Thank you for your purchase
THIS IS ALSO AN ERROR
Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------
You can now login at http://yourdomain.com/PayPal/';
$headers = 'From:[email protected]' . "\r\n";
mail($to, $subject, $message, $headers);
}
}
fclose ($fp);
}
?>
is there a way to get my required post to work in my IPN?
Upvotes: 0
Views: 77
Reputation: 986
You need to add custom field in your form like
< input type="hidden" name="custom" value="2" >
and to get this field on ipn script use below code
< ?php
if (isset($_REQUEST['custom'])){
$custom = $_REQUEST['custom'];
}
?>
Upvotes: 1