簡體   English   中英

Paypal IPN示例代碼沒有ActionResult。 如果沒有視圖,我打算如何給出網址?

[英]Paypal IPN sample code has no ActionResult. How am i meant to give a url if there is no view?

這是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();
}

暫無
暫無

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

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