PDA

View Full Version : Paypal button amount variable



Firehorse
26-03-2011, 06:11 PM
I need the buy now button on a site i'm developing to be the output value of a php form that is on the same page.
Right now this outputs the value I need in plain text on the page itself:

<?php echo $sum_total; ?>

But when I put it into the paypal form value I get an error when testing saying the value is incorrect.


<input type="hidden" name="amount" value="<?php echo $sum_total; ?>">

Does anyone know why this is happening and what I can do to fix it?

hamheyelliot
26-03-2011, 06:19 PM
Mind posting the complete code snippet you're using? And is the output just a digit, without other characters?

Firehorse
26-03-2011, 06:26 PM
Mind posting the complete code snippet you're using? And is the output just a digit, without other characters?

Yes the output is a single digit.

Rest of the code (includes the mailing bit):


<?php
if(isset($_POST['submit'])) {
$to = "*removed*";
$subject = "Ticket Request";
$date_field = $_POST['date'];
$title_field = $_POST['title'];
$name_field = $_POST['name'];
$childname_field = $_POST['childname'];
$email_field = $_POST['email'];
$class_field = $_POST['class'];
$tickets1_field = $_POST['tickets1'];
$tickets2_field = $_POST['tickets2'];
$tickets3_field = $_POST['tickets3'];
$sum_total = ($tickets1_field * 8.00) + ($tickets2_field * 6.00) + ($tickets3_field * 5.00);
$direct_text = '<b>Cost of Ticket Order =</b> £';

$body = "Subject: $subject\n Date: $date_field\n Name: $title_field $name_field\nChild: $childname_field\nEmail: $email_field\nClass: $class_field\n Adult Tickets: $tickets1_field\n Student/Child Tickets: $tickets2_field\n OAP Tickets: $tickets3_field\n$direct_text";
echo "To complete your ticket purchase please click the Buy Now button.<p>";
echo "<b>Date:</b> $date_field<br><b>Name:</b> $title_field $name_field<br><b>Child:</b> $childname_field<br><b>Email:</b> $email_field<br>
<b>Class:</b> $class_field<br><b>Adult Tickets:</b> $tickets1_field<br><b>Student/Child Tickets:</b> $tickets2_field<br><b>OAP Tickets:</b> $tickets3_field<p>$direct_text$sum_total";
mail($to, $subject, $body);
} else {
echo "Oops! Something went wrong when ordering your tickets, please try again later. Do NOT click the buy now button as the order has not been correctly processed.";
}
?>
<p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="amount" value="<?php echo $sum_total; ?>">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="*removed*">
<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

hamheyelliot
26-03-2011, 06:36 PM
Looks solid to be honest, I'm a bit thrown.

You could try adding some of these values I've plucked out of another PayPal button, they could be required for all I know:

<input type="hidden" value="[email protected]" name="business">

<input type="hidden" value="successful_payment.html" name="return">

<input type="hidden" value="unsuccessful_payment.html" name="cancel_return">

<input type="hidden" value="GBP" name="currency_code">

<input type="hidden" value="" name="item_name">

Firehorse
26-03-2011, 06:40 PM
If it helps then this is the exact message paypal gives:
The link you have used to enter the PayPal system contains an incorrectly formatted item amount.

Tried adding a couple of those lines but no change unfortunately :/

hamheyelliot
26-03-2011, 06:43 PM
Hmm, how does the value show up? Like '7' or '7.30' or whatever it might be.

Edit: Just noticed it's x.xx, I'll have a quick look.

Firehorse
26-03-2011, 06:49 PM
Hmm, how does the value show up? Like '7' or '7.30' or whatever it might be.

Edit: Just noticed it's x.xx, I'll have a quick look.

For me it is always showing up as "8" rather than "8.00" etc.

hamheyelliot
26-03-2011, 07:02 PM
I'll be pleasantly (but inside angrily) surprised if this doesn't work for you!

<form method="post" id="paypal" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" value="_xclick" name="cmd">
<input type="hidden" value="GB" name="lc">
<input type="hidden" value="[email protected]" name="business">
<input type="hidden" value="Ticket Purchase" id="item_name" name="item_name">
<input type="hidden" value="1" name="item_number">
<input type="hidden" value="<?php echo $sum_total; ?>" id="amount" name="amount">
<input type="hidden" value="GBP" name="currency_code">
<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
</form>

I've just bolded the stuff you can definitely change, I know you're no code pushover don't worry :P Let me know how this works as so far it's plain sailing at my end.

Firehorse
26-03-2011, 08:10 PM
It worked :D +rep to you good sir!

hamheyelliot
26-03-2011, 08:22 PM
It worked :D +rep to you good sir!
Haha, phew! Cheers :D

Want to hide these adverts? Register an account for free!