我在 ASP.Net C# 4.0 中使用 PayPal 沙箱。我添加了以下网络参考:
https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl
如果我有 1 件商品(请给我 2 件 T 恤),我可以将其传递给 PayPal 对象并毫无问题地完成我的交易:
var item = new PayPalAPIHelper.PayPalWS.PaymentDetailsItemType
{
Quantity = 2, //etc...etc
};
var paymentDetails = new PayPalAPIHelper.PayPalWS.PaymentDetailsType();
paymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[]{item};
现在我的困境是当客户想要不同的物品(1 件 T 恤、1 条裤子)时。现在我需要多个 PaymentDetailsItemType 对象来传递给 paymentDetails 对象。我试过这个:
//now i have an array of different items
var items = new PayPalAPIHelper.PayPalWS.PaymentDetailsItemType[3];
items[0].Description = "T-shirt";
items[1].Description = "Jeans";
paymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[]{items};
我收到此错误:
Cannot implicitly convert type 'PayPalAPIHelper.PayPalWS.PaymentDetailsItemType[]'
to 'PayPalAPIHelper.PayPalWS.PaymentDetailsItemType'
我可以做到这一点,它编译:
paymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[]{items[0],items[1]};
但是当我运行它时,当我调用 PayPal 服务时,我在元素“数量”中得到数据类型“不匹配”:
PayPalAPIHelper.PayPalWS.PaymentDetailsType paymentDetails = new PayPalAPIHelper.PayPalWS.PaymentDetailsType();
paymentDetails.PaymentDetailsItem = new PayPalAPIHelper.PayPalWS.PaymentDetailsItemType[] { items[0],items[1] };
reqDetails.PaymentDetails = new PayPalAPIHelper.PayPalWS.PaymentDetailsType[] { paymentDetails };
PayPalAPIHelper.PayPalWS.SetExpressCheckoutReq req = new PayPalAPIHelper.PayPalWS.SetExpressCheckoutReq()
{
SetExpressCheckoutRequest = new PayPalAPIHelper.PayPalWS.SetExpressCheckoutRequestType()
{
Version = Version,
SetExpressCheckoutRequestDetails = reqDetails
}
};
// query PayPal and get token
//error occurs here
PayPalAPIHelper.PayPalWS.SetExpressCheckoutResponseType resp = BuildPayPalWebservice().SetExpressCheckout(req); //this is where the error occurs
如何将多种类型传递给 PayPal API Web 服务,以便用户可以订购不同的商品?提前致谢