Integrating PayPal into Liferay

By Xinsheng Chen, xinsheng_chen@yahoo.com

Introduction #

This article describes a simple way to integrate PayPal "Buy-now" button into a Liferay Portal application. It is called "Instant Payment Notification ("IPN")" integration in PayPal. In this way of integration, a form is embedded in a page of the seller's Liferay Portal site. When a user clicks on the submit button, a post request is sent to PayPal site. The user performs payment steps on the PayPal site. When the transaction is done, the PayPal site calls an IPN handler (an HTTP request) on a seller's server, sending the seller information about the payment transaction. The seller's server machine will do verification and validation of the payment.

Implementation #

Here I would only describe the steps to complete this integation at PayPal's sandbox site. The steps for integration at PayPal site are very similar.

Create a PayPal Sandbox Account #

Go to https://developer.paypal.com/ and create an log-in account at PayPal's sandbox site.

Create a Test Business Account #

Log in PayPal's sandbox site and create a test business account. It is for your imaginery store.

Generate HTML Code for a Form with the "Buy Now" Button #

Go to the "Profile" page. Follow the "Create a New Button" link and generate code for the "Buy Now" button form.

Add the Form Code into your Liferay Portal Page #

You may need to coustomize the form code for your situation. For example, you may want to add a success-return url and a transaction-cancel url in the form.

Write the IPN Handler #

The IPN handler is also called the IPN listener. In the sample code at PayPal's site, it is a jsp file.

Copy this sample code and paste it into a "ROOT/html/yourfolder/listener.jsp" file (I am using liferay-portal-tomcat-5.5-4.3.1). Customize it according to your needs.

Register your IPN Handler url at PayPal Sandbox as http://yourIP/html/yourfolder/listener.jsp #

After the payment transaction is finished, PayPal site will call this IPN handler as an HTTP post request. You should add your custom code in this "listener.jsp" file to process the payment information from PayPal.

Testing #

(1) Test with the IPN simulator in the Sandbox

(2) Test by clicking on the "Buy Now" button and finish the whole payment process

Tips #

After you get the return parameter values from Paypal, trim the string values before you do comparison.

When you are testing in the whole payment process, PayPal sandbox site requires real credit card numbers.

0 附件
30715 查看
平均 (0 票)
满分为 5,平均得分为 0.0。
评论
讨论主题回复 作者 日期
Thanks for this article, Xinsheng Chen, quite... Juan Fernández 2010年5月14日 上午3:31
Ok I have done the paypal transaction, now i... Manikandan S 2011年7月28日 上午5:48
hi, can u please help using code sample Tahir Noor Khaliq 2015年8月11日 上午12:21
Thanks It was helpful Aravinth Kumar 2014年4月12日 上午3:11

Thanks for this article, Xinsheng Chen, quite interesting
在 10-5-14 上午3:31 发帖。
Ok I have done the paypal transaction, now i want to get all the values like product name, price which I sent it to paypal.
How can I get those values in my jsp files?
My jsp path is
\liferay-portal-6.0.6\tomcat-6.0.29\webapps\ROOT\html\portlet\book\myjsp.jsp
在 11-7-28 上午5:48 发帖以回复 Juan Fernández
在 14-4-12 上午3:11 发帖。
hi, can u please help using code sample
在 15-8-11 上午12:21 发帖以回复 Mani kandan