Entries Tagged as 'paypal'

Easy payments using Paypal IPN,Using Paypal in PHP

There are several PHP scripts and classes to process PayPal payments using their native IPN (Internet payment notification) feature. Because the whole process is based on the data you need to send via a web form to the PayPal payment processor these script look very similar.

Inside the form there are several required values to process a payment. PayPal gives the advice to post them all to get everything working. The following variables get some special attention:

business = your PayPal email address
cmd = single payments or subscription service (_xclick or _xclick-subscriptions)
return = the URL where the buyer get back after the payment is processed
cancel_return = the URL where the buyer get back if he has cancelled the payment
notify_url = the location where your IPN script is located
rm = how you need the data submitted from PayPal to your IPN script (1=get, 2=post)
currency_code = the currency you accept for your payment
lc = the country version of PayPal where your buyer is send to

<?php
$url
= ‘https://www.paypal.com/cgi-bin/webscr’;
$postdata = ;
foreach(
$_POST as $i =&gt; $v) {
$postdata .= $i.‘=’.urlencode($v).‘&amp;’;
}
$postdata .= ‘cmd=_notify-validate’; $web = parse_url($url);
if (
$web[’scheme’] == ‘https’) {
$web[‘port’] = 443;
$ssl = ’ssl://’;
} else {
$web[‘port’] = 80;
$ssl = ;
}
$fp = @fsockopen($ssl.$web[‘host’], $web[‘port’], $errnum, $errstr, 30);if (!

$fp) {
echo
$errnum.‘: ’.$errstr;
} else {
fputs($fp, “POST ”.$web[‘path’].“ HTTP/1.1rn”);
fputs($fp, “Host: ”.$web[‘host’].“rn”);
fputs($fp, “Content-type: application/x-www-form-urlencodedrn”);
fputs($fp, “Content-length: ”.strlen($postdata).“rn”);
fputs($fp, “Connection: closernrn”);
fputs($fp, $postdata . “rnrn”);while(!

feof($fp)) {
$info[] = @fgets($fp, 1024);
}
fclose($fp);
$info = implode(‘,’, $info);
if (
eregi(‘VERIFIED’, $info)) {
// yes valid, f.e. change payment status
} else {
// invalid, log error or something
}
}

?>