Using Stripe with Grails

You can use whatever you want for the amount. Enter it as you normally would in dollars like 12.99 for example. The controller converts this to an integer of cents since Stripe deals in cents. If goes well, you should see the confirmation page with the success message! If something goes wrong and you receive the error message, you can comment out the try/catch block around the Charge.create(chargeParams) to see the actual error message from the Stripe API. Once you have successfully submitted the form and received the confirmation message, go to your Stripe account and click on Payments to verify that it shows up!

This post is just barely touching the surface of the Stripe capabilities! We did a one-time charge here, but you can do all sorts of stuff with the Stripe API with Groovy like subscriptions / plans for recurring payments. You can also do standard stuff like issue refunds or coupons. Take a look at the Java API documentation for more details.

Well that concludes my walk-through of using Stripe for processing credit cards in a Grails application. I hope you found this post interesting and consider trying out my plugin! Here are links to the source for the plugin and the plugin portal page.

Page 2 of 2 | Previous page

7 comments on this post.
  1. groovylearner:

    var form$ = $(“#payment-form”)
    When above statement gets executed, form$ holds entire payment-form and payment-form has credit card number. So I am unable to understand how we are avoiding submission of credit card number to server. Can you please elaborate

  2. Adam Kruszewski:

    We don’t. It is an error which also exists in Stipe documentation (from which it was probably taken). You should have a separate form for your data and for CC info or clean the CC info before submitting (on the other hand I think the whole Stripe solution uses too much JavaScript for me to feel comfortable, but those are just my 0.02$).

    Cheers,
    a.

  3. Bobby Warner » Using Stripe with Grails Continued:

    [...] my last post I introduced using Stripe with Grails to process credit cards. I guess I should have waited to [...]

  4. Bob Herrmann:

    The input elements dont have the Name attribute specified. If a field is not named using name, the field and its value will not be passed for server-side processing.

  5. An Army of Solipsists » Blog Archive » This Week in Grails (2011-52), and the year in review:

    [...] Using Stripe with Grails [...]

  6. » Blog Archive:

    [...] Using Stripe with Grails [...]

  7. Sebastian Grant:

    @Bob Herrmann – by the looks of the code, this plugin is utilising AJAX to do the posting:

    /*********************/

    Stripe.createToken({
    number: $(‘.card-number’).val(),
    cvc: $(‘.card-cvc’).val(),
    exp_month: $(‘.card-expiry-month’).val(),
    exp_year: $(‘.card-expiry-year’).val()
    },

    /*********************/

    Although, for performance, I would suggest using IDs for the inputs as opposed to classes.

Leave a comment





*