【问题标题】:Paypal PDT returns Fail always to my HTTP post request C# MVCPaypal PDT 总是向我的 HTTP 发布请求 C# MVC 返回失败
【发布时间】:2016-04-20 12:06:38
【问题描述】:

我遇到了一种非常奇怪的问题,即在成功支付交易后,我无法获得附加返回 URL 的 TransactionId。由于 Paypal 自动将我重定向到我在 PDT 设置页面中提到的 ReturnUrl,并且 Paypal 将 trasactionId 附加到此名为 tx 的返回Url 并使用该 trasactionId 我向此 Url 发出 Post 请求

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

但问题是我无法获得该 transactionId?任何人都可以帮助我解决这个问题,这可能是什么问题。这是我用来发出 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();

如果我通过浏览器直接请求此 URL 并附加 TransactionId 和 IdentityToken ,那么我会得到成功响应,但是这样我就不会得到 transactionId 并且我的响应总是失败。请帮助我解决这个问题。我的代码中可能有什么问题或解决此问题的任何其他问题。感谢您的宝贵时间。

【问题讨论】:

    标签: c# paypal


    【解决方案1】:

    我使用 MVC,因此使用模型绑定从查询字符串中获取 tx 值。但我不认为这是你的问题。

    必须按照您所说的那样设置返回 URL。此外,必须在指定 URL 的同一位置打开 PDT。此外,不幸的是,如果客户使用信用卡而不是 PayPal 帐户,他们将不会自动返回您的网站。

    我正在实施 IPN,因为信用卡客户可能不会返回该网站。

    【讨论】:

    • 客户会自动返回到我们的网站成功页面,如果我们将我们的网站设置为使用 Paypal iframe 进行付款处理,那么当我们在 paypal 网站而不是我们的网站上完成付款处理时,您所说的情况是有效的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2019-09-30
    • 1970-01-01
    • 2016-08-17
    • 2020-12-11
    • 2010-10-16
    • 2014-01-25
    相关资源
    最近更新 更多