[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [cobalt-users] Paypal and IPN on RAQ
- Subject: RE: [cobalt-users] Paypal and IPN on RAQ
- From: BSmith@xxxxxxxxxxx
- Date: Tue Feb 25 08:56:01 2003
- List-id: Mailing list for users to share thoughts on Sun Cobalt products. <cobalt-users.list.cobalt.com>
-----Original Message-----
From: Revd Leonard Payne [mailto:vicarage@xxxxxxxxxxxxxx]
Subject: [cobalt-users] Paypal and IPN on RAQ
Hi there
Has anyone had problems in getting Paypal IPN (Instant Purchase
Notification) working on a Raq?
regards
Leonard
_____________________________________
It must be your programming skills. Use the example from their site.
It works perfectly. Here you go, here it is:
This sends it:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="brian@xxxxxxxxxx">
<input type="hidden" name="item_name" value="IPN Test">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="return"
value="http://www.nuonce.net/test/print.php">
<input type="hidden" name="notify_url"
value="http://www.nuonce.net/test/print.php">
<input type="image" src="http://images.paypal.com/images/x-click-butcc.gif"
name="submit">
</form>
The return can be a thank you page. I just put them as 1 page. You can
setup the
notify page as like a mini daemon, so it just updates a db, or whatever you
want.
You can also return a "custom" field. READ READ READ. It is rather easy!!
This receives it: (PHP)
<?php
# i used this to see what paypal sends to me:
foreach ($_POST as $key => $value) {
echo "Key: $key; Value: $value<br>\n";
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($HTTP_POST_VARS 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 ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
// note: additional IPN variables also available -- see
// IPN documentation
$item_name = $HTTP_POST_VARS['item_name'];
$receiver_email = $HTTP_POST_VARS['receiver_email'];
$item_number = $HTTP_POST_VARS['item_number'];
$invoice = $HTTP_POST_VARS['invoice'];
$payment_status = $HTTP_POST_VARS['payment_status'];
$payment_gross = $HTTP_POST_VARS['payment_gross'];
$txn_id = $HTTP_POST_VARS['txn_id'];
$payer_email = $HTTP_POST_VARS['payer_email'];
if (!$fp) {
// ERROR
echo "$errstr ($errno)";
} 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 an email address in your PayPal
account
// process payment
print "received";
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>