What Is a 402 Status Code?
Reserved for future use.
- Source: RFC7231 Section 6.5.2
402 CODE REFERENCES
Rails HTTP Status Symbol :payment_required
Go HTTP Status Constant http.StatusPaymentRequired
Symfony HTTP Status Constant Response::HTTP_PAYMENT_REQUIRED
Python2 HTTP Status Constant httplib.PAYMENT_REQUIRED
Python3+ HTTP Status Constant http.client.PAYMENT_REQUIRED
Python3.5+ HTTP Status Constant http.HTTPStatus.PAYMENT_REQUIRED
.NET HttpStatusCode.PaymentRequired
Rust http::StatusCode::PAYMENT_REQUIRED
Java java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED
Apache HttpComponents Core org.apache.hc.core5.http.HttpStatus.SC_PAYMENT_REQUIRED
Angular @angular/common/http/HttpStatusCode.PaymentRequired
402 status code example
Here’s an example of a request and response for a 402 status code:
Request
POST /checkout HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 124
{
"product_id": "1234",
"quantity": 2,
"billing_info": {
"name": "John Smith",
"credit_card_number": "1234567890123456",
"expiration_date": "05/26",
"cvv": "123"
}
}
Response
HTTP/1.1 402 Payment Required
Content-Type: text/plain
Retry-After: 300
Your account is not active. Please renew your subscription to complete this transaction.
In this example, the client is making a POST request to checkout for a product on the server. The server is indicating that the payment is required for the product and therefore the transaction cannot be completed at this time with a 402 Payment Required status code. The Retry-After header in the response specifies the number of seconds after which the client can retry the request.
The response also includes a message that indicates why the payment cannot be completed, in this case, that the client’s account is not active and the subscription needs to be renewed to complete the transaction.
The 402 status code is a non-standard HTTP status code that is not widely used, but it is intended to indicate that the client needs to make a payment before the request can be completed. It is typically used in situations where the client has an active account but requires additional payment to complete the transaction.
How to fix a 402 status code
A 402 status code indicates that a payment is required to complete the requested action. Therefore, to “fix” a 402 status code, the client must provide the necessary payment information and retry the request.
Here are the general steps to fix a 402 status code:
- Review the response message: The response message typically provides information on why the payment is required. It may be due to an expired subscription, insufficient funds, or other payment-related issues. Review the message to determine the specific issue.
- Provide the necessary payment information: If the issue is related to a payment method, such as an expired credit card, provide the updated payment information.
- Retry the request: After providing the necessary payment information, retry the request to complete the action.
- Verify the payment has been processed: Once the request is successfully completed, verify that the payment has been processed correctly.
If the issue cannot be resolved through providing payment information or retrying the request, contact the service provider or the organization responsible for handling the payment to resolve the issue.
In summary, to fix a 402 status code, the client must provide the necessary payment information and retry the request.
Additional resources
- Learn about web development
- Learn about SEO
- Web development services from WebFX
- SEO services from WebFX
- MDN Web Docs
- W3Schools
Marketing Tips for Niche Industries
- Travel and Tourism Marketing Budget
- Urgent Care Marketing Ideas: 5 High-ROI Tactics
- Vision Care Industry Statistics
- WebFX: Your Education Digital Marketing Agency
- Why Auto Part Retailers Need Digital Marketing
- Why Digital Marketing is Essential for Auctioneers
- Your Guide to Digital Marketing for Exercise Equipment Companies
- Your Guide to Digital Marketing for Industrial Repair Companies
- 2025 Professional Services Trends: Embracing the Future
- 6 Best Heavy Equipment Marketing Agencies