PayPal Express return 配置生成找不到没有 ID 的订单
PayPal Express return configuration produces couldn't find Order without an ID
我正在处理 PayPal Express 集成并成功连接到 PayPal 并进行付款,但在 return 我得到:
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'
解决方案是将路由更改为:
match '/checkout/success/:id', :to => 'checkout#success', :as => :checkout_success
现在 return_url 可以使用了。
我之前试过match '/checkout/success/:id', :to => 'checkout#success'
,但只有:as => :checkout_success
解决了问题。
我正在处理 PayPal Express 集成并成功连接到 PayPal 并进行付款,但在 return 我得到:
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'
解决方案是将路由更改为:
match '/checkout/success/:id', :to => 'checkout#success', :as => :checkout_success
现在 return_url 可以使用了。
我之前试过match '/checkout/success/:id', :to => 'checkout#success'
,但只有:as => :checkout_success
解决了问题。