Custom generated PayPal Button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    Custom generated PayPal Button

    Hi everyone,

    i have been recently asked by some members how you can create a custom generated PayPal Buy Now button. These buttons are extremely useful and are the basis of customized payments. Ok, let's see how you do this. We will suppose here that you want to create a button where amount and item description are user defined. The same technique can be used to customize any other parameter that a PayPal button allows for, as Currency, shipping etc. A working example can be seen in my own payments page, in http://www.dbtechnosystems.com/payment_general.php

    For this tutorial, we will asume that the page (which needs to be in php) is called "payment.php"

    Ok, lets see the steps one by one:

    1. Creating the main button code:
    Go in your PayPal account, and create a button with the charatteristics you like. As we said, we will customize Item description and amount, so don't care about these two things, you can place there as amount "10" and as description: "example description". You will get a code like

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="you@yoursite.com">
    <input type="hidden" name="item_name" value="example description">
    <input type="hidden" name="item_number" value="">
    <input type="hidden" name="amount" value="10">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
    <img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
    </form>
    Now, change these two lines as follows:


    <input type="hidden" name="item_name" value="<? echo $item_name; ?>">
    <input type="hidden" name="amount" value="<? echo $amount; ?>">
    Ok, add this code in the begining:

    <?
    if ($amount != 0){
    ?>
    and the following one at the end:

    <?
    }
    ?>
    At this point the entire button code will be:

    <?
    if ($amount != 0){
    ?>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="you@yoursite.com">
    <input type="hidden" name="item_name" value="="<? echo $item_name; ?>">
    <input type="hidden" name="item_number" value="">
    <input type="hidden" name="amount" value="="<? echo $amount; ?>">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
    <img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
    </form>
    <?
    }
    ?>
    Add a html box, more or less the same size as the button that you want to create, in your page, and paste the code in it. Place the html box where you want it to appear.

    Step 2. Create the form that will customize the button: this is a very simple form, with two fields: "amount", and "item_name". Please use exactly these names, as they are the same that PayPal uses. Add a submit button. Set the form action in "payment.php" so the page will submit to itself, the method to "POST", the encoding type to "multipart / form data".

    Double click the amount field and the initial value to be

    <? echo $amount; ?>

    Double click the item_name field and set the initial value to be <? echo $item_name; ?>

    Ok, the form part is finished.

    Step 3. Go to Page html, and paste the following code in the Start of page Tag:

    <?
    $item_name = $_POST['item_name'];
    $amount = $_POST['amount'];
    ?>
    Now, set your page extension to be php when published, save, and publish.

    That's all, have fun!!

    Warning: this trick asumes that you use a NON ENCRYPTED PayPal buy now button. Ad Davidindalicia has correctly stated in a post furher down, the code results clear to whoever views the source code. So, anyone can see the return page link. Conclusion: do NOT use this trick to generate a PayPal Button for downloadable products, unless you have a script that will verify the payment before allowing the download link(s) to appear in the return page.
    This trick is intended for customized payments, where the return page is simply a thank you page (you send the product yourself, either per email, if it is an electronic product, or phisically ship it, if it is a real product), or for those cases where the product is a downloadable one, but the download link is protected by a payment verification code as described above.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

  • aconstas1
    Lieutenant Colonel

    • Mar 2007
    • 582

    #2
    Re: Custom generated PayPal Button

    Thanks Naval. Just another one of those treasures that you wont find anywhere else.
    Best Regards,
    Alex
    Surveillance Systems
    Restaurant POS | Retail POS
    Free WoW Gold Guide

    Comment

    • aconstas1
      Lieutenant Colonel

      • Mar 2007
      • 582

      #3
      Re: Custom generated PayPal Button

      Does this work if I add the appropriate hidden fields and code to an encrypted button that I generate with PayPal?
      Best Regards,
      Alex
      Surveillance Systems
      Restaurant POS | Retail POS
      Free WoW Gold Guide

      Comment

      • aconstas1
        Lieutenant Colonel

        • Mar 2007
        • 582

        #4
        Re: Custom generated PayPal Button

        sorry another question, can you make item_name required with ABVFP or will the name extension mess up the PayPal side of it?
        Best Regards,
        Alex
        Surveillance Systems
        Restaurant POS | Retail POS
        Free WoW Gold Guide

        Comment

        • davidundalicia
          General

          • Mar 2006
          • 6294

          #5
          Re: Custom generated PayPal Button

          NavalDesign,

          Would it not be a good idea to advise anyone that uses this tip, that they will also need a method of confirming payment BEFORE directing the client to the actual download page?

          If members use this tip as it is, then the return page is visible after the paypal button has been generated and BEFORE the payment has been made......
          Have fun
          Regards..... David

          Step by Step Visual Tutorials for the complete beginner
          Newbies / Beginners Forum
          FREE Membership Login Scripts: - Meta Tags Analyzer
          My Social Networking Site - Free Contact Forms
          Finished your New website!! Now get it noticed Here:

          Comment

          • aconstas1
            Lieutenant Colonel

            • Mar 2007
            • 582

            #6
            Re: Custom generated PayPal Button

            The buttons i generate do not grab the correct item_name
            my field is correctly named and has the correct initial value
            my button html also has the correct code in the value
            What else could cause this?

            my payment php page is HERE
            Best Regards,
            Alex
            Surveillance Systems
            Restaurant POS | Retail POS
            Free WoW Gold Guide

            Comment

            • aconstas1
              Lieutenant Colonel

              • Mar 2007
              • 582

              #7
              Re: Custom generated PayPal Button

              I dont know what I did, but apparently where the fields appear in html versus the button has something to do with functionality. Also i had copied and pasted the amount code and just changed the item_number name which made my amount field be entered for the item_name during button generation. I had to delete the line in the HTML code in the button and retype the line for the item_name value without copying and pasting. I dont know why this would have effected the functionality of my form and button generation, but it did.
              Best Regards,
              Alex
              Surveillance Systems
              Restaurant POS | Retail POS
              Free WoW Gold Guide

              Comment

              • davidundalicia
                General

                • Mar 2006
                • 6294

                #8
                Re: Custom generated PayPal Button

                Alex, when I tested your button it generated the button with the correct text in the item-name.

                But the return page could not be found...maybe you should check the spelling of your return link.
                Have fun
                Regards..... David

                Step by Step Visual Tutorials for the complete beginner
                Newbies / Beginners Forum
                FREE Membership Login Scripts: - Meta Tags Analyzer
                My Social Networking Site - Free Contact Forms
                Finished your New website!! Now get it noticed Here:

                Comment

                • aconstas1
                  Lieutenant Colonel

                  • Mar 2007
                  • 582

                  #9
                  Re: Custom generated PayPal Button

                  Originally posted by davidundalicia
                  Alex, when I tested your button it generated the button with the correct text in the item-name.

                  But the return page could not be found...maybe you should check the spelling of your return link.
                  hehe yes i got it working, and it didn't find the return yet because I'm still building it. :p
                  Thanks for watching out for me though.
                  Best Regards,
                  Alex
                  Surveillance Systems
                  Restaurant POS | Retail POS
                  Free WoW Gold Guide

                  Comment

                  • navaldesign
                    General & Forum Moderator

                    • Oct 2005
                    • 12080

                    #10
                    Re: Custom generated PayPal Button

                    Originally posted by aconstas1
                    Does this work if I add the appropriate hidden fields and code to an encrypted button that I generate with PayPal?
                    No, you need to use a NON encrypted button.

                    Can you make the "item_name" required ?

                    Yes, but a differents version would be needed, with a second page, which would check the amount and item name, and if the amount is not null, will chek the item name to see if it is null, and if yes, it will give an error message. If both are null, it will redirect to the same initial page.

                    The button is correctly generated in your page.
                    Navaldesign
                    Logger Lite: Low Cost, Customizable, multifeatured Login script
                    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                    Comment

                    • navaldesign
                      General & Forum Moderator

                      • Oct 2005
                      • 12080

                      #11
                      Re: Custom generated PayPal Button

                      Originally posted by davidundalicia
                      NavalDesign,

                      Would it not be a good idea to advise anyone that uses this tip, that they will also need a method of confirming payment BEFORE directing the client to the actual download page?

                      If members use this tip as it is, then the return page is visible after the paypal button has been generated and BEFORE the payment has been made......
                      David, you are correct. But this is NOT intended for a downloadable product payment. Usually downloadable products have a fixed description and price. It is intended for a customized service payment, where the return page is simply a thank you page.

                      However, you are correct, and i shall place the correct warning in my initial post.

                      Thanks.

                      You know my opinion on paid for downloads: no links, no risk. The thank you page (in my opinion) MUST have a payment verification script.
                      Navaldesign
                      Logger Lite: Low Cost, Customizable, multifeatured Login script
                      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                      Comment

                      • davidundalicia
                        General

                        • Mar 2006
                        • 6294

                        #12
                        Re: Custom generated PayPal Button

                        As a method of paying for a service without a downloadable product, then once again your expertise and contribution is highly commendable and I shall use this myself..............Thanks George.
                        Have fun
                        Regards..... David

                        Step by Step Visual Tutorials for the complete beginner
                        Newbies / Beginners Forum
                        FREE Membership Login Scripts: - Meta Tags Analyzer
                        My Social Networking Site - Free Contact Forms
                        Finished your New website!! Now get it noticed Here:

                        Comment

                        • Karen Mac
                          General

                          • Apr 2006
                          • 8332

                          #13
                          Re: Custom generated PayPal Button

                          When copy and pasting from other sources on the web like webpages or forums, its a good idea to to first copy into notepad, then recopy the notepad code to your actual application. Very often you pick up some erroneous code or figures that may or not be visible to you, but generally notepad will eliminate that.

                          Alternately, could you not just make your own button and just change the URL to your .gif instead of the secured one at paypal?

                          <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
                          or will it give a pop up error?

                          Karen

                          VodaHost

                          Your Website People!
                          1-302-283-3777 North America / International
                          02036089024 / United Kingdom
                          291916438 / Australia

                          ------------------------

                          Top 3 Best Sellers

                          Web Hosting - Unlimited disk space & bandwidth.

                          Reseller Hosting - Start your own web hosting business.

                          Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)


                          Comment

                          • aconstas1
                            Lieutenant Colonel

                            • Mar 2007
                            • 582

                            #14
                            Re: Custom generated PayPal Button

                            I'm using this to allow my customers to pay me their monthly bills via web site instead of me having to go collect or them mail it in. Excellent addition to the web site.
                            Best Regards,
                            Alex
                            Surveillance Systems
                            Restaurant POS | Retail POS
                            Free WoW Gold Guide

                            Comment

                            • navaldesign
                              General & Forum Moderator

                              • Oct 2005
                              • 12080

                              #15
                              Re: Custom generated PayPal Button

                              Originally posted by Karen Mac
                              When copy and pasting from other sources on the web like webpages or forums, its a good idea to to first copy into notepad, then recopy the notepad code to your actual application. Very often you pick up some erroneous code or figures that may or not be visible to you, but generally notepad will eliminate that.

                              Alternately, could you not just make your own button and just change the URL to your .gif instead of the secured one at paypal?



                              or will it give a pop up error?

                              Karen
                              Hi KAren,

                              yes, you can change the image source. No problem
                              Navaldesign
                              Logger Lite: Low Cost, Customizable, multifeatured Login script
                              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                              Comment

                              Working...
                              X