Unofficial Stripe.JS wrapper for Opal

stripe-opal provides credit card payment capabilities to opal by wrapping Stripe.js and providing a nice ruby syntax for dealing with card payments.

Note

This is an unofficial Gem and I don't work for Stripe. The gem is maintained, but not officially supported or endorsed by Stripe.

Getting Started

Usage

Add this to app/main/config/dependencies.rb for your Volt Project:

javascript_file "https://js.stripe.com/v2/"

OR, if you are writing a static app that does not use Volt, but uses Opal:

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>

THEN

Make this HTML form...

<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>

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

And run payments like this:


StripeOpal::Card
  .get_token('#payment-form') # Notice the ID on the form above?
  .then { |token| "Pass the `token.id` to a Volt::Task or AJAX call" }
  .fail { |error|  "Tell the user they put bad info in." }

If you are developing a Volt Framework app, it's best to put the code above in a controller method

def pay_from_controller
  StripeOpal::Card
    .get_token('#payment-form') # Notice the ID on the form above?
    .then { |token| "Pass the `token.id` to a Volt::Task or AJAX call" }
    .fail { |error|  "Tell the user they put bad info in." }
end

and add e-submit="pay_from_controller" to the <form> tag.

Installation

Install stripe-opal from RubyGems:

$ gem install stripe-opal

Or include it in your Gemfile for Bundler:

gem 'stripe-opal'

License

(The MIT License)

Copyright (C) 2015 by Rick Carlino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.