我正在尝试设置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账户并且交易完成的事实。我误会了吗?为了取消交易,还有什么我应该做的吗?
答案 0 :(得分:0)
IPN功能是通知商家付款变动,包括;
收到付款,包括快速结账和自适应付款。
信用卡授权。
eCheck付款以及相关的待处理,已完成或已拒绝状态事件。
定期付款和订阅操作。
退款,纠纷,撤销和退款
如果您未验证发送给收听者的文本,则IPN不会取消付款。
PayPal的其他文章:https://developer.paypal.com/docs/classic/products/instant-payment-notification/