Member Avatar for doctorphp

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('&pound;'.$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.

Recommended Answers

All 3 Replies

Use this and edit for your situation, i guess its better

<?php
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name=cmd value=_xclick>
<input type="hidden" name="business" value="{$set['paypal']}">
<input type="hidden" name="item_name" value="{$domain}|DP|1|{$userid}">
<input type="hidden" name="amount" value="3.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://{$domain}/donatordone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://{$domain}/donatordone.php?action=cancel">
<input type="hidden" name="notify_url" value="http://{$domain}/ipn_donator.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
?>
Member Avatar for doctorphp

Thanks but none of the hidden fields change the quantity.

Just add one new hidden field with quantity name.

<input type='hidden' name='quantity' value='3'>

Above will show 3 quantity on paypal page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.