简体   繁体   English

使用.NET SDK Paypal的IPN列表器?

[英]IPN listner using .NET SDK Paypal?

I am working with .NET SDK Paypal. 我正在使用.NET SDK Paypal。 I am not sure if SDK provides the IPN listener feature. 我不确定SDK是否提供IPN侦听器功能。 I have tried below code, which always returns true, is it the correct way to IPN verification or not, I tried to find on google. 我试过下面的代码,该代码始终返回true,是否是IPN验证的正确方法,我尝试在Google上找到。 but didn't find anything. 但什么也没找到。

 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)
        {
        }

When I try with HTTPWebRequest, it always send me INVALID for every transaction: 当我尝试使用HTTPWebRequest时,它总是向我发送每笔交易的无效信息:

here is my code: 这是我的代码:

 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);
    }

You have to use the IPN tester tool on Paypals site, unless you do then there's no transaction on the Paypal end that will match so everything will show as invalid. 您必须在Paypals网站上使用IPN测试仪工具,除非您这样做,否则Paypal端没有匹配的交易,因此所有交易都将显示为无效。 You're currently using the Sandbox endpoint so that will only validate requests that come from the tester. 您当前正在使用沙盒端点,因此将仅验证来自测试器的请求。

For live transactions made with actual payments you don't use the sandbox endpoint. 对于使用实际付款进行的实时交易,请不要使用沙盒端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM