I keep getting error #10400 (Order total is missing) but am not sure what I am leaving out. Everything appears to be processing correctly. This is where the payment is setup:
def setcheckout
api = PayPal::SDK::Merchant::API.new
@set_express_checkout = api.build_set_express_checkout(params[:SetExpressCheckoutRequestType])
# Find Item Total and Order Total
details = @set_express_checkout.SetExpressCheckoutRequestDetails
pay = details.PaymentDetails[0]
pay.PaymentDetailsItem[0].Name = 'Item'
pay.PaymentDetailsItem[0].Amount = 1
pay.PaymentDetailsItem[0].Quantity = 1
pay.ItemTotal = pay.PaymentDetailsItem[0].Amount
pay.OrderTotal.currencyID = pay.ItemTotal.currencyID
pay.OrderTotal.value = pay.ItemTotal.value.to_f
# Notify url
#pay.NotifyURL ||= ipn_notify_url
# Return and cancel url
details.ReturnURL ||= 'http://localhost:3000/confirm'
details.CancelURL ||= 'http://localhost:3000/failed'
@set_express_checkout_response = api.set_express_checkout(@set_express_checkout)
if @set_express_checkout_response.success?
redirect_to "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{@set_express_checkout_response.Token}"
end
end
This takes me to paypal, authenticates the user, and returns to the confirmation url as expected. That looks like this:
def confirm
session[:token] = params[:token] if params[:token]
session[:PayerID] = params[:PayerID] if params[:PayerID]
api = PayPal::SDK::Merchant::API.new
@do_express_checkout_payment = api.build_do_express_checkout_payment(params[:DoExpressCheckoutPaymentRequestType])
details = @do_express_checkout_payment.DoExpressCheckoutPaymentRequestDetails
details.Token = session[:token]
details.PayerID = session[:PayerID]
#details.PaymentDetails[0].NotifyURL ||= ipn_notify_url
@do_express_checkout_payment_response = api.do_express_checkout_payment(@do_express_checkout_payment) if request.post?
end
Once the "Confirm and Pay" button is clicked and the above is posted to, the transaction fails with a 10400 Order total is missing.
error. It looks to me like I specified the order total above, and the total is displayed when I am taken to paypal. What am I missing?
I don't see the total getting sent in your DoExpressCheckoutPayment request..?? You need to include those same details in DECP that you do in SEC.
As of version 112.0 they introduced the USESESSIONPAYMENTDETAILS parameter, which is supposed to allow to tell DECP to just use what you sent in SEC if you set it to true or 1. There seems to be some discrepancy about whether or not it works, though. I've yet to test it myself.