HOW TO: Add a generated PayPal Button?

Last post 11-17-2008 11:37 AM by rtpHarry. 5 replies.

Sort Posts:

  • HOW TO: Add a generated PayPal Button?

    11-17-2008, 10:37 AM
    • Member
      30 point Member
    • IgorV
    • Member since 04-04-2007, 12:43 PM
    • Posts 179

    I've trying to create a simple store front using the PayPal Web Payments Standard and so far so good until I got to the button.

    The generated button uses HTML input button and fields and then when I add it to my .aspx page it won't work as intended (doesn't work at all).  The button shows but doesn't perform the function.

     

    I'm wondering is becuase it uses a seperate form for each button?

    Code:

     

    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart"/>
    <input type="hidden" name="business" value="email@hotmail.com"/>
    <input type="hidden" name="lc" value="CA"/>
    <input type="hidden" name="item_name" value="Rubber band"/>
    <input type="hidden" name="item_number" value="4005"/>
    <input type="hidden" name="amount" value="18.00"/>
    <input type="hidden" name="currency_code" value="CAD"/>
    <input type="hidden" name="add" value="1"/>
    <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest"/>
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt=""/>
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
    </form>
     
  • Re: HOW TO: Add a generated PayPal Button?

    11-17-2008, 10:58 AM
    • All-Star
      36,220 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,819

     Solution 1:

    Use this code to redirect to the url with your data injected:

     

            // two: redirect to paypal to make secure payment
            StringBuilder sb = new StringBuilder();
            sb.Append("cmd=_xclick&");
            sb.Append(@"business=insertpaypal@email.here.com&");
            sb.Append("no_shipping=1&");
            sb.Append("currency_code=GBP&");
            sb.Append("lc=GB&");
            sb.Append("bn=PP-BuyNowBF&");
            sb.Append(@"item_name=Web Payment&");
            sb.Append(@"item_number=" + txtYourName.Text + " " + txtPostCode.Text + "&");
            sb.Append("amount=" + double.Parse(txtAmount.Text).ToString());
    
            Response.Redirect(@"https://www.paypal.com/cgi-bin/webscr?" + sb.ToString());
      
  • Re: HOW TO: Add a generated PayPal Button?

    11-17-2008, 11:03 AM
    • All-Star
      36,220 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,819

    Solution 2:

    Use this class from an example website to dynamically generate the form page and submit it.

    filename: ~/App_Code/RemotePost.cs

     

    using System.Collections.Specialized;
    using System.Web;
    
    /* Usage example
     * From: http://www.jigar.net/articles/viewhtmlcontent78.aspx
     * 
    RemotePost myremotepost = new RemotePost();
    myremotepost.Url = "http://www.jigar.net/demo/HttpRequestDemoServer.aspx";
    myremotepost.Add("field1", "Huckleberry");
    myremotepost.Add("field2", "Finn");
    myremotepost.Post(); 
     * */
    
    /// <summary>
    /// Summary description for RemotePost
    /// </summary>
    public class RemotePost
    {
        private NameValueCollection Inputs = new NameValueCollection();
    
        public string Url = "";
        public string Method = "post";
        public string FormName = "form1";
    
        public void Add(string name, string value)
        {
            Inputs.Add(name, value);
        }
    
        public void Post()
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("&lt;html><head>");
            HttpContext.Current.Response.Write(string.Format("&lt;/head><body onload=\"document.{0}.submit()\"&gt;", FormName));
            HttpContext.Current.Response.Write(string.Format("&lt;form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
    
            for (int i = 0; i < Inputs.Keys.Count; i++)
            {
                HttpContext.Current.Response.Write(string.Format("&lt;input name=\"{0}\" type=\"hidden\" value=\"{1}\"&gt;", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
            }
    
            HttpContext.Current.Response.Write("&lt;/form>");
            HttpContext.Current.Response.Write("&lt;/body></html>");
            HttpContext.Current.Response.End();
    
        }
    }
     
  • Re: HOW TO: Add a generated PayPal Button?

    11-17-2008, 11:04 AM
    • All-Star
      36,220 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,819

     Note: The code pasting tool on these forums has altered the < and > to &lt; &gt;

     

    You should probabaly just grab it direct from the site

  • Re: HOW TO: Add a generated PayPal Button?

    11-17-2008, 11:21 AM
    • Member
      30 point Member
    • IgorV
    • Member since 04-04-2007, 12:43 PM
    • Posts 179

    Thanks for the info but that link doesn't work you provided.

     As for the code input how would it work?  Should I just put it in on page load event or under a button event?  If it's button event how would I do that since the pre-generated code is HTML button.

    If you could elaberate a bit I would appreciate it.

  • Re: HOW TO: Add a generated PayPal Button?

    11-17-2008, 11:37 AM
    Answer
    • All-Star
      36,220 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,819

     Hey,

    The link is a bit sketchy yeah! I just tried and it 404'd then refresh and it works.

    Try it again or look in the Google Cache



    With regards to running any of the code I posted you would scrap the <form> generated by the paypal website and add a new <asp:Button> into your website. Then add a click handler to this and write your code.
Page 1 of 1 (6 items)