【问题标题】:Reditect url from the method of notify_url of paypal in mvc从mvc中paypal的notify_url方法重定向url
【发布时间】:2015-10-17 14:44:51
【问题描述】:

我使用贝宝付款。在贝宝中,我找到了两种类型的 url -

  1. return_url
  2. notify_url

我想在交易后检查有效性,保存一些数据,然后将买家重定向到具有唯一值的收据页面,该值保存在数据库中。这就是为什么我不使用redirect_url

这是我的代码

[HttpPost]
        public ActionResult TestPaypalIpn()
        {
            var response = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8).ReadToEnd();

            var webClient = new WebClient();
            string address = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate&" + response;
            System.IO.File.WriteAllText(@"D:\Streamstech\Content\requestAddress.txt", address);

            try
            {
                string result = webClient.DownloadString(address);
                System.IO.File.WriteAllText(@"D:\Streamstech\Content\response.txt", result);
                if (result == "VERIFIED")
                {
                    if (Request.Params["payment_status"] == "Completed" && Request.Params["business"] == Request.Params["receiver_email"])
                    {
                        var lisenceKey = Request.Params["transaction_subject"];

                        var userProductLisence = UserProductLisenceRepository.GetConditional(
                        l => l.LisenceKey == lisenceKey).FirstOrDefault();

                        if (userProductLisence != null)
                        {
                            if (userProductLisence.PaypalTransactionId == null)
                            {
                                userProductLisence.PaypalTransactionId = Request.Params["txn_id"];
                                userProductLisence.PayerEmailForPaypalTransaction = Uri.EscapeUriString(Request.Params["payer_email"]);
                                UserProductLisenceRepository.Edit(userProductLisence);
                                return RedirectToAction("Receipt", "Transaction", new { requestId = userProductLisence.LisenceKey });
                            }
                        }
                    }
                    return RedirectToAction("ShowError", "Transaction", new { errorname = "", errorMessage = "something went wrong, try again later" });
                }
                return RedirectToAction("ShowError", "Transaction", new { errorname = "verification Problem", errorMessage = "Transaction not verified" });
            }
            catch (Exception e)
            {
                System.IO.File.WriteAllText(@"D:\Streamstech\Content\error.txt", e.Message);
                return RedirectToAction("ShowError", "Transaction", new { errorname = "Error..!!!", errorMessage = "something went wrong, try again later" });
                throw;
            }

            return null;
        }

在这里我可以比较,将数据保存到数据库.. 但它没有重定向到收据页面.. 代码中有什么问题...??

或任何建议我该怎么做..? 谢谢你。。

【问题讨论】:

    标签: asp.net-mvc-4 paypal paypal-ipn paypal-sandbox


    【解决方案1】:

    根据您的要求,您需要使用 return_url 而不是 notify_url。对于notify_url,它用于在系统后端接收消息,付款完成后您可能无法立即收到。参考https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/

    【讨论】:

      猜你喜欢
      • 2018-08-20
      • 1970-01-01
      • 2012-09-18
      • 2012-09-22
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      相关资源
      最近更新 更多