Skip to content

Commit aa09cb3

Browse files
committed
Fix new subscriptions
Strong Parameters for account params Fix if condition in save_with_payment When save_with_payment is called, stripe_customer_token might not be available, so we should check for just stripe_card_token.
1 parent 1f29298 commit aa09cb3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/controllers/accounts_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def new
1515
def create
1616
redirect_to teamname_path(slug: @team.slug) if @plan.free?
1717

18-
@account = @team.build_account(params[:account])
18+
@account = @team.build_account(account_params)
1919
@account.admin_id = current_user.id
2020
# TODO: (whatupdave) this doesn't look like it's being used any more. Remove if possible
2121
# @account.trial_end = Date.new(2013, 1, 1).to_time.to_i if session[:discount] == ENV['DISCOUNT_TOKEN']
@@ -38,7 +38,7 @@ def create
3838
end
3939

4040
def update
41-
if @account.update_attributes(params[:account]) && @account.save_with_payment(@plan)
41+
if @account.update_attributes(account_params) && @account.save_with_payment(@plan)
4242
redirect_to new_team_opportunity_path(@team), notice: "You are subscribed to #{@plan.name}." + plan_capability(@plan, @team)
4343
else
4444
flash[:error] = @account.errors.full_messages.join("\n")
@@ -107,4 +107,8 @@ def paying_user_context
107107
# Honeybadger.context(user_email: current_user.try(:email)) if current_user
108108
end
109109

110+
def account_params
111+
params.require(:teams_account).permit(:stripe_card_token)
112+
end
113+
110114
end

app/models/teams/account.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def subscribe_to!(plan, force=false)
3636
end
3737

3838
def save_with_payment(plan=nil)
39-
if valid?
39+
if stripe_card_token
4040
create_customer unless plan.try(:one_time?)
4141
subscribe_to!(plan) unless plan.nil?
4242
save!

0 commit comments

Comments
 (0)