October 2025
Current State: Payment Request API returns
AbortError for both:
User clicks "X" → AbortError
How can we tell the difference?
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:
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
}
Links: