Hi everyone. I am trying to write a script that lets users of my website purchase credits. They either have the choice of purchasing 1,2,4,6,8 or 10 credits. Here is the code for the PayPal IPN.
<?php
include 'config.php';
// 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);
// 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 = encode($_POST['payer_email'], 'email');
$page = decode(clean($_POST['paofor']), 'paofor');
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if($payment_amount=='0.59'||'1.18'||2||3||'4.20'||'5.25'&&$payment_currency=="GBP")
{
if($payment_amount==0.59)
{
$credits = 1;
}
else
if($payment_amount==1.18)
{
$credits = 2;
}
else
if($payment_amount==2)
{
$credits = 4;
}
else
if($payment_amount==3)
{
$credits = 6;
}
else
if($payment_amount==4.20)
{
$credits = 8;
}
else
if($payment_amount==5.25)
{
$credits = 10;
}
//update user records
$update_creds = sprintf("UPDATE users SET download_credits=download_credits+" . $credits . " WHERE username='%s' AND id='%s'", clean($_COOKIE['username']), clean($_COOKIE['id']));
$update_creds = mysql_query($update_creds);
$creds_user_msg = 'Hi ' . decode($fetch['first'], '<ST6_+') . '.This is an email to let you know that your purchase of ' . $credits . ' download credit(s) was successful. Payment Method: ' . bold('PayPal') . 'Payment InfoItem: ' . bold('' . $credits . ' Download Credit(s)') . 'Amount: ' . bold('£'.$payment_amount) . 'Date and Time of Purchase: ' . bold(date('l jS F Y - g:iA', time())) . '';
$creds_admin_msg = $fetch['username'] . ' (' . decode($fetch['first'], '<ST6_+') . ' ' . decode($fetch['last'], 'ANK6/Q') . ') bought ' . $credits . ' download credits.Date and Time: ' . date('l jS F Y - g:iA', time()) . '';
email(decode($payer_email, 'AmrsZG'), $upgradeemail, 'Upgrade Successful', $creds_user_msg);
email('email@site.com', $upgradeemail, 'Credits Purchase', $creds_admin_msg);
email('email@site.com', $upgradeemail, 'Credits Purchase', $creds_admin_msg);
sendText('number', 'Credits Purchase. Username: ' . $fetch['username'] . '. Email: ' . decode($payer_email, 'AmrsZG') . '. Date and Time: ' . date('l jS F Y - g:iA', time()) . '');
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
I am having trouble updating the quantity on the PayPal screen. As you will see below in the image the quantity says "1". Please can someone help me change this to the amount the user chooses.
Thanks in advance.