Search code examples
grailsstripe-paymentsgrails-plugin

Using the Grails Stripe plugin


I'm using Stripe grails plugin in my application and I'm getting the below error:

Class:groovy.lang.MissingPropertyExceptionMessage:No such property: Stripe for class: com.myApp.app.SubscriptionRequestController

Here is my action:

def charge(String stripeToken, Double amount) {
    Stripe.apiKey = grailsApplication.config.grails.plugins.stripe.secretKey
    def amountInCents = (amount * 100) as Integer
    def chargeParams = [
        'amount': amountInCents,
        'currency': 'usd',
        'card': stripeToken,
        'description': 'customer@sample.org'
    ]

    def status
    try {
        Charge.create(chargeParams)
        status = 'Your purchase was successful.'
    } catch(CardException) {
        status = 'There was an error processing your credit card.'
    }

    redirect(action: "confirmation", params: [msg: status])
    return
}

i'm also getting the below error since i installed the plugin when i remove it i don't see it, it occurs while trying to access or refresh any view :

java.lang.RuntimeException: It looks like you are missing some calls to the r:layoutResources tag. After rendering your page the following have not been rendered: [head] 

Solution

  • Try this:

    in your main layout file e.g.: main.gsp, have the two additional both in body and head. Also, loads the stripe-v2 manually. No need to add it in web-app/js as the plugin itself already has it.

    <html>
        <head>
            <g:javascript src="stripe-v2.js" />
            <r:layoutResources/>
        </head>
        <body>
            <g:layoutBody/>
            <r:layoutResources/>
        </body>
    </html>
    

    in config.groovy add:

    grails.resources.modules = {
        stripe {
            dependsOn 'jquery'
            resource url:'/js/stripe-v2.js', disposition: 'head', exclude:'minify'
        }
    }
    

    Sample gsp (taken from the docs) but i added payment-errors as the source use it:

    <stripe:script formName="payment-form"/>
    <g:form controller="checkout" action="charge" method="POST" name="payment-form">
        <div class="payment-errors"></div>
        <div class="form-row">
            <label>Amount (USD)</label>
            <input type="text" size="20" autocomplete="off" id="amount" name="amount"/>
        </div>
    
        <stripe:creditCardInputs cssClass="form-row"/>
    
        <button type="submit">Submit Payment</button>
    </g:form>
    

    I think the plugin itself did not support the current implementation of Grails Asset Pipeline.I think it is not compatible for grails 2.4.3 and above.