// ── 3DS browser fingerprint ─────────────────────────────────────
//
// Wraps `Clover3DSUtil.getBrowserInfo()`. Clover requires the EMVCo 3DS2
// browser fingerprint on the charge request when 3DS is enabled; without it
// the charge fails with "Missing or invalid/incomplete browser_info for
// 3DSecure". We collect it at tokenization time and bundle it with the result.

import type { ThreeDSUtil, ThreeDsBrowserInfo } from './types';

export function getBrowserInfo(util: ThreeDSUtil | undefined | null): ThreeDsBrowserInfo | undefined {
  if (!util?.getBrowserInfo) {
    return undefined;
  }
  try {
    return util.getBrowserInfo();
  } catch (error) {
    console.warn('[wcp-payment-fields] getBrowserInfo failed', error);
    return undefined;
  }
}
