402 Payment Required

HTTP 402 Payment Required 客户端错误响应状态码是一个非标准响应状态码,保留供将来使用。

创建此状态码是为了支持数字现金或(小额)支付系统,它将指示在客户端付款之前,请求的内容不可用。目前没有标准的使用约定,不同的系统在不同的上下文中使用它。

状态

http
402 Payment Required

示例

支付 API 失败

某些支付 API 使用 402 响应作为支付请求失败的通用捕获。以下示例尝试使用 POST 请求调用支付 API 以启动交易。

http
POST /merchant/transfers/payment HTTP/1.1
Host: payments.example.com
Content-Type: application/json
Content-Length: 402

{
  "payment_transfer": {
    "reference": "PAYMENT123456",
    "amount": "1337",
    "currency": "EUR",
    "sender_account_uri": "pan:5299920000000149;exp=2020-08;cvc=123",
    "sender": {
      "first_name": "Amelia",
      "middle_name": "Rosenburg",
      "email": "test123@sender.example.com"
    },
    "recipient": {
      "first_name": "Tyrone",
      "middle_name": "Johnston",
      "email": "test123@example.com",
      "merchant_id": "123"
    },
    "authentication_value": "ucaf:jJJLtQa+Iws8AREAEbjsA1MAAAA",
  }
}

如果交易出现问题,服务器会以 402 响应请求,在这种情况下,卡已过期。

http
HTTP/1.1 402 Payment Required
Date: Tue, 02 Jul 2024 12:56:49 GMT
Content-Type: application/json
Content-Length: 175

{
  "error": {
    "code": "expired_card",
    "doc_url": "https://example.com/error-codes#expired-card",
    "message": "The card has expired. Verify expiration or use a different card.",
  }
}

规范

规范
HTTP 语义
# status.402

兼容性说明

此状态码是保留的但未定义。实际实现中,响应的格式和内容各不相同。没有浏览器支持 402,错误将显示为通用的 4xx 状态码。

另见