3 Usage - Reference Documentation
Authors: Bobby Warner
Version: 1.3
3 Usage
To use Stripe in a GSP, you will use the TagLib provided by the plugin. The TagLib will take care of processing the credit card details. You can also optionally have it completely generate the credit card form fields too.The first tag you will need is script. The formName attribute needs to match the name attribute on your <g:form> tag.<stripe:script formName="payment-form"/><stripe:creditCardInputs cssClass="form-row"/><!doctype html>
<html>
<head>
<meta name="layout" content="main"/>
<r:require module="application"/>
</head>
<body>
<h3>Checkout</h3> <stripe:script formName="payment-form"/> <g:form action="charge" method="POST" name="payment-form">
<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" class="submit-button">Submit Payment</button>
</g:form>
</body>
</html>package stripesampleimport com.stripe.model.Charge import com.stripe.exception.CardException;class CheckoutController { def index() {} def charge(String stripeToken, Double amount) { 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 } def confirmation(String msg) { [msg: msg] } }