gpt4 book ai didi

c# - 如何将项目添加到 PayPal API 中的项目列表

转载 作者:行者123 更新时间:2023-11-30 14:50:54 26 4
gpt4 key购买 nike

我对 MVC 有点陌生。但我已经走了很长一段路。我将 PayPal MVC API 集成到我的项目中,当我将多个项目放入购物车并检查项目列表时,我意识到只填充了数组中的最新项目。

我一直在尝试玩这个,但我很容易不知道在 PayPal 中将多个项目添加到项目列表时我错过了什么。

PaymentWithCreditCard()中有这部分:

        //create and item for which you are taking payment
//if you need to add more items in the list
//Then you will need to create multiple item objects or use some loop to instantiate object
var item = new Item();
foreach (var cartitem in cookieCarts)
{
item.name = cartitem.Fullname;
item.currency = "USD";
item.price = cartitem.Price;
item.quantity = cartitem.Qty.ToString();
item.sku = cartitem.Sku;
var intPrice = Int32.Parse(cartitem.Price);
subtotal = subtotal + intPrice;
}

//Now make a List of Item and add the above item to it
//you can create as many items as you want and add to this list
var itms = new List<Item>();
itms.Add(item);
var itemList = new ItemList();
itemList.items = itms;

我不确定如何将我的 forloop 添加到项目列表中

最佳答案

@NeoSketo 试试这个。另外,我看不到小计在做什么,所以我没有管它。

            List<Item> items = new List<Item>();

foreach (var cartitem in cookieCarts)
{
items.Add(new Item {
name = cartitem.FullName,
currency = "USD",
price = cartitem.Price,
sku = cartitem.Sku,
quantity = cartitem.Qty.ToString()
});

var intPrice = Int32.Parse(cartitem.Price);
subtotal = sobtotal + intPrice;
}

ItemList theItemList = new ItemList();
theItemList.items = new List<Item>();
theItemList.items = items;

关于c# - 如何将项目添加到 PayPal API 中的项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35637971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com