ProfK
ProfK

Reputation: 51063

What do I return from a POST action called from an external site?

I have a Payment controller, which exposes an HttpPost action method called Notify. This action is posted to when my external payment service sends me an Immediate Payment Notification (IPN), and it's sole purpose is to update my data based on the data I receive in the IPN. It never returns a view, so what should my action method return? I'm sure the payment service wants an HTTP 200 or something in response to the IPN post.

Upvotes: 1

Views: 108

Answers (3)

Chris Marisic
Chris Marisic

Reputation: 33098

return new HttpStatusCodeBoundedResult(200, "IPN accepted");
return new HttpStatusCodeBoundedResult(400, "Bad IPN request");

.

public class HttpStatusCodeBoundedResult : HttpStatusCodeResult
{
    /// <summary>
    /// Initializes a new instance of <see cref="HttpStatusCodeBoundedResult"/>.
    /// </summary>
    /// <param name="statusCode">The status code.</param>
    public HttpStatusCodeBoundedResult(int statusCode) : base(statusCode)
    {
    }

    /// <summary>
    /// Initializes a new instance of <see cref="HttpStatusCodeBoundedResult"/>.
    /// </summary>
    /// <param name="statusCode">The status code.</param>
    /// <param name="statusDescription">The status description. Will be 
    ///   truncated to  512 characters and have \r\n characters stripped.</param>
    public HttpStatusCodeBoundedResult(int statusCode, string statusDescription)
        : base(statusCode, ApplyHttpResponseBoundary(statusDescription, 512))
    {
    }

    private static string ApplyHttpResponseBoundary(string input, int length)
    {
        input = input.Replace("\r", string.Empty).Replace("\n", string.Empty);

        return input.Length <= length ? input : input.Substring(0, length);
    }
}

Upvotes: 1

SLaks
SLaks

Reputation: 887225

You can just make it return void.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You could return an empty result:

return new EmptyResult();

Upvotes: 1

Related Questions