Transport.from
Create a custom transport
Creates a custom server-side transport.
Usage
import { , , } from 'mppx'
import { } from 'mppx/server'
const = .<Request, Response>({
: ['Authorization'],
() {
const = ..('Authorization')
if (!) return null
const = .()
if (!) return null
return .()
},
: 'http',
({ , }) {
const : <string, string> = {
'WWW-Authenticate': .(),
'Cache-Control': 'no-store',
}
let : string | null = null
if () {
['Content-Type'] = 'application/problem+json'
= .(.(.))
}
return new (, { : 402, })
},
({ , }) {
const = new (.)
.('Payment-Receipt', .())
return new (., {
: .,
: .,
,
})
},
})Return type
type ReturnType = Transport<Input, ChallengeOutput, ReceiptResponse, ReceiptOutput>Parameters
bindCredential (optional)
- Type:
(options: { challenge: Challenge; credential: Credential; input: Input }) => Credential | Promise<Credential>
Rebinds a transport-native Credential to the normalized route Challenge. Use this when the wire format doesn't carry an MPP Challenge directly.
captureRequest (optional)
- Type:
(input: Input) => CapturedRequest | Promise<CapturedRequest>
Captures an immutable request snapshot for Challenge binding and later verification.
credentialHeaders (optional)
- Type:
readonly string[]
HTTP header names from which this transport can read Credentials. Composed methods use this list to keep Credentials scoped to their matching transport.
getCredential
- Type:
(input: Input) => Credential | null
Extracts Credential from the transport input. Returns null if no Credential was provided, or throws if malformed.
matchCredential (optional)
- Type:
(options: { input: Input; request: Record<string, unknown> }) => boolean | Promise<boolean>
Returns whether a transport-native Credential targets one configured payment request. Use this when several configured offers share the same wire method and intent.
name
- Type:
string
Transport name for identification.
respondChallenge
- Type:
(options: { challenge: Challenge; error?: PaymentError; input: Input }) => ChallengeOutput | Promise<ChallengeOutput>
Creates a transport response for a payment Challenge.
respondReceipt
- Type:
(options: { challengeId: string; credential: Credential; envelope?: VerifiedChallengeEnvelope; input: Input; receipt: Receipt; response: ReceiptResponse }) => ReceiptOutput
Attaches a Receipt to a successful response.
supportsStreamingReceipts (optional)
- Type:
boolean
Marks transports whose Receipt wrapper accepts route-produced async iterables. Framework adapters use this to preserve streaming payment accounting.