If you are developing an E-Business web application , where you have to provide online payment solution to your customer then PayPal is one of the most secure , faster and easier way to make payment online .
In this blog, we will have a basic idea that how easily you can integrate PayPal functionality in your Liftweb project using Scala .
We are assuming that you are aware with the basics of LiftWeb and Scala .
Lift provides integration support for both PDT(Payment Data Transfer) and IPN(Instant Payment Notification) . You do not need to add any extra functionality to handle response from PayPal .
Payment Data Transfer :

PDT(Payment Data Transfer) provides you some transaction details to be displayed to buyer , when page is redirected after completing transaction . To use PDT , you must enable AUTO RETURN .
IPN(Instant Payment Notification):

Once transaction is complete , IPN(Instant Payment Notification) sends a notification to your server with all specific details about completed transaction .
PayPal Environment setup :
Before implementing PayPal in your application , you must setup PayPal environment .
- Go To https://developer.paypal.com
- Set up both a “preconfigured seller” and “preconfigured buyer” account in the sandbox.
- Log into the sandbox as the seller account you just created, and enable Auto Return in the selling preferences.
- Enable PayPal Data Transfer (it’s on the same screen as the Auto Return configuration).
- Edit the IPN callback URL and enable IPN.
LiftWeb Environment setup :
- Add PayPal repository in your build.sbt
"net.liftmodules" % "paypal_2.9.2" % "2.5-SNAPSHOT-1.2-SNAPSHOT"
- Let’s create PayPal Handler class which implements two traits PaypalIPN and PaypalPDT.
object PaypalHandler extends PaypalIPN with PaypalPDT with Loggable { import PaypalTransactionStatus._ val paypalAuthToken = "yourtokengoeshere" def pdtResponse = { case (info, resp) => info.paymentStatus match { case Full(CompletedPayment) => DoRedirectResponse.apply("/paypal/success") case _ => DoRedirectResponse.apply("/paypal/failure") } } def actions = { case (CompletedPayment,info,_) => //Update your transaction detail case (FailedPayment,info,_) => //Update your transaction detail case (status, info, resp) => } } - Now add following lines in your Boot.Scala to initialize the PaypalRules object that contains configuration .
........... PaypalRules.init PaypalHandler.dispatch.foreach(LiftRules.dispatch.append(_)) ...........
- Now add Buy Now button to instantiate the transaction process .
Compose the BuyNowSnippet with your snippet:
class TrasanctionSummary extends BuyNowSnippet { ......... override val values = Map( "business" -> "test@business.com", "item_number" -> reference, "item_name" -> ("Auction Order: " + reference)) ................. }Above lines are required to implement the button .
- Finally add PayPal response pages to the SiteMap .
.............. Menu("Transaction Complete") / "paypal" / "success" >> LocGroup("public") >> Hidden, Menu("Transaction Failure") / "paypal" / "failure" >> LocGroup("public") >> Hidden, ...........






Change PaypalHandler.dispatch.foreach([LiftRules.dispatch.append(_))
for
PaypalHandler.dispatch.foreach(LiftRules.dispatch.append(_))
Good article
Thanks
Hi Jose ,
Thanks for pointing this out . We have fixed this .