专柜商务和条纹支付

时间:2016-03-02 20:00:26

标签: ruby-on-rails rubygems

按照此文档/教程(https://github.com/tryshoppe/shoppe)尝试将Shoppe(https://github.com/tryshoppe/shoppe-stripe)和Stripe付款(https://tryshoppe.com/docs/payment-gateways/stripe)集成到我的Rails应用程序中。不知道为什么我得到这个错误...

  

找不到带有'id'=

的Shoppe :: Order
def payment
 @order = Shoppe::Order.find(session[:current_order_id])
 if request.post?
 if @order.accept_stripe_token(params[:stripe_token])
 redirect_to checkout_confirmation_path
end

2 个答案:

答案 0 :(得分:0)

错误告诉您,它无法找到ID为空的Shopped::Order

这意味着参数session[:current_order_id]不包含任何信息。

您需要考虑纠正导致与:current_order_id哈希中的session键相关的值的任何内容为空白。

答案 1 :(得分:0)

商店文档中存在错误。要访问current_order,您需要在ApplicationController中创建帮助器,如此。然后我建议改为引用current_order.id。

的ApplicationController:

private

  def current_order
    @current_order ||= begin
      if has_order?
        @current_order
      else
        order = Shoppe::Order.create(:ip_address => request.ip)
        session[:order_id] = order.id
        order
      end
    end
  end

  def has_order?
    session[:order_id] && @current_order = Shoppe::Order.includes(:order_items => :ordered_item).find_by_id(session[:order_id])
  end

  helper_method :current_order, :has_order?

OrdersController:

def payment
  @order = Shoppe::Order.find(current_order.id)
  ### rest of your code here ###
end