【问题标题】:IPN listner using .NET SDK Paypal?使用 .NET SDK Paypal 的 IPN 侦听器?
【发布时间】:2019-01-16 23:32:40
【问题描述】:

我正在使用 .NET SDK Paypal。我不确定 SDK 是否提供 IPN 侦听器功能。我试过下面的代码,它总是返回true,它是否是IPN验证的正确方法,我试图在谷歌上找到。但什么也没找到。

 var ipn = Request.Form.AllKeys.ToDictionary(k => k, k => Request[k]);

        var param = Request.BinaryRead(Request.ContentLength);
        PayPal.IPNMessage iPNMessage = new PayPal.IPNMessage(ipn, param);
        PayPal.IPNMessage service = null;

        try
        {
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();
            service = new PayPal.IPNMessage(configurationMap, param);
            var response = service.Validate();
        }
        catch (System.Exception ex)
        {
        }

当我尝试使用 HTTPWebRequest 时,它总是向我发送每笔交易的 INVALID:

这是我的代码:

 public HttpStatusCodeResult Receive()
    {
        LogRequest(Request);
        Task.Run(() => VerifyTask(Request));
        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

    private void VerifyTask(HttpRequestBase ipnRequest)
    {
        var verificationResponse = string.Empty;
        try
        {

            var verificationRequest = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
            verificationRequest.Method = "POST";
            verificationRequest.ContentType = "application/x-www-form-urlencoded";
            var param = Request.BinaryRead(ipnRequest.ContentLength);
            var strRequest = Encoding.ASCII.GetString(param);
            strRequest = "cmd=_notify-validate&" + strRequest;
            verificationRequest.ContentLength = strRequest.Length;
            var streamOut = new StreamWriter(verificationRequest.GetRequestStream(), Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            var streamIn = new StreamReader(verificationRequest.GetResponse().GetResponseStream());
            verificationResponse = streamIn.ReadToEnd();
            streamIn.Close();
        }
        catch (Exception exception)
        {
        }
        ProcessVerificationResponse(verificationResponse);
    }

【问题讨论】:

    标签: c# asp.net-mvc paypal sdk


    【解决方案1】:

    您必须使用 Paypal 网站上的 IPN 测试工具,除非您这样做,否则 Paypal 端没有匹配的交易,因此所有内容都将显示为无效。您当前使用的是沙盒端点,因此只会验证来自测试人员的请求。

    对于使用实际付款进行的实时交易,您不使用沙盒端点。

    【讨论】:

      猜你喜欢
      • 2012-10-09
      • 2012-05-20
      • 2019-06-22
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      • 2013-08-07
      • 2021-09-22
      • 2013-11-01
      相关资源
      最近更新 更多