我正在asp.net项目中实现Paypal Express Checkout功能,该功能需要授权,然后取消或获取授权金额。我正在使用他们的版本= 104.0的API。
据我了解整个过程,我正在做正确的事情:
我在付款明细中将ActionType设置为“授权”调用SetExpressCheckout方法
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
}
};
然后我打电话给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");
响应显示“Failure”和Errors数组包含1项ErrorCode = 10609和消息“Invalid Transaction ID”
你有没有想过为什么会这样?
非常感谢!
答案 0 :(得分:0)
要在授权后获取资金,您需要运行DoCapture,而不是DoAuthorization。