在ASP.net中使用NVP API时,PayPal SetExpressCheckout存在问题
发布时间:2020-12-15 20:15:41 所属栏目:asp.Net 来源:网络整理
导读:嗨, 我正在实施我的Facebook游戏和贝宝的快速结帐支付服务之间的整合. 我的网站是在ASP.net开发的,我正在使用NVP API进行集成. 我的问题是我不断得到10400错误 – 订单总计缺失. 我的代码是: // Set the key/value pairs to send in the requestvar kvpl =
|
嗨,
我正在实施我的Facebook游戏和贝宝的快速结帐支付服务之间的整合. 我的网站是在ASP.net开发的,我正在使用NVP API进行集成. 我的问题是我不断得到10400错误 – 订单总计缺失. 我的代码是: // Set the key/value pairs to send in the request
var kvpl = new List<KeyValuePair<string,string>>();
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_PAYMENTACTION","Sale"));
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_AMT","23.00"));
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_ITEMAMT","15.00"));
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_TAXAMT","5.00"));
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_SHIPPINGAMT","1.00"));
kvpl.Add(new KeyValuePair<string,string>("PAYMENTREQUEST_0_HANDLINGAMT",string>("PAYMENTREQUEST_0_INSURANCEAMT",string>("PAYMENTREQUEST_0_CURRENCYCODE","ILS"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_NAME0","The name of product 1"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_NUMBER0","5543312"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_DESC0","The description of product 1"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_AMT0","10.00"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_QTY0","1"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_NAME1","The name of product 2"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_NUMBER1","4431234"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_DESC1","The description of product 2"));
kvpl.Add(new KeyValuePair<string,string>("L_PAYMENTREQUEST_0_AMT1",string>("L_PAYMENTREQUEST_0_QTY1","1"));
kvpl.Add(new KeyValuePair<string,string>("ALLOWNOTE",string>("NOSHIPPING","1"));
// SetExpressCheckout
bool ret = test.ShortcutExpressCheckout(amt,ref token,ref retMsg,kvpl);
// Check return value
if (ret)
{
// Success,store the token in the session and redirect to Paypal
session["token"] = token;
Response.Redirect( retMsg );
}
else
{
// Something went wrong
Response.Redirect("APIError.aspx?" + retMsg);
}
ShortcutExpressCheckout方法的代码是: public bool ShortcutExpressCheckout(string amt,ref string token,ref string retMsg,List<KeyValuePair<string,string>> customParams)
{
string host = "www.paypal.com";
if (bSandbox)
{
pendpointurl = "https://api-3t.sandbox.paypal.com/nvp";
host = "www.sandbox.paypal.com";
}
string returnURL = "http://localhost:50020/" + "ConfirmPayment.aspx";
string cancelURL = "http://localhost:50020/" + "CancelPayment.aspx";
var encoder = new NVPCodec();
encoder["VERSION"] = "72.0";
encoder["METHOD"] = "SetExpressCheckout";
encoder["RETURNURL"] = returnURL;
encoder["CANCELURL"] = cancelURL;
if (customParams != null)
{
customParams.ForEach(kvp => encoder[kvp.Key] = kvp.Value);
}
string pStrrequestforNvp = encoder.Encode();
string pStresponsenvp = HttpCall(pStrrequestforNvp);
var 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;
}
}
代码生成的请求是: METHOD=SetExpressCheckout& VERSION=72.0& RETURNURL=[removed]& CANCELURL=[removed]& PAYMENTREQUEST_0_PAYMENTACTION=Sale& PAYMENTREQUEST_0_AMT=23.00& PAYMENTREQUEST_0_ITEMAMT=15.00& PAYMENTREQUEST_0_TAXAMT=5.00& PAYMENTREQUEST_0_SHIPPINGAMT=1.00& PAYMENTREQUEST_0_HANDLINGAMT=1.00& PAYMENTREQUEST_0_INSURANCEAMT=1.00& PAYMENTREQUEST_0_CURRENCYCODE=ILS& L_PAYMENTREQUEST_0_NAME0=The+name+of+product+1& L_PAYMENTREQUEST_0_NUMBER0=5543312& L_PAYMENTREQUEST_0_DESC0=The+description+of+product+1& L_PAYMENTREQUEST_0_AMT0=10&L_PAYMENTREQUEST_0_QTY0=1& L_PAYMENTREQUEST_0_NAME1=The+name+of+product+2& L_PAYMENTREQUEST_0_NUMBER1=4431234& L_PAYMENTREQUEST_0_DESC1=The+description+of+product+2& L_PAYMENTREQUEST_0_AMT1=5.00& L_PAYMENTREQUEST_0_QTY1=1.00& ALLOWNOTE=1& NOSHIPPING=1 而我得到的回应是: TIMESTAMP=2011%2d09%2d01T12%3a23%3a19Z& CORRELATIONID=cf89eeaa101ae& ACK=Failure& VERSION=2%2e3& BUILD=2085867& L_ERRORCODE0=10400& L_SHORTMESSAGE0=Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e& L_LONGMESSAGE0=Order%20total%20is%20missing%2e& L_SEVERITYCODE0=Error 我审查了paypal提供的文档和许多有关此问题的帖子,但我找不到我做错了什么. 任何帮助将不胜感激, Koby 解决方法
您的订单总参数缺少,因为您使用的是旧版本.您显示的API请求和您的响应不匹配.
你实际上提交了2.3版,而不是版本72.0 ..看到你的API响应:“VERSION = 2.3&” 以下请求和响应对我有用 API请求 USER=******************** PWD=******************** SIGNATURE=******************** METHOD=SetExpressCheckout VERSION=72.0 RETURNURL=******************** CANCELURL=******************** PAYMENTREQUEST_0_PAYMENTACTION=Sale PAYMENTREQUEST_0_AMT=23.00 PAYMENTREQUEST_0_ITEMAMT=15.00 PAYMENTREQUEST_0_TAXAMT=5.00 PAYMENTREQUEST_0_SHIPPINGAMT=1.00 PAYMENTREQUEST_0_HANDLINGAMT=1.00 PAYMENTREQUEST_0_INSURANCEAMT=1.00 PAYMENTREQUEST_0_CURRENCYCODE=ILS L_PAYMENTREQUEST_0_NAME0=The+name+of+product+1 L_PAYMENTREQUEST_0_NUMBER0=5543312 L_PAYMENTREQUEST_0_DESC0=The+description+of+product+1 L_PAYMENTREQUEST_0_AMT0=10&L_PAYMENTREQUEST_0_QTY0=1 L_PAYMENTREQUEST_0_NAME1=The+name+of+product+2 L_PAYMENTREQUEST_0_NUMBER1=4431234 L_PAYMENTREQUEST_0_DESC1=The+description+of+product+2 L_PAYMENTREQUEST_0_AMT1=5.00 L_PAYMENTREQUEST_0_QTY1=1.00 ALLOWNOTE=1 NOSHIPPING=1 API响应 TOKEN=EC-3UE641439J019845E TIMESTAMP=2011-09-01T17:13:17Z CORRELATIONID=4f7e60c2d70aa ACK=Success VERSION=72.0 BUILD=2085867 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何在ASP.NET MVC中执行[RequireHttps(Red
- asp.net-core – ASP.NET Core / MVC6中的WebTelemetryInit
- asp.net-mvc – Asp.Net MVC3 RC Razor视图:在块内嵌入代码
- .net – 什么是Automapper?
- stored-procedures – 如何在ASP.Net MVC(C#)中调用和执行存
- asp.net-mvc – 如何将URL参数绑定到具有不同名称的模型属性
- 获取当前ASP.NET Web Api 2操作的URL
- asp.net-mvc-3 – 如何格式化MVC Route参数?
- asp.net-mvc-3 – 将AuthorizeAttribute应用于控制器类并同
- asp.net-mvc – HTML.Hidden For value set
推荐文章
站长推荐
- asp.net-mvc – 删除布局将默认为_ViewStart,为什
- asp.net-mvc – ASP.NET MVC:HTTPContext和依赖
- oauth-2.0 – 连接Auth令牌并将其传递给启用了CO
- asp.net-mvc – 如何在运行时之前编译cshtml
- asp.net-mvc – 为什么在MVC中传递实体不是一个好
- asp.net – RegisterForEventValidation只能在渲
- asp.net-web-api – WebAPI 2属性路由启用会话状
- ASP.NET性能在32位/ 64位服务器之间降低
- asp.net – 在Application_BeginRequest中设置会
- asp.net – 通过http将数据从服务器推送到浏览器
热点阅读
