mercredi 12 décembre 2018

PayPal Express return configuration produces couldn't find Order without an ID

I am working on a PayPal express integration and successfully connect to PayPal and place the payment, but on return I get:

ActiveRecord::RecordNotFound in CheckoutController#success

Couldn't find Order without an ID

The actions in my controller are:

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

routes are:

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

Aucun commentaire:

Enregistrer un commentaire