更新用户创建条带费用的帐户代码

时间:2016-02-15 16:57:17

标签: ruby-on-rails stripe-payments

我构建了一个用于创建帐户的rails应用程序,如下所示。

现在我希望它在重定向到新帐户之前使用条带为卡充电。 代码如下。

如何将这两个块组合成一个创建操作,以便控制器中的操作完成两个代码块中的操作,但是在一个操作中?

我正在尝试将第二个块添加到第一个块,而不是相反,因为我已经构建了一个完整的登录系统。

正常登录

def create
    @user = User.new(user_params)
    if @user.save
      @user.send_activation_email
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end

条纹创建代码

def create
    @registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"],
                                                               card_token: 

    stripe_params["stripeToken"])
        raise "Please, check registration errors" unless @registration.valid?
        @registration.process_payment
        @registration.save
        redirect_to @registration, notice: 'Registration was successfully created.'
      rescue e
        flash[:error] = e.message
        render :new
      end

0 个答案:

没有答案
相关问题