Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created September 26, 2012 18:39
Show Gist options
  • Save coderforhire/3789742 to your computer and use it in GitHub Desktop.
Save coderforhire/3789742 to your computer and use it in GitHub Desktop.
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require twitter/bootstrap
//= require jquery
//= require jquery-ui
//= require jquery_ujs
// *= require_tree .
$(document).ready(function(){
});
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()
subscription =
setupForm: ->
$('#new_subscription').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#subscription_stripe_card_token').val(response.id)
$('#new_subscription')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
<div class="account-container register">
<div class="content clearfix">
<h1>Create Your Account</h1>
<div class="login-fields">
<%= form_for(@subscription) do |f| %>
<%= text_field_tag :card_number, nil, name: nil, :placeholder => "Card Number" %></br>
<%= text_field_tag :card_code, nil, name: nil, :placeholder => "CVV Code" %></br>
<h3>Expiration:</h3>
<%if @user.errors.any? %>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li></br>
<% end %>
<% end %>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %></br>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %></br>
<h3>Plan:</h3>
<%= f.select :plan, {"19.99/mo" => '1', "25.99/mo" => '2', "59.99/mo" => '3'}, :selected => params[:plan] %>
<%= text_field :user, :email, :placeholder => "Email" %></br>
<%= f.hidden_field :stripe_card_token %>
<%= password_field :user, :password , :placeholder => "Password" %></br>
<%= password_field :user, :password_confirmation, :placeholder => "Confirm Password" %></br>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<% if @subscription.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@subscription.errors.count, "error") %> prohibited this purchase from being saved:</h2>
<ul>
<% @subscription.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div> <!-- /login-fields -->
<div class="login-actions">
<span class="login-checkbox">
<input id="Field" name="Field" type="checkbox" class="field login-checkbox" value="First Choice" tabindex="4" />
<label class="choice" for="Field">I have read and agree with the Terms of Use.</label>
</span>
<%= f.submit "Get me a database.", :class => "button btn btn-primary btn-large" %>
<% end %>
</div>
</div> <!-- /content -->
</div> <!-- /account-container -->
<!-- Text Under Box -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment