def create customer = current_user.stripe_customer source = Stripe::Source.create(token: params[:stripeToken]) customer.default_source = source customer.save begin Stripe::Subscription.create( customer: customer, plan: 'pro' ) current_user.assign_attributes(stripe_subscription_id: subscription.id) current_user.save redirect_to root_path, notice: 'Thanks for subscribing!' rescue Stripe::CardError => e flash.alert = e.message render action: :new end