locked
PayPal Button (Pay Pal Button ) SOLUTIONS!!!! RRS feed

  • Question

  • User362990094 posted

    Hi, all - I'm a newbie who just spent all day today trying to add a single PayPal button to my site (built in VWD2005X Ed).  I am not using a starter kit and literally just wanted to add an encrypted Buy Now Button to my page.  Here's what I tried, and here's what WORKED.

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

    THE QUICKEST SOLUTION: 

    1) PayPal link (vs. a button) - This works great and quickly if you don't mind not having encryption:

    <a href=" https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=YourPaymentEmailAtPayPal&item_name=YourItemName&item_number=YourItemNumber&amount=PriceNoDollarSign">

    </a>

    plus, you can add the real PayPal button image as the hyperlink image by referencing the PayPal button URL provided in the form code PayPal created for your button (<IMG src="https://www.paypal.com, etc.">.  Voila - you have a button - just no encryption.

     My thanks to Ahmad at PayPal Merchant Tech support (http://www.pdncommunity.com/pdn/board/message?board.id=basicpayments&message.id=2477&jump=true#M2477)

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

    THE BEST SOLUTION (if your host security settings allow it):

    2) PayPal Developer modules - I downloaded these and the Buy Now Button worked beautifully locally. But as soon as I uploaded it to my Go Daddy-hosted site, I got an error page: "That assembly does not allow partially trusted callers."  If you don't get that error page, go with these; they are easy and fantastic.  You will need to download them, install them, add some code to your web.config (per instructions) open VWD and choose Website/Add Reference and check the new PayPal control listing, then go to Tools/Choose Toolbox Items and check the new PayPal controls, which will then populate the bottom of your toolbox.

    My thanks to PayPal for this comprehensive solution - I wish it had worked with my host! 

    Download PayPal's developer kits by logging in at www.paypal.com, then going to Merchant Services / PayPal Developer Network (near bottom of page) /  SDKs and Toolkits (left menu). The Developers’ Toolkits are enough for simple buttons, but there are Pro kits for payment on your site.

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

    THE SIMPLEST SOLUTION.

    3) For me, the perfect answer was IFRAMES.  Someone casually referenced it in a listing here (thanks - can't find you again in the long list of PayPal pleas!), but there was no explanation of how to do it.  So I went on a Google hunt!

    For any other newbies in need of a very easy solution to your trusted PayPal button on a .NET 2.0 page, all you do is:

    A) SAVE PAYPAL'S GENERATED BUTTON FORM AS AN INDEPENDENT HTML FILE IN YOUR VWD PROJECT. Name it, for example, paypalbutton.htm.

    - In your PayPal Form code, add target=_top to make sure PayPal opens in the full browser window, not inside of the IFRAME. You also could set target=_blank if you want PayPal to open in a new window.

    - Be sure to set the doc's body background color to transparent, just for aesthetics (CSS is best, body style='background-color: transparent' attribute works fine.)

    B) REFERENCE YOUR NEW PAYPAL HTML FILE IN AN IFRAME ON YOUR ASPX PAGE. Wherever you want the button to appear on the page, place your IFRAME code, indicating source=paypalbutton.htm (be directory specific, of course). You can set the height pretty small to fit the button, and set the width however long you need to be able to align the button left or right on your page.

    - Be sure to set the IFRAME for allowtransparency=true for aesthetics

    That's it! I found this through http://dotnetjunkies.com/WebLog/adambeal/archive/category/2695.aspx and fooled around with it until it was consistent in Netscape, IE and Firefox. Thanks, Adam.

    Hope this saves someone else a full day of trial and error!  Does anyone know of any security issues with this approach? dma

    Friday, October 20, 2006 10:32 PM

All replies

  • User362990094 posted
    Re the wonderful PayPal Developer controls 
    You will need to download them, install them, add some code to your web.config (per instructions) open VWD and choose Website/Add Reference and check the new PayPal control listing, then go to Tools/Choose Toolbox Items and check the new PayPal controls, which will then populate the bottom of your toolbox.
    One more step!  You'll also need to upload the PayPal control dll file from your computer to your Web site's Bin folder.
    Saturday, October 21, 2006 1:41 PM
  • User-1041416522 posted

    Hi,

    This is exactly what I am looking for. I downloaded the Paypal dll  and add the Dll in my visual studio.

    Can you show me a sample code behind in VB.

     I appreciate your help.

    Thanks,

    Arnold

    Thursday, May 10, 2007 4:27 PM
  • User-1329334484 posted

    I can not find this API, can you send me the exact link? they offer some paid service...

    i have placed the form html code, but it does not work with Ajax... this is the code,which does not work with ajax:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="myemail">
    <input type="hidden" name="item_name" value="Item name">
    <input type="hidden" name="item_number" value="Item ID">
    <input type="hidden" name="amount" value="12.00">
    <input type="hidden" name="buyer_credit_promo_code" value="">
    <input type="hidden" name="buyer_credit_product_category" value="">
    <input type="hidden" name="buyer_credit_shipping_method" value="">
    <input type="hidden" name="buyer_credit_user_address_change" value="">
    <input type="hidden" name="no_shipping" value="0">
    <input type="hidden" name="no_note" value="1">
    <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/btn_paynowCC_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

     

    Monday, September 10, 2007 11:19 PM
  • User-1254308814 posted

    <script type="text/javascript">
    function moveDivOut()
    {
         var inner = document.getElementById('innerDiv');
         var outer = document.getElementById('outerDiv');
         var innerHtml = inner.innerHTML;
         inner.innerHTML = "";
         outer.innerHTML = innerHTML;
    }
    </script>
    ...<body onload="moveDivOut();">
    <div id="outerDiv"></div> <!-- Keep this div up here so the content doesn't shift down -->
    <!-- Server Form -->
    <form runat="server" id="form1">
    <div id="innerDiv">
        <!-- Create Buy Now buttons from an xml or database storage and bind them to a listview-->
       <!-- HTML forms listview and form code not included -->
    .....
        <form .....></form>  ...
        <form .....></form>  ...
        <form .....></form>  ...
        <form .....></form>  ...
    ......
    </div>
    </form>

    This is the easiest way to get the design time binding for buy now buttons.

    Tuesday, April 15, 2008 9:55 PM
  • User2077096843 posted

     These are all hacks. Here's the ASP.NET 2.0 solution to this problem:

     

    http://www.codersbarn.com/post/2008/03/Integrate-PayPal-Checkout-Button-with-ASPNET-20.aspx  

    Tuesday, May 6, 2008 1:21 AM
  • User524842929 posted

    Got a single ASP.NET Server control will do everything to integrate PayPal payment to your ASP.NET Website once you simply drag and drop the control to your aspx page. It is ASP.NET PayPal Control for Website Payments Standard. Very easy to use. Rich design time wizard and strong set of API to customize programmatically. Encrypted Website Payments Button can be generated on the fly. Not only that, the control can capture IPN/PDT and fire IPN server side events where all IPN data is available from it's event argument object. Same for PDT.

    Here is the link: http://www.spicelogic.com/Products/ASP-NET-PayPal-Control-for-Website-Payments-Standard-4

    It works in Shared Hosting environment, very easy to use. IPN / PDT can be handled too like handling server side events.

    Wednesday, May 14, 2008 3:52 AM
  • User-672208662 posted

    I'm sorry, but this seems very much like a hack to me as well.

    I acknowledge this issue is a bit of a thorn in the side of ASP.NET web forms. But I've come up with two approaches that seems less "hacky" to me:

    http://www.softcircuits.com/Blog/post/2009/01/22/Implementing-Non-ASPNET-Posts-in-ASPNET.aspx

    and

    http://www.softcircuits.com/Blog/post/2010/02/14/Quick-and-Dirty-Buy-Now-Buttons-in-ASPNET.aspx

    The one that makes most sense depends on your requirements. Note that these are simply Buy-Now buttons I'm discussing. For anything more involved, you should either delve fully into the PayPal ecommerce API or write your own.

    Sunday, February 14, 2010 1:52 PM
  • User1021557662 posted

    I'm working through some Pay Pal Button issues as well. I've converted the code over to javascript to accomadate another problem, but now cannot get the link to open in a new window when clicked. Any tips?

    Here is the code:

    <input type="hidden" value="_s-xclick" name="cmd" /> <input type="hidden" value="R9ANYYFTZA9" name="hosted_button_id_NON" id="hosted_button_id_NON" />
    <p><a href="javascript:theForm.__VIEWSTATE.value='';theForm.encoding='application/x-www-form-urlencoded';document.getElementById('hosted_button_id_NON').name='hosted_button_id';theForm.action='https://www.paypal.com/cgi-bin/webscr';theForm.submit();"><img border="0" alt="" src="images/btn-buy-now.gif" /></a> <img height="1" border="0" width="1" src="images/btn-buy-now.gif" alt=" Non-Caffeinated" /></p></div>

    Friday, February 26, 2010 9:54 AM
  • User1280950372 posted

    The following worked for me, mainly because I can't stand using JavaScript:

    <div style="text-align: center; vertical-align: middle;">
        <asp:HyperLink ID="[URL provided by PayPal]"
            runat="server">
            <asp:Image ID="imgPayPal" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif"
                runat="server" />
        </asp:HyperLink>
    </div>
    


     

    Tuesday, March 2, 2010 4:10 PM
  • User-1211565148 posted

    Hi,

    Like all of us, I was stuck by the fact you need a form tag for the PayPal button to work, which is impossible to insert in an ASP.NET page because of the enclosing ASP.NET standard form tag.

    My solution was to create an .aspx web form, but to uncheck the Place code in separate file check box of Add new item dialog box. I ended with a page which works basically like an ASP classic page (remember ASP classic, when we were young?). This way I can do exactly what I want in this page.

    In my case, the order is built in a regular ASP.NET page, this particular page being a confirmation step before proceeding to PayPal.

    Laurent

    Friday, May 28, 2010 5:05 AM
  • User690501615 posted

    Good solutions but the second will only work if you have 1 paypal button on the page. In the case where you have multiple buttons this will not work since it posts the entire form and the Paypal cart handles this by adding only the last item it comes to from the form post. 

    A solution that works better is to add the hidden inputs to the page and write a javascript function to set the values of the hidden fields and post the form. This drastically reduces the button code and overcomes the multiple button issue.


    This is the hidden inputs added to the webform

    <body>
    <form id="Form1" runat="server">
    <input value="1" type="hidden" name="add"> 
    <input value=_cart type="hidden" name="cmd"> 
    <input value="enquiries@friaryvintners.co.uk" type="hidden" name="business"> 
    <input value="" type="hidden" name="item_name"> 
    <input value="" type="hidden" name="item_number"> 
    <input value="" type="hidden" name="amount"> 
    <input value="1" type="hidden" name="no_note"> 
    <input value="GBP" type="hidden" name="currency_code"> 
    <input value="PP-ShopCartBF" type="hidden" name="bn">

     <body>

    <form id="Form1" runat="server">
    <input value="1" type="hidden" name="add"> 
    <input value=_cart type="hidden" name="cmd"> 
    <input value="email@mail.com" type="hidden" name="business"> 
    <input value="" type="hidden" name="item_name"> 
    <input value="" type="hidden" name="item_number"> 
    <input value="" type="hidden" name="amount"> 
    <input value="1" type="hidden" name="no_note"> 
    <input value="GBP" type="hidden" name="currency_code"> 
    <input value="PP-ShopCartBF" type="hidden" name="bn">

    Javscript function added to the header:
    <script type="text/javascript">
    function sendPP(item_name,item_number,amount){
       Form1.item_name.value = item_name;
       Form1.item_number.value = item_number;
       Form1.amount.value = amount;
       Form1.__VIEWSTATE.value='';
       Form1.encoding='application/x-www-form-urlencoded';
       Form1.action='https://www.paypal.com/cgi-bin/webscr';
       Form1.submit();
    }
    </script>

    Amended Paypal button code:

    <a href="javascript:sendPP('Item name here','Item number here','price');"><img border=0 src="[your_site_URL]/images/buy_now.jpg"></a>


    Wednesday, September 29, 2010 6:05 AM
  • User293550750 posted
    Thank you very much. The iframe approach worked perfectly.
    Friday, March 25, 2011 9:31 AM