10401订单总数无效ASP.NET C#
我正在使用ASP.NET(Web表单)和msdn的WingtipToys教程编写一个商店应用程序 我有一个问题,当我使用贝宝按钮。我有一个错误:10401订单总数无效ASP.NET C#,c#,asp.net,paypal,webforms,paypal-sandbox,C#,Asp.net,Paypal,Webforms,Paypal Sandbox,我正在使用ASP.NET(Web表单)和msdn的WingtipToys教程编写一个商店应用程序 我有一个问题,当我使用贝宝按钮。我有一个错误: 10401 Transaction refused because of an invalid argument. See additional error messages for details. Order total is invalid. 这是代码的一部分,我认为有问题: public bool ShortcutExpressCheckou
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;
}
}
public bool ShortcutExpressCheckout(字符串金额、参考字符串令牌、参考字符串retMsg)
{
如果(bSandbox)
{
pEndPointURL=pEndPointURL_SB;
host=host_SB;
}
字符串returnURL=”https://localhost:44317/Checkout/CheckoutReview.aspx";
字符串取消URL=”https://localhost:44317/Checkout/CheckoutCancel.aspx";
NVPCodec编码器=新的NVPCodec();
编码器[“方法”]=“SetExpressCheckout”;
编码器[“RETURNURL”]=RETURNURL;
编码器[“取消URL”]=取消URL;
编码器[“品牌名称”]=“商店”;
编码器[“付款请求金额”]=金额;
编码器[“PAYMENTREQUEST\u 0\u ITEMAMT”]=金额;
编码器[“PAYMENTREQUEST\u 0\u PAYMENTACTION”]=“销售”;
编码器[“付款请求\u 0\u货币代码”]=“PLN”;
//购买购物车产品
使用(Shop.Logic.ShoppingCartActions myCartOrders=new Shop.Logic.ShoppingCartActions())
{
List myOrderList=myCartOrders.GetCartItems();
for(int i=0;i
总订单已永久分配(22.50),但仍有问题
有什么提示吗?价格在
encoder["L_PAYMENTREQUEST_0_AMT" + i] = "22.50";
也许应该是这样
encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Produkt.nazwa_price.ToString();
价格是在
encoder["L_PAYMENTREQUEST_0_AMT" + i] = "22.50";
也许应该是这样
encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Produkt.nazwa_price.ToString();
好的,问题解决了。我必须在不同的班级把金额改成小数
所以贝宝订单的正确格式是:“xx.xx”好的,问题解决了。我必须在不同的班级把金额改成小数
因此,paypal订单的正确格式是:“xx.xx”如果您的计算机使用十进制komma,那么您应该将分配更改为:
encoder["L_PAYMENTREQUEST_0_AMT" + i] = (myOrderList[i].Produkt.nazwa_price.ToString()).Replace(",",".");
如果您的计算机使用十进制komma,则您应将分配更改为:
encoder["L_PAYMENTREQUEST_0_AMT" + i] = (myOrderList[i].Produkt.nazwa_price.ToString()).Replace(",",".");
我也有同样的问题。原因是波兰的十进制格式不同。 要查看要更改的行,请在下面的代码中查找//注释:
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;
}
}
public bool ShortcutExpressCheckout(字符串金额、参考字符串令牌、参考字符串retMsg)
{
如果(bSandbox)
{
pEndPointURL=pEndPointURL_SB;
host=host_SB;
}
字符串returnURL=”https://localhost:44304/Checkout/CheckoutReview.aspx";
字符串取消URL=”https://localhost:44304/Checkout/CheckoutCancel.aspx";
金额=金额替换(“,”,“);//
NVPCodec编码器=新的NVPCodec();
编码器[“方法”]=“SetExpressCheckout”;
编码器[“RETURNURL”]=RETURNURL;
编码器[“取消URL”]=取消URL;
编码器[“BRANDNAME”]=“翼尖玩具示例应用程序”;
编码器[“付款请求金额”]=金额;
编码器[“PAYMENTREQUEST\u 0\u ITEMAMT”]=金额;
编码器[“PAYMENTREQUEST\u 0\u PAYMENTACTION”]=“销售”;
编码器[“付款请求\u 0\u货币代码”]=“PLN”;
//购买购物车产品
使用(WingtipToys.Logic.ShoppingCartActions myCartOrders=new WingtipToys.Logic.ShoppingCartActions())
{
List myOrderList=myCartOrders.GetCartItems();
for(int i=0;i
我也有同样的问题。原因是波兰的十进制格式不同。
要查看要更改的行,请在下面的代码中查找//注释:
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;
}
}
public bool ShortcutExpressCheckout(字符串金额、参考字符串令牌、参考字符串retMsg)
{
如果(bSandbox)
{
pEndPointURL=pEndPointURL_SB;
host=host_SB;
}
字符串returnURL=”https://localhost:44304/Checkout/CheckoutReview.aspx";
字符串取消URL=”https://localhost:44304/Checkout/CheckoutCancel.aspx";
金额=金额替换(“,”,“);//
NVPCodec编码器=新NVP