IPN 验证不会在应该失败的时候失败

IPN validation doesn't fail when it should fail

我正在尝试设置 PayPal 来处理付款。一切正常,除了当我的 IPN 没有向 PayPal 发送验证消息时付款没有被取消。据我了解,如果 IPN 未验证付款,则交易应该被取消。 代码如下所示:

[HttpPost]
public IActionResult Receive()
{
    //Store the IPN received from PayPal
    LogRequest(Request);

    Task.Run(() => VerifyTask(Request));

    //Reply back a 200 code
    return new EmptyResult();
}

private void VerifyTask(HttpRequest ipnRequest)
{
    try
    {
        VerifyIpnParamsWithException(ipnRequest);
        var verificationRequest = (HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");

        //Set values for the verification request
        verificationRequest.Method = "POST";
        verificationRequest.ContentType = "application/x-www-form-urlencoded";
        var param = ReadRequestBody(ipnRequest.Body);
        var strRequest = Encoding.ASCII.GetString(param);

        //Add cmd=_notify-validate to the payload
        strRequest = "cmd=_notify-validate&" + strRequest;
        verificationRequest.ContentLength = strRequest.Length;

        //Attach payload to the verification request
        using (var streamOut = new StreamWriter(verificationRequest.GetRequestStream(), Encoding.ASCII))
        {
            streamOut.Write(strRequest);
            streamOut.Close();
        }
        var verificationResponse = string.Empty;

        //Send the request to PayPal and get the response
        using (var streamIn = new StreamReader(verificationRequest.GetResponse().GetResponseStream()))
        {
            verificationResponse = streamIn.ReadToEnd();
            streamIn.Close();
        }
        ProcessVerificationResponse(verificationResponse);
    }
    catch (Exception exception)
    {
        DAL.LogError(exception, ipnRequest);
    }
}

当我测试它时,根据我的日志,在向 PayPal 发送验证消息之前抛出了异常。这并没有改变钱被转移到PayPal账户并完成交易的事实。我误会了吗?为了取消交易,我还应该做些什么吗?

IPN 的功能是通知商家有关支付活动的信息,其中包括 ;

  • 收到的付款,包括快速结帐和自适应付款。

  • 信用卡授权。

  • eCheck 付款和相关的待处理、已完成或已拒绝状态事件。

  • 定期付款和订阅操作。

  • 退款、争议、撤销和退款

如果您不验证发送给您的收听者的文本,IPN 不会取消付款。

来自 PayPal 的更多文章:https://developer.paypal.com/docs/classic/products/instant-payment-notification/