2

我在 ASP.net 中使用 PayPal,当我在沙盒中测试时,一切都是正确的,但是当我使用实时部分时,我收到了这个错误:

这笔付款无法完成,您的帐户也没有被扣款。请联系您的商家以获取更多信息。我们目前无法使用您的 PayPal 帐户处理您的付款。请返回商家网站并尝试使用其他付款方式(如果有)。

这是我的网络配置

 <add key="token" value="*************************"/>
  <add key="paypalemail" value="*************@gmail.com"/>
  <add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
  <add key="FailedURL" value="http://www.stockholmsbygg.net/Failed.aspx"/>
  <add key="SuccessURL" value="http://www.stockholmsbygg.net/FindOpenRequests.aspx"/>
  <add key="Notification" value="http://www.stockholmsbygg.net/Notification.aspx"/>

并重定向到贝宝

   public static string RedirectToPaypal(string invoiceNumber, string requestId, string userId, string customId, string itemName, string amount)
        {

            string redirecturl = "";
            redirecturl += "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();
            redirecturl += "&first_name=" + userId;
            redirecturl += "&item_name=" + itemName;
            redirecturl += "&amount=5.00";
            redirecturl += "&quantity=1";
            redirecturl += "&currency=SEK";
            redirecturl += "&invoice=" + invoiceNumber;
            redirecturl += "&custom=" + requestId;
            redirecturl += "&on0=" + HttpContext.Current.Request.UserHostAddress;
            redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString() + "?Type=ShowDetail";
            redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
            redirecturl += "&notify_url=" + ConfigurationManager.AppSettings["Notification"].ToString();
            return redirecturl;
        }

这是我从贝宝返回到我的地址后检查的所有内容

if (Request.QueryString["cm"] != null)
                        {

                             const string authToken = "*********************************";
                             string txToken = Request.QueryString["tx"];
                             string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;

                             //const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                           string strSandbox = "https://www.paypal.com/cgi-bin/webscr";
                             var req = (HttpWebRequest)WebRequest.Create(strSandbox);

                            req.Method = "POST";
                            req.ContentType = "application/x-www-form-urlencoded";
                             req.ContentLength = query.Length;


                             var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                           streamOut.Write(query);
                           streamOut.Close();
                           var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
                           string strResponse = streamIn.ReadToEnd();
                             streamIn.Close();

                             var results = new Dictionary<string, string>();
                             if (strResponse != "")
                             {
                                 var reader = new StringReader(strResponse);
                                 string line = reader.ReadLine();

                                 if (line == "SUCCESS")
                                 {

                                     while ((line = reader.ReadLine()) != null)
                                     {
                                         results.Add(line.Split('=')[0], line.Split('=')[1]);

                                     }
                                     var userId = Convert.ToInt64(Session["UserID"]);
                                     var item = Convert.ToInt64(Request.QueryString["cm"]);
                                     context = new entities();
                                     var existUser = context.Payments.Where(u => u.UserID == userId).ToList();
                                     var existItem = existUser.Where(i => i.RequestID == item).ToList();
                                     var paypalInvoice = results["invoice"];
                                     var txn_id = results["txn_id"];
                                     var sameInvoice =
                                         existItem.Where(i => i.invoice== paypalInvoice).FirstOrDefault();
                                     if (sameInvoice != null)
                                     {
                                         var currentAmount = Request.QueryString["amt"];
                                         var dbAmount = Convert.ToDecimal(sameInvoice.Amount).ToString();
                                         var currentIp = HttpContext.Current.Request.UserHostAddress;

                                         if (dbAmount != null)
                                         {
                                             if (currentAmount == dbAmount)
                                             {

                                                 if (currentIp == sameInvoice.IP)
                                                 {

                                                     sameInvoice.Status = true;
                                                     sameInvoice.PaypalTX = txn_id;
                                                     pnlSearch.Visible = false;
                                                     pnlShowDetail.Visible = true;
                                                     ShowDetail(Request.QueryString["cm"], true);
                                                     btnBack.Visible = false;
                                                     PrivateDetail.Visible = true;
                                                     interested.Visible = false;
                                                     context.SaveChanges();
                                                 }

                                             }
                                         }


                                     }

                                 }
                                 else if (line == "FAIL")
                                 {
                                     // Log for manual investigation
                                     Response.Write("Unable to retrive transaction detail");
                                 }
                             }
                             else
                             {
                                //unknown error
                                 Response.Write("ERROR");
                             }
                         }

问题是什么?同样在第一次测试时,我付了钱,但什么也没发生。发票状态仍然是假的,而自从我付款后它应该变成真的!

4

1 回答 1

1

这个函数是错误的 100%RedirectToPaypal()

没有重定向到贝宝。只有post带有发布参数的地址,而不是 get(重定向)。

这是合乎逻辑的,因为如果您将所有敏感数据放在 url 上,那么任何在中间的 ether 代理都会暴露给任何将 url 与所有数据一起保存的东西。

对我来说,如果您使用该数据进行重定向而不是发布,则在贝宝上找不到任何有关该帐户的信息,因为没有发布数据,这就是您收到该错误的原因。

于 2012-09-30T15:33:02.197 回答