Paypal IPN Variables

gflam

Developer
Developer
Theme Developer
Joined
Jun 14, 2010
Messages
1,900
Reaction score
29
Location
Jersey
Don't know a ton about web development :) lol not really my cup of tea but i started working on my site Init 2 Winit Applications and trying to work with the ipn so that we can accept payments for boot manager through that.

Anyone have any knowledge using the ipn? Don't really need to do much just looking to pass two variables and write it to a text file on my server. I've written text files with php just can't figure out how to pass the variables from the ipn to the script and write to the file. I tested on with the sandbox and the ipn was successful and i've ensured the link in my paypal button is right to go to this script but it's just not working correctly for some reason.

Code looks like this

Paypal Form
Code:
<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>

PHP Script
Code:
<?php
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header = "POST /cgi-bin/webscr HTTP/1.0\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";

$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

$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'];

$From_email = "From: [email protected]";
$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;
$email_msg .= "\n\nThank you for the purchase!\n\nInit 2 Winit Apps";

if (!$fp) {
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$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) {

$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);
}
?>

Any help would be appreciated :) I'll send whoever can help a free copy of boot manager as well just to sweeten the deal a little :) lol
 
OP
gflam

gflam

Developer
Developer
Theme Developer
Joined
Jun 14, 2010
Messages
1,900
Reaction score
29
Location
Jersey
Spent a few hours today teaching myself some php its currently 3:40 :) in the end I figured it all out and got the whole thing working ipn is no fun but it works and is pretty versatile

Sent from my evo 3d at 1.8ghz
 
Top