我正在 asp.net 项目中实现 Paypal Express Checkout 功能,该功能需要授权,然后取消或获取授权金额。我正在使用他们的版本 = 104.0 的 API。
据我了解整个过程,我做的一切都是正确的:
我在付款详细信息中调用 SetExpressCheckout 方法,并将 ActionType 设置为“授权”
SetExpressCheckoutRequestDetailsType reqDetails = new SetExpressCheckoutRequestDetailsType(); reqDetails.ReturnURL = "http://some.url"; reqDetails.CancelURL = "http://some.url"; reqDetails.NoShipping = "1"; reqDetails.OrderDescription = "You're about to buy items for " + payment.Amount.ToString("F"); reqDetails.cpplogoimage = "http://some.ulr/image.jpb"; reqDetails.PaymentDetails = new PaymentDetailsType[1]; reqDetails.PaymentDetails[0] = new PaymentDetailsType(); reqDetails.PaymentDetails[0].PaymentDetailsItem = new PaymentDetailsItemType[cart.LineItems.Count]; int i = 0; foreach (LineItemModel li in cart.LineItems) { PaymentDetailsItemType item = new PaymentDetailsItemType(); item.Amount = new BasicAmountType(); item.Amount.Value = li.TotalIncludingShipping.ToString("F"); item.Amount.currencyID = CurrencyCodeType.AUD; item.Name = li.ProductItem.DisplayName; item.Number = li.ProductItem.SKU; item.Quantity = li.Quantity.ToString(); item.Description = ""; reqDetails.PaymentDetails[0].PaymentDetailsItem.SetValue(item, i); i++; } reqDetails.OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.AUD, Value = payment.Amount.ToString("F") }; reqDetails.PaymentDetails[0].PaymentAction = PaymentActionCodeType.Authorization; reqDetails.PaymentDetails[0].PaymentActionSpecified = true; SetExpressCheckoutReq req = new SetExpressCheckoutReq() { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() { Version = "104.0", SetExpressCheckoutRequestDetails = reqDetails } };
- 一切正常,并且在我的测试个人帐户的通知中的 Paypal 后端我可以看到金额已自动完成的消息
然后我打电话给 DoExpressCheckout。这是请求的代码
DoExpressCheckoutPaymentReq payReq = new DoExpressCheckoutPaymentReq() { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType() { Version = ConfigurationManager.AppSettings["PaypalAPIVersion"], DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType() { Token = token, PayerID = payerID, PaymentDetails = new PaymentDetailsType[1] } } }; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Authorization; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentActionSpecified = true; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0] = new PaymentDetailsType(); payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].PaymentAction = PaymentActionCodeType.Authorization; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].PaymentActionSpecified = true; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal = new BasicAmountType(); payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal.currencyID = CurrencyCodeType.AUD; payReq.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0].OrderTotal.Value = total.ToString("F");
此请求也返回“成功”。我保存响应的 DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID 以备将来使用
但是,当我使用上一个响应中的事务 ID 运行 DoAuthorize 时,我得到“失败”。这是请求代码:
DoAuthorizationReq authReq = new DoAuthorizationReq() { DoAuthorizationRequest = new DoAuthorizationRequestType() { Version = "104.0", TransactionID = doCheckoutTransactionId } }; authReq.DoAuthorizationRequest.Amount = new BasicAmountType(); authReq.DoAuthorizationRequest.Amount.currencyID = CurrencyCodeType.AUD; authReq.DoAuthorizationRequest.Amount.Value = total.ToString("F");
响应显示“失败”并且错误数组包含 1 个错误代码 = 10609 和消息“无效事务 ID”的项目
你有什么想法为什么会发生这种情况?
非常感谢!