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 Anexos
30725 Visualizações
Média (0 Votos)
A média da avaliação é 0.0 estrelas de 5.
Comentários
Respostas do tópico Autor Data
Thanks for this article, Xinsheng Chen, quite... Juan Fernández 14 de Maio de 2010 03:31
Ok I have done the paypal transaction, now i... Manikandan S 28 de Julho de 2011 05:48
hi, can u please help using code sample Tahir Noor Khaliq 11 de Agosto de 2015 00:21
Thanks It was helpful Aravinth Kumar 12 de Abril de 2014 03:11

Thanks for this article, Xinsheng Chen, quite interesting
Postado em 14/05/10 03: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
Postado em 28/07/11 05:48 em resposta a Juan Fernández.
Thanks It was helpful
Postado em 12/04/14 03:11.
hi, can u please help using code sample
Postado em 11/08/15 00:21 em resposta a Mani kandan.