| Code:
|
<form method='post' action='https://www.paypal.com/cgi-bin/webscr' target='paypal'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='business' value='$account'>
<input type='hidden' name='item_name' value='$itemname'>
<input type='hidden' name='item_number' value='$lid'>
<input type='hidden' name='amount' value='$price'>
<input type='hidden' name='notify_url' value='$nukeurl/modules/$module_name/ipn.php'>
<input type='hidden' name='return' value='$nukeurl/modules/$module_name/ipn.php'>
<input type='hidden' name='rm' value='2'>
<input type='hidden' name='cancel_return' value='$nukeurl'>
<input type='hidden' name='on0' value='Username'>
<input type='hidden' name='os0' value='$usernamea'>
<input type='hidden' name='currency_code' value='$currency'>
<input type='hidden' name='quantity' value='1'>
<input type='image' name='add' src='modules/$module_name/images/buy.gif' class='paypal'>
</form>
|
| Code:
|
<?php
include("../../mainfile.php");
global $db, $prefix;
// 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 ('www.paypal.com', 80, $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'];
$buyer = $_POST['option_selection1'];
if (!$fp) {
// HTTP ERROR
echo"ERROR: fp";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check that txn_id has not been previously processed
$matchtxn = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_paypal WHERE txn_id='$txn_id'"));
// check that receiver_email is your Primary PayPal email
$matchmail = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_items WHERE account='$receiver_email' AND itemname='$item_name'"));
// check that payment_amount/payment_currency are correct
$matchprice = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_items WHERE itemname='$item_name' AND currency='$payment_currency' AND price='$payment_amount'"));
// if($matchtxn == 0 && $matchmail > 0 && $matchprice > 0){
// process payment
$db->sql_query("INSERT INTO ".$prefix."_dlshop_paypal VALUES (NULL, '$txn_id', '$item_name', '$item_number', '$buyer', '$payment_amount', '$payment_currency', '$receiver_email', '$payer_email')");
// }
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
echo"ERROR";
}
}
fclose ($fp);
}
?>
|