Learning
Learning

Reputation: 20001

How to make paypal button work in asp.net webform

I am trying to find a way to add paypal donation button to asp.net webform, since it is wrapped around form which i cant add. Is there a way to add it. Or just a link button for the same.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="xxxx">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Upvotes: 0

Views: 751

Answers (1)

VDWWD
VDWWD

Reputation: 35524

There are a couple of things you can do.

Make a static HTML page with the form and use an Iframe on the aspx page.

<iframe src="paypal.html"></iframe>

Do the form post on a button click from code behind (code not tested, but there are many more examples here on SO as how to make a form post in code behind)

protected void Button1_Click(object sender, EventArgs e)
{
    using (WebClient client = new WebClient())
    {
        byte[] response = client.UploadValues("https://www.paypal.com/cgi-bin/webscr", new NameValueCollection()
        {
            { "cmd", "_s-xclick" },
            { "hidden", "xxxx" }
        });

        string result = Encoding.UTF8.GetString(response);
    }
}

You can try to make a link with the form values as a query string. There are references to this on various forums.

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=xxxx">PayPal</a>

And finally you could communicate with the PayPal API

https://developer.paypal.com/docs/api/

Upvotes: 2

Related Questions