follow the steps:---
1) The first step is to install the plugin by editing
grails-app/conf/BuildConfig.groovy. Add entry similar to below in the plugins section:
grails.project.dependency.resolution = {
plugins {
...
compile ":paypal:0.6.8"
}
}
2) To configure, just edit grails-app/conf/Config.groovy. :-
environments {
production {
grails.paypal.server = "https://www.paypal.com/cgi-bin/webscr"
grails.paypal.email = "merchant@grails.asia"
grails.serverURL = "http://store.grails.asia"
}
development {
grails.paypal.server = "https://www.sandbox.paypal.com/cgi-bin/webscr"
grails.paypal.email = "merchant_test_grails@paypal.com"
grails.serverURL = "http://localhost:8080/sample"
}
}
3) Create Domain Class:---
class ProductItem {
String name
BigDecimal price
static constraints = {
name(blank:false, nullable:false, unique: true)
price(blank:false, nullable:false)
}
}
import org.grails.paypal.Payment
class ProductPurchase {
SystemUser user
ProductItem item
Payment payment
boolean completed = false
}
4) Create a Buy/Purchase Filter. For example, create the filter grails-app/conf/myfilters/PurchaseFilters.groovy with this code:
class PurchaseFilters {
def filters = {
all(controller:'paypal', action:'buy') {
before = {
}
after = { Map model ->
def user = SystemUser.get(request.payment.buyerId)
def item = ProductItem.findByName(request.payment.paymentItems[0].itemName)
new ProductPurchase( user:user, payment:request.payment, item:item).save()
}
afterView = { Exception e ->
}
}
}
}
6) Create a Purchase Completed Filter. For example, create the filter grails-app/conf/myfilters/PurchaseCompletedFilters.groovy with this code:
class PurchaseCompletedFilters {
def filters = {
all(controller: 'paypal', action: '(success|notifyPaypal)') {
before = {
}
after = { Map model ->
def payment = request.payment
if(payment && payment.status == org.grails.paypal.Payment.COMPLETE) {
def purchase = ProductPurchase.findByPayment(payment)
if ( !purchase.completed ) {
purchase.completed = true
}
}
}
afterView = { Exception e ->
}
}
}
}
7) create buy button in gsp :----
/<paypal:button
itemName="${item.name}"
itemNumber="${item.name}"
discountAmount="${0}"
amount="${item.price}"
buyerId="${user.id}"/>