使用条带处理付款当前用户被注销(设计和条带化)

时间:2015-05-02 23:38:48

标签: ruby-on-rails ruby-on-rails-4 devise stripe-payments

我正在为我的用户使用设计。在我创建的应用程序中,我有如下嵌套路由:

     resources :programs, except: [:show] do
     resources :memberships, only: [:new, :create]
     end

登录用户进入程序索引点击'购买会员资格'并被重定向到其上有条纹支付表格的new_program_membership_path。当条纹处理成功付款时,用户会看到感谢您的回复我的会员资格/ create.html.erb视图。无论出于何种原因,他们都被重定向到此视图,他们似乎从应用程序中退出。当我放置

    before_action :authenticate_user!

我的会员控制器顶部的操作和付款成功处理用户被重定向到程序索引页面(而不是成员资格#create),设计错误读取“您已登录”。

这是我的会员控制员:

      def create
      Stripe.api_key = ENV['stripe_api_key']

      # Amount in cents
      @amount = Program.find(params[:program_id]).price*100
      @program = Program.find(params[:program_id])

      if (Program.find(params[:program_id]).price*100) < 50000
      customer = Stripe::Customer.create(
      :email => params[:stripeEmail],
      :description => @program.name,
      :card  => params[:stripeToken]
       )

      else
      charge = Stripe::Charge.create(
      :amount => @amount, # amount in cents, again
      :currency => "usd",
      :source => params[:stripeToken],
      :description => @program.name
      )

     end

     rescue Stripe::CardError => e
     flash[:error] = e.message
     redirect_to new_program_membership_path
     end

这是我的program_controller.rb

     class ProgramsController < ApplicationController
     before_action :set_program, only: [:show, :edit, :update, :destroy]
     before_action :authenticate, :except => [ :index, :show ]
     # GET /programs
     # GET /programs.json
     def index
     @programs = Program.all
     @program = Program.find_by(id: params[:id])
     end

    # GET /programs/1
    # GET /programs/1.json
    def show
    end

    # GET /programs/new
    def new
    @program = Program.new
    end

   # GET /programs/1/edit
   def edit
   end

  # POST /programs
  # POST /programs.json
  def create
  @program = Program.new(program_params)

  respond_to do |format|
  if @program.save
    format.html { redirect_to programs_url, notice: 'Program was successfully created.' }
    format.json { render :show, status: :created, location: @program }
  else
    format.html { render :new }
    format.json { render json: @program.errors, status: :unprocessable_entity }
     end
   end
  end

   # PATCH/PUT /programs/1
   # PATCH/PUT /programs/1.json
   def update
      respond_to do |format|
      if @program.update(program_params)
    format.html { redirect_to @program, notice: 'Program was successfully updated.' }
     format.json { render :show, status: :ok, location: @program }
   else
    format.html { render :edit }
    format.json { render json: @program.errors, status: :unprocessable_entity }
     end
    end
  end

     # DELETE /programs/1
     # DELETE /programs/1.json
       def destroy
         @program.destroy
            respond_to do |format|
          format.html { redirect_to programs_url, notice: 'Program was successfully destroyed.' }
  format.json { head :no_content }
      end
    end

在我的代码中,如果用Stripe成功付款后用户将被注销,我的错误是什么?

0 个答案:

没有答案