【问题标题】:How to add items to the item List in PayPal API如何将项目添加到 PayPal API 中的项目列表
【发布时间】:2016-06-08 20:34:20
【问题描述】:

我对 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 添加到项目列表中

【问题讨论】:

    标签: c# asp.net-mvc paypal


    【解决方案1】:

    @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;
    

    【讨论】:

    • 不错!非常感谢!我看到了!是的,小计只是通过迭代计算价格。
    猜你喜欢
    • 2019-11-26
    • 2018-04-04
    • 2022-10-25
    • 2017-07-14
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多