Created
September 8, 2012 17:37
-
-
Save coderforhire/3677733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@subscription = Subscription.new(params[:subscription]) | |
@user = User.new(params[:user]) | |
if @user.save | |
redirect_to "http://google.com" | |
# @subscription.update_attributes[:user_id => @user.id] | |
# redirect_to @subscription, :notice => "Thank you for subscribing!" | |
else | |
respond_to do |format| | |
format.html { render action: "new", notice: @user.errors } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/assets/javascripts/subscriptions.js.coffee | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="account-container register"> | |
<div class="content clearfix"> | |
<h1>Create Your Account</h1> | |
<div class="login-fields"> | |
<%= form_for(@subscription) do |f| %> | |
<%= f.hidden_field :stripe_card_token %> | |
<% if @subscription.stripe_card_token.present? %> | |
Credit card has been provided. | |
<% else %> | |
<%= text_field_tag :card_number, nil, name: nil, :placeholder => "Card Number" %></br> | |
<%= text_field_tag :card_code, nil, name: nil, :placeholder => "CVV Code" %></br> | |
<h2>Expiration:</h2> | |
<%= 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> | |
<%= text_field :user, :email, :placeholder => "Email" %></br> | |
<%= password_field :user, :password , :placeholder => "Password" %></br> | |
<%= password_field :user, :password_confirmation, :placeholder => "Confirm Password" %></br> | |
<% end %> | |
<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 %> | |
<% @user.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