Plugins You can find out about all the publicly available Grails plugins.

Provides integration with Paypal's Instant Payment Notfication (IPN) system

  • Tags: paypal
  • Latest: 0.6.8
  • Last Updated: 17 July 2012
  • Grails version: 1.1 > *
  • Authors: Matthias Bohlen, (originally by Graeme Rocher, followed by Matt Stine)
3 votes
compile "org.grails.plugins:paypal:0.6.8"



This plug-in allows Grails applications to integrate with Paypal and its Instant Payment Notification (IPN) system.

A PayPalController is provided that has a "notifyPaypal" action which deals with responses from the PayPal IPN. In order for this to function you need to enable IPN in your PayPal Profile under Profile / Instant Payment Notification Preferences and provide PayPal with the URL you have mapped the "notify" action to.

In order for this plug-in to function you must configure the following settings in Config.groovy:

  • grails.paypal.server - The URL of the paypal server
  • - The email of the merchant account
  • grails.serverURL - The server URL for production


PayPal Plugin


To install this plug-in run:

grails install-plugin paypal

Version 0.6.5 renames the "notify" action of the controller to "notifyPaypal". Any end user code will need to be changed accordingly


This plug-in provides 3 new artefacts:

  • A PaypalController - a Grails controller that deals with PayPal requests and integrations with the PayPal Instance Payment Notification (IPN) system
  • A PaypalTagLib - a tag library that provides the ability to create PayPal "buy now" buttons
  • A Payment domain class - a domain class that is used to store information about Payments
To get started you need to configure PayPal server and merchant email address in Config.groovy as well as the grails server URL used for absolute links. For example:

environments {
  production {
     grails.paypal.server = "" = "[email protected]"
     grails.serverURL = ""	  // Beware this is an application-wide setting	
  development {
     grails.paypal.server = "" = "[email protected]"
     grails.serverURL = "http://812.99.101.131"				

With this done the next thing to do is to create a PayPal button. For example:

	itemName="iPod Nano"

The itemName, itemNumber, amount and buyerId are required. The buyerId can be a reference to an existing domain class id such as a User id. The transactionId is used in case you are resuming an existing Payment.

When the button is clicked the plugin will create and save a new instance of the org.grails.paypal.Payment class to track the order. The button will also send the IPN URL that PayPal should use to send notifications back.

In order for IPN to function correctly you must set the grails.serverURL setting in Config.groovy to a web facing domain or IP address (so that PayPal can do a post back)

Payment Tracking with Filters

A typical way to integrate with the PayPal plug-in is through the use of filters. The PayPal plug-in places the payment instance into the request when it has been created so a filter that executes after the PaypalController and integrate with it.

For example:

buyFilter(controller:"paypal", action:"buy") {
 after = {
      new IPodPayment(payment:request.payment, IPod.get(
paymentReceivedFilter(controller:'paypal', action:'(success|notifyPaypal)') {
  after = {
     def payment = request.payment
     if(payment && payment.status == org.grails.paypal.Payment.COMPLETE) {
         def payment = IPodPayment.findByPayment(request.payment)

Returning to several different domains from Paypal

Since 0.6.2 you can provide Paypal with a domain different from "grails.serverURL" just in case you need it. A typical case would be handling several domains with the same application, so your user follows where it started.

buyFilter(controller:"paypal", action:"buy") {
 before = {
    params.baseUrl = "/** whatever domain you want Paypal to return once the payment is done *//"