【问题标题】:10401 Order total is invalid ASP.NET C#10401 订单总额无效 ASP.NET C#
【发布时间】:2017-10-29 18:40:18
【问题描述】:

我正在使用来自 msdn 的 ASP.NET(Web-Form) 和 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),但仍有问题。

有什么建议吗?

【问题讨论】:

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


    【解决方案1】:

    价格分配在

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

    也许应该是这样的

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

    【讨论】:

    • 还是同样的问题 ;)
    【解决方案2】:

    好的,问题解决了。我必须在不同的班级将 amt 更改为十进制。

    所以paypal订单的正确格式是:“xx.xx”

    【讨论】:

      【解决方案3】:

      如果您的计算机使用小数点,那么您应该将分配更改为:

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

      【讨论】:

        【解决方案4】:

        我也遇到了同样的问题。原因是波兰的十进制格式不同。 要查看要更改的行,请在下面的代码中查找 // 注释:

        public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
        {
            if (bSandbox)
            {
                pEndPointURL = pEndPointURL_SB;
                host = host_SB;
            }
        
            string returnURL = "https://localhost:44304/Checkout/CheckoutReview.aspx";
            string cancelURL = "https://localhost:44304/Checkout/CheckoutCancel.aspx";
        
            amt = amt.Replace(",",".");  // <---------SOLUTION------------>
        
            NVPCodec encoder = new NVPCodec();
            encoder["METHOD"] = "SetExpressCheckout";
            encoder["RETURNURL"] = returnURL;
            encoder["CANCELURL"] = cancelURL;
            encoder["BRANDNAME"] = "Wingtip Toys Sample Application";
            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 (WingtipToys.Logic.ShoppingCartActions myCartOrders = new WingtipToys.Logic.ShoppingCartActions())
            {
                List<CartItem> myOrderList = myCartOrders.GetCartItems();
        
                for (int i = 0; i < myOrderList.Count; i++)
                {
                    encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString();
                    encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Product.UnitPrice.ToString().Replace(",", ".");  // <---------SOLUTION------------>
                    encoder["L_PAYMENTREQUEST_0_QTY" + i] = myOrderList[i].Quantity.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;
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2012-09-10
          • 1970-01-01
          • 2016-02-18
          • 2015-09-10
          • 2016-06-15
          • 2012-11-28
          • 2017-07-11
          • 2021-12-13
          • 2018-12-06
          相关资源
          最近更新 更多