Improved Error Codes for Payment Request API

GitHub Issue #1040 - W3C Payment Request Working Group

October 2025

The Problem 🚨

Current State: Payment Request API returns AbortError for both:

  • 👤 User intentionally canceling payment (closing window)
  • ⚠️ Actual errors during payment processing
PayPal checkout modal with close button highlighted

User clicks "X" → AbortError

How can we tell the difference?

Why This Matters 💡

For Merchants: Different callbacks for different scenarios

  • onCancel() - User intentionally abandoned checkout
  • onError() - Technical error occurred, maybe retry

Current Reality: PayPal SDK uses fragile string matching:

if ([
  "Request cancelled",              // Chrome <= 76, Opera 63
  "User closed the Payment Request UI.", // Chrome 77+, Edge 79+, Opera 64+
].includes(error.message)) {
  this.paymentFlowOptions.onCancel?.();
} else {
  this.paymentFlowOptions.onError?.(error);
}

Problems with this approach:

  • ⚠️ Browser-specific error messages
  • ⚠️ Messages can change between versions
  • ⚠️ No future-proof solution

Proposed Solution ✨

Use distinct error types:

  • AbortError → User intentionally abandoned transaction
  • OperationError → Checkout failures from uncaught errors

Feature Detection Approach:

const paymentRequest = new PaymentRequest(
  supportedMethods, 
  paymentDetails, 
  {enableOperationErrorCode: true}
);

// Feature detection
if (PaymentRequest.isErrorCodeSupported?.("OperationError")) {
  // Use new error codes
  if (error.name === "OperationError") {
    this.paymentFlowOptions.onError?.(error);
  } else {
    this.paymentFlowOptions.onCancel?.();
  }
} else {
  // Fallback to string matching
}

Q&A

Questions?

Links: