简体   繁体   English

贝宝PDT总是对我的HTTP发布请求C#MVC返回Fail

[英]Paypal PDT returns Fail always to my HTTP post request C# MVC

I am facing very weird kind of problem that after successful payment transaction, I am not able to get TransactionId appended with returningUrl. 我面临一种很奇怪的问题,即在成功完成付款交易后,我无法将TransactionId附加到returningUrl后面。 Since Paypal auto redirects me to my ReturnUrl which I have mentioned in PDT settings page, and Paypal appends the trasactionId to this returningUrl named tx and using that trasactionId I make a Post request to this Url 由于Paypal自动将我重定向到我在PDT设置页面中提到的ReturnUrl,并且Paypal将trasactionId附加到名为tx的returningUrl上,并使用该trasactionId向此Url发出发布请求

https://www.sandbox.paypal.com/cgi-bin/webscr https://www.sandbox.paypal.com/cgi-bin/webscr

But here is the problem that I am not able to get that transactionId? 但是,这是我无法获取该transactionId的问题? what could be the problem kindly any body help me in this issue. 可能是什么问题,任何机构都可以帮助我解决这个问题。 This is my code that I am using to make an HTTP post request. 这是我用来发出HTTP发布请求的代码。

string authTokenTest = "sMfRi9rJN3AjqsejnMxFfkeIwhwrCmVZz3nplUy9V6a9Yq0_2YdugSvZYNa";

            //used this but could not retrieved "tx" 
            //string txToken = Request.QueryString.Get("tx"); 
            //Then used this but no use
            var queryValues = HttpUtility.ParseQueryString(Request.Url.Query);
            var txToken = queryValues["tx"];

            string query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authTokenTest);

            //// Create the request back


            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            string url = strSandbox;

            /// to use HTTP 1.1 and TLS 1.2
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            ServicePointManager.DefaultConnectionLimit = 9999;

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            // Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;

            // Write the request back IPN strings
            StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(query);
            stOut.Close();

            // Do the request to PayPal and get the response

            HttpWebResponse payResp = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(payResp.GetResponseStream());
            string strResponse = sr.ReadToEnd();
            sr.Close();

If I make a direct request to this URL via browser and append a TransactionId and IdentityToken then I get the success response, but in this way I am not getting any way the transactionId and my Response is always Fail. 如果我通过浏览器对此URL发出直接请求,并附加一个TransactionId和IdentityToken,那么我将获得成功响应,但是通过这种方式,我不会以任何方式获得transactionId,并且我的响应始终为Fail。 Kindly help my in this problem. 请帮助我解决这个问题。 What could be the issue in my code or any other problem to resolve this issue. 我的代码中可能有什么问题或解决此问题的任何其他问题。 Thanks for your time. 谢谢你的时间。

I use MVC and so use model binding to get the tx value from the query string. 我使用MVC,因此使用模型绑定从查询字符串获取tx值。 But I don't think that's your problem. 但我认为这不是您的问题。

The Return URL has to be set, as you said you did. 如您所说,必须设置Return URL。 Also PDT has to be turned on in the same place the URL is specified. 同样,必须在指定URL的同一位置打开PDT。 Also, unfortunately, customers will not be returned automatically to your site if they use a credit card instead of a PayPal account. 同样,不幸的是,如果客户使用信用卡而不是PayPal帐户,他们也不会自动返回您的网站。

I'm implementing IPN though because credit card customers may not return to the site. 我正在实施IPN,因为信用卡客户可能不会返回该站点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM