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 添付ファイル
30712 参照数
平均 (0 投票)
平均評価は0.0星中の5です。
コメント
コメント 作成者 日時
Thanks for this article, Xinsheng Chen, quite... Juan Fernández 2010/05/14 3:31
Ok I have done the paypal transaction, now i... Manikandan S 2011/07/28 5:48
hi, can u please help using code sample Tahir Noor Khaliq 2015/08/11 0:21
Thanks It was helpful Aravinth Kumar 2014/04/12 3:11

Thanks for this article, Xinsheng Chen, quite interesting
投稿日時:10/05/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
Juan Fernándezへのコメント。投稿日時:11/07/28 5:48
投稿日時:14/04/12 3:11
hi, can u please help using code sample
Mani kandanへのコメント。投稿日時:15/08/11 0:21