-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] Adding creditcard payment #334
Changes from 1 commit
6205c72
1730d5a
88824bc
cd78851
f99a26b
5ee1b55
6a47ded
31aab64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ChargesController < ApplicationController | ||
def new | ||
end | ||
|
||
def create | ||
# Get the credit card details submitted by the form | ||
token = params[:stripeToken] | ||
|
||
# Create a Customer | ||
customer = Stripe::Customer.create( | ||
:source => token, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jup shouldn't copy paste I know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha is stripe using using the rocket hash in their docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that allows projects with older ruby to use stripe ad well I guess |
||
:plan => "value", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:email => current_user.email, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:quantity => User.count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h2>Thanks, you paid <strong>$5.00</strong>!</h2> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script type="text/javascript" src="https://js.stripe.com/v2/"></script> | ||
<%= form_tag charges_path, method: "POST", id: "payment-form" do %> | ||
<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> | ||
<% end %> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | ||
<script type="text/javascript"> | ||
// This identifies your website in the createToken call below | ||
Stripe.setPublishableKey('<%= ENV["STRIPE_PUBLIC_KEY"] %>'); | ||
// ... | ||
jQuery(function($) { | ||
$('#payment-form').submit(function(event) { | ||
var $form = $(this); | ||
|
||
// Disable the submit button to prevent repeated clicks | ||
$form.find('button').prop('disabled', true); | ||
|
||
Stripe.card.createToken($form, stripeResponseHandler); | ||
|
||
// Prevent the form from submitting with the default action | ||
return false; | ||
}); | ||
}); | ||
|
||
function stripeResponseHandler(status, response) { | ||
var $form = $('#payment-form'); | ||
|
||
if (response.error) { | ||
// Show the errors on the form | ||
$form.find('.payment-errors').text(response.error.message); | ||
$form.find('button').prop('disabled', false); | ||
} else { | ||
// response contains id and card, which contains additional card details | ||
var token = response.id; | ||
// Insert the token into the form so it gets submitted to the server | ||
$form.append($('<input type="hidden" name="stripeToken" />').val(token)); | ||
// and submit | ||
$form.get(0).submit(); | ||
} | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Rails.configuration.stripe = { | ||
:publishable_key => ENV['STRIPE_PUBLIC_KEY'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
:secret_key => ENV['STRIPE_SECRET_KEY'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary spacing detected. |
||
} | ||
|
||
Stripe.api_key = Rails.configuration.stripe[:secret_key] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
|
||
RSpec.describe ChargesController, :type => :controller do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new Ruby 1.9 hash syntax. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body beginning. |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for create is too high. [16.16/15]