Skip to content

Function: decodePaymentResponseHeader() ​

ts
function decodePaymentResponseHeader(headerValue): 
  | {
  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;
};

Defined in: packages/x402-core/src/payment-header.ts:130

Parse a PAYMENT-RESPONSE header value into the settle answer it carries.

Throws on bad base64 / JSON, on nesting past MAX_PAYMENT_DEPTH, or when the value is not a settle answer: a boolean success, transaction and network strings on every answer (transaction may be empty), an errorReason string on a failure, payer, errorMessage and amount strings where present, and extensions an object where present. The reason is not checked against the codes this SDK knows, and fields it does not know pass through, so an answer from a newer facilitator still reads.

Parameters ​

headerValue ​

string

Returns ​

Type Literal ​

ts
{
  amount?: string;
  extensions?: {
   [key: string]: unknown;
  };
  network: string;
  payer?: string;
  success: true;
  transaction: string;
}

amount? ​

ts
amount?: string;

The amount settled, in atomic units, as the requirements' amount is.

extensions? ​

ts
extensions?: object;
Index Signature ​
ts
[key: string]: unknown

network ​

ts
network: string;

payer? ​

ts
payer?: string;

Optional in x402 v2, so a facilitator may leave it out.

success ​

ts
success: true;

transaction ​

ts
transaction: string;

Canton updateId of the executed transaction.


Type Literal ​

ts
{
  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? ​

ts
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 ​

ts
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? ​

ts
extensions?: object;
Index Signature ​
ts
[key: string]: unknown

network ​

ts
network: string;

payer? ​

ts
payer?: string;

success ​

ts
success: false;

transaction ​

ts
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.