Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2007
    Posts
    4,664
    Tokens
    1,279

    Latest Awards:

    Question Paypal button amount variable

    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:
    Code:
    <?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.

    Code:
    <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?


  2. #2
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    Mind posting the complete code snippet you're using? And is the output just a digit, without other characters?

  3. #3
    Join Date
    Jan 2007
    Posts
    4,664
    Tokens
    1,279

    Latest Awards:

    Default

    Quote Originally Posted by elliot View Post
    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 Code:
    <?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>
    Last edited by Firehorse; 26-03-2011 at 06:27 PM.


  4. #4
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    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">

  5. #5
    Join Date
    Jan 2007
    Posts
    4,664
    Tokens
    1,279

    Latest Awards:

    Default

    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 :/


  6. #6
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    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.
    Last edited by hamheyelliot; 26-03-2011 at 06:44 PM.

  7. #7
    Join Date
    Jan 2007
    Posts
    4,664
    Tokens
    1,279

    Latest Awards:

    Default

    Quote Originally Posted by elliot View Post
    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.


  8. #8
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    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 Let me know how this works as so far it's plain sailing at my end.

  9. #9
    Join Date
    Jan 2007
    Posts
    4,664
    Tokens
    1,279

    Latest Awards:

    Default

    It worked +rep to you good sir!


  10. #10
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    Quote Originally Posted by Stuto View Post
    It worked +rep to you good sir!
    Haha, phew! Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •