从mvc中paypal的notify_url方法重定向url

Reditect url from the method of notify_url of paypal in mvc

我正在使用贝宝付款。在 paypal 中我发现了两种类型 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;
        }

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

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

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