ruby on rails - Denying user permission that haven't completed the checkout process with stripe subscription -


so, followed tutorial on youtube on how set stripe subscription. have keys inserted correctly , sign form etc. set up. problem noticed if user doesn't pay , goes home page, they'll able see everything. what's best way deny access until have completed payment?

currently subscriber controller

class subscriberscontroller < applicationcontroller  before_filter :authenticate_user!  def new end  def update token = params[:stripetoken]   customer = stripe::customer.create(   card: token,   plan: 1020,   email: current_user.email )  @user = user.find(current_user.id) @user.subscribed = true @user.stripeid = customer.id @user.save  redirect_to people_path, notice: "welcome" end  end 

registration controller:

class registrationscontroller < devise::registrationscontroller protected  def after_sign_up_path_for(resource)     '/subscribers/new' end end 

you need create additional before_filter method if don't want non-paying customers able access application. require creating additional boolean field on users table, "paid" , using filter. example...

class subscriberscontroller < applicationcontroller  before_action :authenticate_user! before_action :authenticate_payment  def new end  def update token = params[:stripetoken]   customer = stripe::customer.create(   card: token,   plan: 1020,   email: current_user.email )  @user = user.find(current_user.id) @user.subscribed = true @user.stripeid = customer.id @user.save  redirect_to people_path, notice: "welcome" end  private  def authenticate_payment   @user = user.find(current_user.id)   unless @user.paid?      redirect_to root_url   end end 

edit: if have subscribed field user, marked true when payment confirmed filter should work

def authenticate_subscription   @user = user.find(current_user)   unless @user.subscribed?     redirect_to root_url   end end 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -