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 狀態碼。

另見