/ HTTP Status Codes

402 Payment Required

The 402 Payment Required HTTP status code is an interesting and lesser-used status code that is part of the HTTP/1.1 standard. This page will provide an in-depth look at the 402 Payment Required status code, its intended purpose, and how it can be used in real-world scenarios. We will also examine examples of HTTP requests and responses involving this status code.

Introduction to 402 Payment Required

The 402 Payment Required status code is defined in the HTTP/1.1 specification (RFC 7231, Section 6.5.2) as follows:

The 402 Payment Required is reserved for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. As an example of its use, however, Apple’s MobileMe service generates a 402 error (“httpStatusCode:402” in the Mac OS X Console log) if the MobileMe account is delinquent.

In other words, the 402 Payment Required status code was initially intended for use in digital payment systems, but it has not been widely adopted for this purpose. However, this does not mean that the status code cannot be used in other contexts or applications where payment is required.

Example of 402 Payment Required

Let’s take a look at an example of an HTTP request and response that might involve the 402 Payment Required status code.

Request

Suppose you are accessing a premium API that requires payment for usage. You send the following HTTP GET request to the API:

GET /api/v1/premium-data HTTP/1.1
Host: example.com
Authorization: Bearer <your_access_token>

Response

If your payment for the premium API is overdue, the server might respond with the 402 Payment Required status code, as shown below:

HTTP/1.1 402 Payment Required
Content-Type: application/json
Date: Mon, 01 Jan 2022 12:00:00 GMT

{
  "error": "Payment Required",
  "message": "Your payment for the premium API is overdue. Please update your payment information to continue using the service."
}

In this case, the server provides a JSON object containing a descriptive error message, informing you that your payment is overdue and that you need to update your payment information to continue using the premium API.

Potential Use Cases

Although the 402 Payment Required status code has not been widely adopted, there are still some potential use cases where it might be applicable. These include:

  1. Paywalled content: Websites that offer premium content behind a paywall can use the 402 Payment Required status code to inform users that they must pay to access the content.
  2. APIs with paid plans: APIs that offer different tiers of service, including paid plans with additional features or usage limits, can use the 402 Payment Required status code to inform users that they must upgrade their plan to access certain functionality.
  3. Subscription-based services: Services that require a subscription for access, such as streaming platforms or online news websites, can use the 402 Payment Required status code to inform users that their subscription has expired or payment is overdue.

Summary

Although the 402 Payment Required status code was initially intended for use in digital payment systems, it has not been widely adopted for this purpose. However, this does not mean that the status code cannot be used in other contexts or applications where payment is required.

Was this helpful?

Thanks for your feedback!