-
Notifications
You must be signed in to change notification settings - Fork 265
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6205c72
Adding creditcard payment
fatboypunk 1730d5a
Clean code up and save the customer.id
fatboypunk 88824bc
Do not work when in single tenant mode or without stripe setup
fatboypunk cd78851
Show and delete subscriptions
fatboypunk f99a26b
[ci skip] wip only delete when subscription is set
fatboypunk 5ee1b55
only delete when subscription is set
fatboypunk 6a47ded
[ci skip] de-activate and activate wip
fatboypunk 31aab64
De-activate and reactivate users as an owner
fatboypunk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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, | ||
plan: "value", | ||
email: current_user.email, | ||
quantity: user_count | ||
) | ||
current_account.update(stripe_id: customer.id) | ||
end | ||
|
||
private | ||
|
||
def user_count | ||
@user_count ||= User.count | ||
end | ||
end | ||
|
||
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. 1 trailing blank lines detected. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%h2 | ||
Thanks, you paid | ||
%strong= number_to_currency(ENV["SUBSCRIPTIONS_PRICE"].to_f * @user_count.to_f, precision: 2, unit: "€") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
%script{:src => "https://js.stripe.com/v2/", :type => "text/javascript"} | ||
= form_tag charges_path, method: "POST", id: "payment-form" do | ||
%span.payment-errors | ||
.form-row | ||
%label | ||
%span= t "payments.labels.card_number" | ||
%input{"data-stripe" => "number", :size => "20", :type => "text"}/ | ||
.form-row | ||
%label | ||
%span= t "payments.labels.cvc" | ||
%input{"data-stripe" => "cvc", :size => "4", :type => "text"}/ | ||
.form-row | ||
%label | ||
%span= t "payments.labels.expiration_date" | ||
%input{"data-stripe" => "exp-month", :size => "2", :type => "text"}/ | ||
%span / | ||
%input{"data-stripe" => "exp-year", :size => "4", :type => "text"}/ | ||
%button{:type => "submit"}= t "payments.pay_button" | ||
%script{:src => "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"} | ||
: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(); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Rails.configuration.stripe = { | ||
publishable_key: ENV["STRIPE_PUBLIC_KEY"], | ||
secret_key: ENV["STRIPE_SECRET_KEY"] | ||
} | ||
|
||
Stripe.api_key = Rails.configuration.stripe[:secret_key] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStripeIdToAccount < ActiveRecord::Migration | ||
def change | ||
add_column :accounts, :stripe_id, :string | ||
end | ||
end |
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]