簡體   English   中英

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

[英]IPN listner using .NET SDK Paypal?

我正在使用.NET SDK Paypal。 我不確定SDK是否提供IPN偵聽器功能。 我試過下面的代碼,該代碼始終返回true,是否是IPN驗證的正確方法,我嘗試在Google上找到。 但什么也沒找到。

 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時,它總是向我發送每筆交易的無效信息:

這是我的代碼:

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

您必須在Paypals網站上使用IPN測試儀工具,除非您這樣做,否則Paypal端沒有匹配的交易,因此所有交易都將顯示為無效。 您當前正在使用沙盒端點,因此將僅驗證來自測試器的請求。

對於使用實際付款進行的實時交易,請不要使用沙盒端點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM