Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将购物车项目发送到paypal_C#_Asp.net Mvc_Paypal - Fatal编程技术网

C# 如何将购物车项目发送到paypal

C# 如何将购物车项目发送到paypal,c#,asp.net-mvc,paypal,C#,Asp.net Mvc,Paypal,我正在使用mvc,我正在尝试将我的整个购物车发送到paypal。我可以让它添加一个项目,但不是整个购物车 这是我的控制器: public ActionResult PostToPayPal(Cart cart, ShippingDetails shippingInfo) { PayPal paypal = new PayPal(); paypal.cmd = "_xclick"; paypal.business = ConfigurationManager.AppSett

我正在使用mvc,我正在尝试将我的整个购物车发送到paypal。我可以让它添加一个项目,但不是整个购物车

这是我的控制器:

public ActionResult PostToPayPal(Cart cart, ShippingDetails shippingInfo)
{
    PayPal paypal = new PayPal();
    paypal.cmd = "_xclick";
    paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"];

    bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandBox"]);
    if (useSandbox)
        ViewBag.actionURL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
    else
    {
        ViewBag.actionURL = "https://www.paypal.com/cgi-bin/webscr";
    }

    paypal.cancel_return = System.Configuration.ConfigurationManager.AppSettings["CancelURL"];
    paypal.@return = ConfigurationManager.AppSettings["ReturnURL"];
    paypal.notify_url = ConfigurationManager.AppSettings["NotifyURL"];

    paypal.currency_code = ConfigurationManager.AppSettings["CurrencyCode"];

    foreach (var lines in cart.Lines )
    {
        paypal.item_name = lines.Product.Name;
        paypal.amount = lines.Product.Price.ToString("c");
    }
    //paypal.item_name = item;
    //paypal.amount = amount;
    return View(paypal);

}
以下是我的看法:

@model SportsStore.Domain.Entities.PayPal

@{
    ViewBag.Title = "PostToPayPal";
}

<h2>PostToPayPal</h2>

        <form id="frm" action="@ViewBag.actionURL">

                @Html.HiddenFor(model => model.cmd)
                @Html.HiddenFor(model => model.business)
                @Html.HiddenFor(model => model.no_shipping)
                @Html.HiddenFor(model => model.@return)
                @Html.HiddenFor(model => model.cancel_return)
                @Html.HiddenFor(model => model.notify_url)
                @Html.HiddenFor(model => model.currency_code)
                @Html.HiddenFor(model => model.item_name)
                @Html.HiddenFor(model => model.amount)

            <p>
                <h4>redirecting to paypal...</h4>
            </p>



        </form>

<script type="text/javascript" language="javascript">
    $(this.document).ready(function () {
        var frm = $("form");
        frm.submit();
    })
</script>
@model sportstore.Domain.Entities.PayPal
@{
ViewBag.Title=“PostToPayPal”;
}
PostToPayPal
@Html.HiddenFor(model=>model.cmd)
@Html.HiddenFor(model=>model.business)
@Html.HiddenFor(model=>model.no_shipping)
@Html.HiddenFor(model=>model.@return)
@Html.HiddenFor(model=>model.cancel\u返回)
@Html.HiddenFor(model=>model.notify\uURL)
@Html.HiddenFor(model=>model.currency\u代码)
@Html.HiddenFor(model=>model.item_name)
@Html.HiddenFor(model=>model.amount)

正在重定向到贝宝。。。

$(this.document).ready(函数(){ var frm=$(“形式”); frm.submit(); })
这是我的购物车:

@模型SportsStore.WebUI.Models.CartIndexViewModel

@{ ViewBag.Title=“小弓窥视:你的购物车”; }

你的车

量
项目
价格
小计
@foreach(Model.Cart.line中的var行)
{
@行。数量
@line.Product.Name
@行。产品。价格。ToString(“c”)
@((行。数量*行。产品。价格)。ToString(“c”))
@使用(Html.BeginForm(“RemoveFromCart”、“Cart”))
{
@隐藏(“ProductId”,line.Product.ProductId)
@Html.HiddenFor(x=>x.ReturnUrl)
}
}
总数:
@Model.Cart.ComputeTotalValue().ToString(“c”)

@ActionLink(“立即签出”、“签出”)

购物车实体代码:

private readonly List<CartLine> lineCollection = new List<CartLine>();

public IEnumerable<CartLine> Lines
{
    get { return lineCollection; }
}

public void AddItem(Product product, int quantity)
{
    CartLine line = lineCollection
        .Where(p => p.Product.ProductID == product.ProductID)
        .FirstOrDefault();

    if (line == null)
    {
        lineCollection.Add(new CartLine {Product = product, Quantity = quantity});
    }
    else
    {
        line.Quantity += quantity;
    }
}

public void RemoveLine(Product product)
{
    lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
}

public decimal ComputeTotalValue()
{
    return lineCollection.Sum(e => e.Product.Price*e.Quantity);
}

public void Clear()
{
    lineCollection.Clear();
}
private readonly List lineCollection=new List();
公共可数线
{
获取{return lineCollection;}
}
公共无效附加项(产品、整数数量)
{
CartLine line=lineCollection
.Where(p=>p.Product.ProductID==Product.ProductID)
.FirstOrDefault();
如果(行==null)
{
添加(新的CartLine{Product=Product,Quantity=Quantity});
}
其他的
{
行.数量+=数量;
}
}
公共空隙清除线(产品)
{
lineCollection.RemoveAll(l=>l.Product.ProductID==Product.ProductID);
}
公共十进制计算总价值()
{
returnlinecollection.Sum(e=>e.Product.Price*e.Quantity);
}
公共空间清除()
{
lineCollection.Clear();
}
}

公共类CartLine { 公共产品产品{get;set;} 公共整数数量{get;set;} }

有什么帮助吗


谢谢……

您是从传递到您的电话中的购物车中获取价格的吗?请告诉我客户端只是传入了一个项目id,而您有一个自定义活页夹,可以在服务器端构建购物车行(出于某种原因…?)?我不确定我是否理解这个问题,但我的购物车对象包含用户添加到购物车中的值。因此,我将该对象传递到我的控制器中。我对其进行了编辑,以显示我的购物车实体。我想Shane所问的是,您从客户的购物车收到的数据是否包括您用于计算其总价的商品价格。这是危险的,因为来自客户端的数据不可信-在计算收费金额之前,您应该在服务器端独立查找价格。哦,好的。不,不是这样的。谢谢
private readonly List<CartLine> lineCollection = new List<CartLine>();

public IEnumerable<CartLine> Lines
{
    get { return lineCollection; }
}

public void AddItem(Product product, int quantity)
{
    CartLine line = lineCollection
        .Where(p => p.Product.ProductID == product.ProductID)
        .FirstOrDefault();

    if (line == null)
    {
        lineCollection.Add(new CartLine {Product = product, Quantity = quantity});
    }
    else
    {
        line.Quantity += quantity;
    }
}

public void RemoveLine(Product product)
{
    lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
}

public decimal ComputeTotalValue()
{
    return lineCollection.Sum(e => e.Product.Price*e.Quantity);
}

public void Clear()
{
    lineCollection.Clear();
}