0

Folks,

I am looking to integrate a payment gateway on my Grails 2.3.10 website. Just beginning to scratch the surface on what does it take to do the same. I am broadly focused on 3 things

a. How do I send the right information to the gateway b. Once I have the approval, how do I store it on my system and then use that information to give the right access to "secured" content. c. Will the content be secured using "role" such as "PaidUser" or are other ways to secure the controllers ?

Any help with sample implementations/issues to deal with/just online info pointers for me to read & learn are very very welcome. Thank You.

uk1974
  • 107
  • 1
  • 7

1 Answers1

0

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}"/>
jaydip jadhav
  • 477
  • 4
  • 5