Function: encodePaymentResponseHeader()
function encodePaymentResponseHeader(response): string;Defined in: packages/x402-core/src/payment-header.ts:115
Serialise a settle answer into a PAYMENT-RESPONSE response header value: base64 of its UTF-8 JSON, as the x402 v2 HTTP transport carries it.
Parameters
response
| { amount?: string; extensions?: { [key: string]: unknown; }; network: string; payer?: string; success: true; transaction: string; } | { errorMessage?: string; errorReason: | "invalid_exact_canton_missing_proof" | "invalid_exact_canton_malformed_payload" | "invalid_exact_canton_signature_invalid" | "invalid_exact_canton_amount_mismatch" | "invalid_exact_canton_merchant_mismatch" | "invalid_exact_canton_instrument_id_mismatch" | "invalid_exact_canton_preapproval_missing" | "invalid_exact_canton_fee_payer_mismatch" | "invalid_exact_canton_expired" | "invalid_exact_canton_execute_before_too_far" | "invalid_exact_canton_insufficient_inputs" | "invalid_exact_canton_memo_mismatch" | "invalid_exact_canton_merchant_not_registered" | "invalid_exact_canton_self_payment" | "invalid_exact_canton_execute_failed" | "unexpected_canton_ledger_error" | "settlement_pending" | "invalid_network" | "unsupported_scheme" | "insufficient_funds" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "unexpected_verify_error" | "unexpected_settle_error" | "invalid_exact_canton_synchronizer_mismatch"; extensions?: { [key: string]: unknown; }; network: string; payer?: string; success: false; transaction: string; }
Type Literal
{ amount?: string; extensions?: { [key: string]: unknown; }; network: string; payer?: string; success: true; transaction: string; }
amount?
string = ...
The amount settled, in atomic units, as the requirements' amount is.
extensions?
{ [key: string]: unknown; } = ...
network
string = ...
payer?
string = ...
Optional in x402 v2, so a facilitator may leave it out.
success
true = ...
transaction
string = ...
Canton updateId of the executed transaction.
Type Literal
{ errorMessage?: string; errorReason: | "invalid_exact_canton_missing_proof" | "invalid_exact_canton_malformed_payload" | "invalid_exact_canton_signature_invalid" | "invalid_exact_canton_amount_mismatch" | "invalid_exact_canton_merchant_mismatch" | "invalid_exact_canton_instrument_id_mismatch" | "invalid_exact_canton_preapproval_missing" | "invalid_exact_canton_fee_payer_mismatch" | "invalid_exact_canton_expired" | "invalid_exact_canton_execute_before_too_far" | "invalid_exact_canton_insufficient_inputs" | "invalid_exact_canton_memo_mismatch" | "invalid_exact_canton_merchant_not_registered" | "invalid_exact_canton_self_payment" | "invalid_exact_canton_execute_failed" | "unexpected_canton_ledger_error" | "settlement_pending" | "invalid_network" | "unsupported_scheme" | "insufficient_funds" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "unexpected_verify_error" | "unexpected_settle_error" | "invalid_exact_canton_synchronizer_mismatch"; extensions?: { [key: string]: unknown; }; network: string; payer?: string; success: false; transaction: string; }
errorMessage?
string = ...
Human-readable text for errorReason. Free text that can change between facilitators, so match on the code, never on this (x402 v2 §9). Which of a code's causes it was goes in extensions.detail, as on verify.
errorReason
| "invalid_exact_canton_missing_proof" | "invalid_exact_canton_malformed_payload" | "invalid_exact_canton_signature_invalid" | "invalid_exact_canton_amount_mismatch" | "invalid_exact_canton_merchant_mismatch" | "invalid_exact_canton_instrument_id_mismatch" | "invalid_exact_canton_preapproval_missing" | "invalid_exact_canton_fee_payer_mismatch" | "invalid_exact_canton_expired" | "invalid_exact_canton_execute_before_too_far" | "invalid_exact_canton_insufficient_inputs" | "invalid_exact_canton_memo_mismatch" | "invalid_exact_canton_merchant_not_registered" | "invalid_exact_canton_self_payment" | "invalid_exact_canton_execute_failed" | "unexpected_canton_ledger_error" | "settlement_pending" | "invalid_network" | "unsupported_scheme" | "insufficient_funds" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "unexpected_verify_error" | "unexpected_settle_error" | "invalid_exact_canton_synchronizer_mismatch" = SettleErrorReasonSchema
extensions?
{ [key: string]: unknown; } = ...
network
string = ...
payer?
string = ...
success
false = ...
transaction
string = ...
The transaction the answer is about. Empty when nothing was relayed. On settlement_pending it is the payment's preparedTxHash: the relay went out and its outcome is not known yet.
Returns
string