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 Attachments
30713 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Thanks for this article, Xinsheng Chen, quite... Juan Fernández May 14, 2010 3:31 AM
Ok I have done the paypal transaction, now i... Manikandan S July 28, 2011 5:48 AM
hi, can u please help using code sample Tahir Noor Khaliq August 11, 2015 12:21 AM
Thanks It was helpful Aravinth Kumar April 12, 2014 3:11 AM

Thanks for this article, Xinsheng Chen, quite interesting
Posted on 5/14/10 3:31 AM.
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
Posted on 7/28/11 5:48 AM in reply to Juan Fernández.
Thanks It was helpful
Posted on 4/12/14 3:11 AM.
hi, can u please help using code sample
Posted on 8/11/15 12:21 AM in reply to Mani kandan.