Easy steps for Stripe Integration with Grails.

This blog will help you to integrate stripe in your grails application.

Step 1) Create an account on Stripe.

Step 2) Get your secretKey and publishableKey from the Stripe Account .


stripAccountDetails

and set the api key in Config.groovy

grails.plugins.stripe.secretKey='sk_test_5ojiNjVDNr7z'
grails.plugins.stripe.publishableKey='pk_test_pSCLOmE'

Step 3) Include stripe.js on the application

Step4) Add these lines on your pom.xml

<dependency>
  <groupId>com.stripe</groupId>
  <artifactId>stripe-java</artifactId>
  <version>1.7.1</version>
</dependency>

or manually add following jars on your lib

1) stripe-java-latest.jar.

step 5) Now you need to include form on your page. Ref

<form action="" method="POST" id="payment-form">
  <span class="payment-errors"></span>

  <div class="form-row">
    <label>
      <span>Card Number</span>
      <input type="text" size="20" data-stripe="number"/>
    </label>
  </div>

  <div class="form-row">
    <label>
      <span>CVC</span>
      <input type="text" size="4" data-stripe="cvc"/>
    </label>
  </div>

  <div class="form-row">
    <label>
      <span>Expiration (MM/YYYY)</span>
      <input type="text" size="2" data-stripe="exp-month"/>
    </label>
    <span> / </span>
    <input type="text" size="4" data-stripe="exp-year"/>
  </div>
<div class="form-row">
    <label>
      <span>Amount</span>
      <input type="text" size="20" data-stripe="amount"/>
    </label>
  </div>

  <button type="submit">Submit Payment</button>
</form>

You can change form as your requirements.

Step 6)If all configuration was going well, on form,s submit button click, Stripe send a request to stripe server with card data and on response you get a Stripe token(if card is valid else send stripe card validation error message). Now this stripe token is used to make transaction through Stripe.

Step 7) On server side of your application you use following code to make your first Stripe request for making payment.

Stripe.apiKey = grailsApplication.config.grails.plugins.stripe.secretKey
Map chargeParams = ["amount":params.amount,"card":params.stripeToken]

Charge.create(chargeParams); 

For more information please follow the stripe documentation.