Skip to main content
07 Aug 2012

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 integration 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 imaginary 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 customize 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

Now you can register your IPN Handler url at PayPal Sandbox

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.

- By

Xinsheng Chen
Architect at CIGNEX, USA Office