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

Neo*_*eto 3 c# asp.net-mvc paypal

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

我一直在尝试使用这个 bu 我很容易不知道我在向 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;
Run Code Online (Sandbox Code Playgroud)

我不知道如何将我的 forloop 添加到项目列表中

Mik*_*ace 5

@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;
Run Code Online (Sandbox Code Playgroud)

  • 好的!非常感谢!我看到了!是的,小计只是通过迭代计算价格。 (2认同)