Tuesday, October 27, 2009

PayPal Buy Now button on an asp.net page

This problem has annoyed for a very long time, you can add a paypal buy now button to any website, you login to your paypal account and fill in a few boxes and presto out spits a few lines of html to get you going.


<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="9225183">
<input type="image" src="https://www.paypal.com/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.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>




Which when added to my page directly (or via my CMS) just doesn't work - I won't go into the reasons why right now.

After many hours of trying to find a simple solution so my clients are able to add these adhoc buttons via the CMS, I realised I was trying to over complicate things by writing loads of code and generally wasting precious development time.
Taking a few steps back and going throguh the whole process again made me realise that when you create these buttons on paypal there is a second tab above the html window that says 'Email' when you view this tab you get this;

https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=123456789

which you can email out to people to pay for an item - can you see what it is yet?


SOLUTION:

Simply add an href using the 'Email' link with the paypal button inside...

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=9225183" target="_blank"> <img border="0" alt="" src="https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" /></a>

Sometime the answer is staring you right in the face.

1 comment:

Jonathan Wood said...

I've written a more thorough explanation of the issues related to placing a PayPal buy-now button on an ASP.NET page at http://www.blackbeltcoder.com/Articles/ecommerce/quick-and-dirty-buy-now-buttons-in-asp-net. You may find that interesting.