0

关于处理付款的快速问题。我想在 Rails 应用程序中成功付款时重定向到特定视图(或显示链接),你们将如何处理这样的操作?

另外,请让我知道避免安全漏洞的最佳方法,以及您将使用哪种支付解决方案以及原因。

4

1 回答 1

0

如果您的应用程序正在尝试处理某种付款,那么目前最好的一个并且许多人会同意是 Active Merchant。我没有亲自使用过它,但如果您从他们的网站上阅读:Active Merchant我确信它会解释核心优势。我还可以支持 Active Merchant 是最好使用的解决方案这一事实,因为 ruby​​-toolbox 还突出显示以下内容:Ruby Toolbox -最常用的付款方式。但是,有多种解决方案可以满足您的需求,这取决于您到底想要它做什么以及想要它处理什么。此外,关于重定向到成功付款的特定视图,您将create在您的OrderControllerPaymentsController将执行以下操作的操作:

 def create
    @order = Order.new(params[:order]) #Create new order based on the 'new' action and pass in order object.
    @order.add_line_items_from_cart(current_cart) #Add the line_items from the cart to the @order.

    respond_to do |format|
      if @order.save #Begin to save order
        OrderMailerProcess.order_process(@order).deliver

        #OrderMailerProcess is called and passes in the order
        #and uses the .deliver function that sends the user the email.
        #The OrderMailerProcess is a mailer set in mailers directory. order_process
        #is the function that handles the mailer.

        Cart.destroy(session[:cart_id]) #If the order is saved destroy the current session of the cart.
        session[:cart_id] = nil #Cart_id now becomes nil

        format.html { redirect_to(root_url, :notice => #Format into ht
            'Thank you for your order you will recieve an email shortly.') }
      else
        format.html { render :action => "new" }
      end
    end
  end

从上面提供的示例中,此创建操作是您如何创建订单的一个片段,并在保存订单后触发邮件发送给该用户,详细说明他们订购的内容。但是与您最相关的是,在format.html块内部redirect_to(root_url, :notice....)这意味着在创建订单后,用户将被重定向到您的应用程序的根目录,在大多数电子商务系统中都是home#index. 应该把事情弄清楚

于 2013-05-23T07:34:27.187 回答