c# - 10401 订单总计无效 ASP.NET C#

标签 c# asp.net paypal webforms paypal-sandbox

我正在使用 ASP.NET(Web-Form) 和来自 msdn 的 WingtipToys 教程编写一个商店应用程序。

我在使用 paypal 按钮时遇到问题。我有错误:

10401
Transaction refused because of an invalid argument. See additional error messages for details.
Order total is invalid.

这是我认为有问题的部分代码:

public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
{
    if (bSandbox)
    {
        pEndPointURL = pEndPointURL_SB;
        host = host_SB;
    }

    string returnURL = "https://localhost:44317/Checkout/CheckoutReview.aspx";
    string cancelURL = "https://localhost:44317/Checkout/CheckoutCancel.aspx";

    NVPCodec encoder = new NVPCodec();
    encoder["METHOD"] = "SetExpressCheckout";
    encoder["RETURNURL"] = returnURL;
    encoder["CANCELURL"] = cancelURL;
    encoder["BRANDNAME"] = "Shop";
    encoder["PAYMENTREQUEST_0_AMT"] = amt;
    encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt;
    encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
    encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "PLN";

    // Get the Shopping Cart Products
    using (Shop.Logic.ShoppingCartActions myCartOrders = new Shop.Logic.ShoppingCartActions())
    {
        List<ElementKoszyka> myOrderList = myCartOrders.GetCartItems();

        for (int i = 0; i < myOrderList.Count; i++)
        {
            encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Produkt.nazwa_produkt.ToString();
           // string tmp = Math.Round(myOrderList[i].Produkt.cena, 2).ToString();
           // encoder["L_PAYMENTREQUEST_0_AMT" + i] = Math.Round(myOrderList[i].Produkt.cena, 2).ToString();
            encoder["L_PAYMENTREQUEST_0_AMT" + i] = "22.50";
            encoder["L_PAYMENTREQUEST_0_QTY" + i] = myOrderList[i].ilosc.ToString();
        }
    }

    string pStrrequestforNvp = encoder.Encode();
    string pStresponsenvp = HttpCall(pStrrequestforNvp);

    NVPCodec decoder = new NVPCodec();
    decoder.Decode(pStresponsenvp);

    string strAck = decoder["ACK"].ToLower();
    if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
    {
        token = decoder["TOKEN"];
        string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token;
        retMsg = ECURL;
        return true;
    }
    else
    {
        retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
            "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
            "Desc2=" + decoder["L_LONGMESSAGE0"];
        return false;
    }
}

总订单已永久分配(22.50),但仍有问题。

有什么建议吗?

最佳答案

价格分配于

encoder["L_PAYMENTREQUEST_0_AMT" + i] = "22.50";

也许应该是这样的

encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Produkt.nazwa_price.ToString();

关于c# - 10401 订单总计无效 ASP.NET C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242747/

相关文章:

c# - 使用 SharePoint 作为数据源

php - 卡在 Paypal 集成中

paypal - 刷卡硬件支付系统是特定的吗?

c# - 无法在服务结构中使用 DNS 与服务通信

c# - 用字典绑定(bind)下拉列表

c# - 在asp中如何从查询字符串中获取数据?

javascript - 从 JavaScript 发送消息到处理程序

api - Paypal REST API 错误请求

c# - 如何将 PictureBox 用作按钮

c# - 如何添加源生成器作为 nuget 引用?