Skip to content
LogoLogo

Response.requirePayment

Create a 402 response

Creates a 402 Payment Required response with a WWW-Authenticate: Payment header. Optionally includes RFC 9457 Problem Details in the response body when an error is provided.

Usage

import {  } from 'mppx'
import {  } from 'mppx/server'
 
const  = .({
  : 'challenge-123',
  : 'tempo',
  : 'charge',
  : 'api.example.com',
  : {
    : '1.00',
    : '0x20c0000000000000000000000000000000000000',
    : '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  },
})
 
const  = .({  })
Response { status: 402, headers: { 'WWW-Authenticate': 'Payment ...' } }

Return type

type ReturnType = Response

A standard Response with status 402 and a WWW-Authenticate: Payment header containing the serialized Challenge. When an error is provided, the body contains a JSON problem details object with Content-Type: application/problem+json.

Parameters

challenge

  • Type: Challenge

The Challenge to serialize into the WWW-Authenticate header.

error (optional)

  • Type: PaymentError

An error to include as RFC 9457 Problem Details in the response body.

Problem details can include a method-specific details object and an actionable hint. Treat details as safe-to-expose diagnostic data only.