【发布时间】:2014-05-27 04:51:01
【问题描述】:
我不断收到错误 #10400(订单总数丢失),但不确定我遗漏了什么。一切似乎都在正确处理。这是设置付款的地方:
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
这会将我带到贝宝,对用户进行身份验证,然后按预期返回确认 URL。看起来像这样:
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
单击“确认并付款”按钮并将上述内容发布到后,交易将失败并出现10400 Order total is missing. 错误。在我看来,我在上面指定了订单总额,当我被带到贝宝时会显示总额。我错过了什么?
【问题讨论】:
标签: ruby-on-rails ruby paypal express-checkout