gpt4 book ai didi

c# - Paypal IPN 示例代码没有 ActionResult。如果没有 View ,我将如何提供 URL?

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:54 24 4
gpt4 key购买 nike

这是 ipn 的 paypals 示例代码。我已经用了几天了,但一无所获。我不确定我要调用什么。在上一个问题中,我问过一些人说您不调用 Receive 方法。所以这让我开始思考 Paypal 将如何知道去哪里。 (即使用什么方法。)

public class IPNController : Controller
{
[HttpPost]
public HttpStatusCodeResult Receive()
{
//Store the IPN received from PayPal
LogRequest(Request);

//Fire and forget verification task
Task.Run(() => VerifyTask(Request));

//Reply back a 200 code
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");

//Set values for the verification request
verificationRequest.Method = "POST";
verificationRequest.ContentType = "application/x-www-form-urlencoded";
var param = Request.BinaryRead(ipnRequest.ContentLength);
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
var streamOut = new StreamWriter(verificationRequest.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();

//Send the request to PayPal and get the response
var streamIn = new StreamReader(verificationRequest.GetResponse().GetResponseStream());
verificationResponse = streamIn.ReadToEnd();
streamIn.Close();

}
catch ( Exception exception)
{
//Capture exception for manual investigation
}

ProcessVerificationResponse(verificationResponse);
}


private void LogRequest(HttpRequestBase request)
{
// Persist the request values into a database or temporary data store
}

private void ProcessVerificationResponse(string verificationResponse)
{
if (verificationResponse.Equals("VERIFIED"))
{
// check that Payment_status=Completed
// check that Txn_id has not been previously processed
// check that Receiver_email is your Primary PayPal email
// check that Payment_amount/Payment_currency are correct
// process payment
}
else if (verificationResponse.Equals("INVALID"))
{
//Log for manual investigation
}
else
{
//Log error
}
}
}

没有 ActionResult 所以我怎么打算给一个 URL。想到这个但是好像返回无效

public ActionResult IPN() {
Receive()


}

我已经问过之前的问题,但似乎仍然无法理解这个 IPN。

最佳答案

对于任何看到这个的人来说,这是一个没有经验的我,我所要做的就是返回 Ok() 所以我的操作结果如下所示:

public ActionResult IPN() 
{
Receive();
return Ok();
}

关于c# - Paypal IPN 示例代码没有 ActionResult。如果没有 View ,我将如何提供 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com