首页 > 解决方案 > PayPal Express 退货配置产生找不到没有 ID 的订单

问题描述

我正在处理 PayPal 快速集成并成功连接到 PayPal 并付款,但在返回时我得到:

ActiveRecord::RecordNotFound in CheckoutController#success

Couldn't find Order without an ID

我的控制器中的操作是:

def place_order
  @order = Order.new(params[:order])
  @order.customer_ip = request.remote_ip 
  populate_order
  if @order.save
    checkout_paypal
  else
    render :action => 'index'
  end
end

def success
  @page_title = 'Thank You!'
  @order = Order.find(params[:order])
  @order.express_payer_id = params[:PayerID]
  @order.save
end

private 

def checkout_paypal
  paypal_response = ::GATEWAY.setup_purchase(
    (@order.total * 100).round, # paypal amount is in cents
    :ip => request.remote_ip,
    :return_url => checkout_success_url(@order),
    :cancel_return_url => checkout_error_url(@order)
  )
  @order.express_token = paypal_response.token
  @order.save
  redirect_to ::GATEWAY.redirect_url_for(paypal_response.token) and return
end

路线是:

match '/checkout/place_order', :to => 'checkout#place_order'
match '/checkout/success',     :to => 'checkout#success'
match '/checkout/error',       :to => 'checkout#error'

标签: ruby-on-railsruby-on-rails-3paypal

解决方案


解决方案是将路线更改为:

match '/checkout/success/:id', :to => 'checkout#success', :as => :checkout_success

现在 return_url 工作。

我以前尝试match '/checkout/success/:id', :to => 'checkout#success'过,但只有:as => :checkout_success解决了问题。


推荐阅读