I’m working on the website of a restaurant that Sue’s friend owns. Recently, her friend wanted to add online order feature, and her preferred payment method was PayPal.
Though I’m a web developer with quite diverse experience, I haven’t done it. I mostly worked on large scale web sites, and PayPal was never an considered option there. It’s kind of fun and refreshing to work on small scale website where I have to look after the whole aspects, not just small part of big thing.
First, there is an ASP.NET MVC Storefront webcast in which Rob Conery talks about attaching paypal payment on the site. It’s very useful and fun to watch as his videos are always.
“Buy Now” button
The quick and easiest option is to add “Buy Now” button on the site and use IPN to verify that the payment has gone through.
The “Buy Now”‘s HTML code is quite straight forward.
It’s looks like this.
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="firstname.lastname@example.org"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="item_name" value="Teddy Bear"> <input type="hidden" name="amount" value="12.99"> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form>
I changed the action url to the sandbox one and the business to the sandbox test user for testing.
This is for real transaction, and you wouldn’t want to go live without any testing, especially with payment. It’ll probably break bad and bite you back. So you need to test it in the sandbox.
- Go to PayPal sandbox
- Create your developer account. It’s different from your real paypal account, so you have to create one even though you have a paypal account.
- Then create two test accounts, one is seller and the other is buyer.
Receiving payment notification
You would need to be notified when the payment is gone through. You can use PDT or IPN, or both. IPN makes a request to your webserver, so you can update the record. With PDT you get the notification instantly and can do any additional processing required and show the user a confirmation page. IPN is more reliable as PDT can break if the user’s machine breaks out during the processing.
With IPN, you can use IPN simulator. If you just use standard “buy now” button or cart, then choose “Web Accept” transaction type.
to be continued …