首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从mvc模式下paypal的notify_url方法看

从mvc模式下paypal的notify_url方法看
EN

Stack Overflow用户
提问于 2015-07-27 12:06:51
回答 1查看 615关注 0票数 0

我正在使用贝宝付款。在paypal里我发现了两种类型的url -

  1. return_url
  2. notify_url

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

这是我的密码

代码语言:javascript
运行
复制
[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;
        }

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-28 06:38:36

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31652683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档