@funnelfox/billing 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -559,7 +559,7 @@ var PaymentMethod;
559
559
  /**
560
560
  * @fileoverview Constants for Funnefox SDK
561
561
  */
562
- const SDK_VERSION = '0.13.1';
562
+ const SDK_VERSION = '0.13.2';
563
563
  const DEFAULTS = {
564
564
  BASE_URL: 'https://billing.funnelfox.com',
565
565
  REGION: 'default',
@@ -1375,11 +1375,13 @@ class APIClient {
1375
1375
  }
1376
1376
  }
1377
1377
  /**
1378
- * Sends the request exactly once: no retry and no client timeout (FFB-704, decision 9).
1378
+ * Sends the request exactly once: no retry and, without `timeoutMs`, no client timeout
1379
+ * (FFB-704, decision 9).
1379
1380
  * Same URL, headers and error classes as `request()`. Used only by `silentPurchase`'s
1380
- * `handle3DS` mode for `one_click` and `resume_payment`, which must not be POSTed twice.
1381
+ * `handle3DS` mode for `one_click` and `resume_payment`, which must not be POSTed twice;
1382
+ * `one_click` is re-sent by the caller only with the same idempotency key.
1381
1383
  */
1382
- async requestOnce(endpoint, options = {}) {
1384
+ async requestOnce(endpoint, options = {}, timeoutMs) {
1383
1385
  const url = `${this.baseUrl}/${this.orgId}${endpoint}`;
1384
1386
  const requestOptions = {
1385
1387
  method: 'GET',
@@ -1391,7 +1393,10 @@ class APIClient {
1391
1393
  ...options,
1392
1394
  };
1393
1395
  try {
1394
- return await this._makeRequest(url, requestOptions);
1396
+ const request = this._makeRequest(url, requestOptions);
1397
+ return await (timeoutMs
1398
+ ? withTimeout(request, timeoutMs, 'Request timed out')
1399
+ : request);
1395
1400
  }
1396
1401
  catch (error) {
1397
1402
  if (error instanceof APIError) {
@@ -1597,11 +1602,11 @@ class APIClient {
1597
1602
  }));
1598
1603
  }
1599
1604
  /** `one_click`, POSTed exactly once (see `requestOnce`). */
1600
- async oneClickOnce(payload) {
1605
+ async oneClickOnce(payload, timeoutMs) {
1601
1606
  return (await this.requestOnce(API_ENDPOINTS.ONE_CLICK, {
1602
1607
  method: 'POST',
1603
1608
  body: JSON.stringify(payload),
1604
- }));
1609
+ }, timeoutMs));
1605
1610
  }
1606
1611
  /** `resume_payment`, POSTed exactly once (see `requestOnce`). */
1607
1612
  async resumePaymentOnce(params) {
@@ -2154,6 +2159,9 @@ class CheckoutInstance extends EventEmitter {
2154
2159
  this.counter = 0;
2155
2160
  this.cachedSessionResponse = null;
2156
2161
  this.taxRecalcSeq = 0;
2162
+ // WebKit allows one ApplePaySession per page: a second tap while the sheet is
2163
+ // still opening throws InvalidAccessError, but Primer asks to start first.
2164
+ this.isApplePaySheetOpen = false;
2157
2165
  this.cardSessionFieldConfig = {};
2158
2166
  this.isTelemetryEnabled = false;
2159
2167
  this.telemetryCleanup = null;
@@ -2320,6 +2328,7 @@ class CheckoutInstance extends EventEmitter {
2320
2328
  primerHandler.handleFailure(error?.message || 'Payment processing failed');
2321
2329
  }
2322
2330
  finally {
2331
+ this.isApplePaySheetOpen = false;
2323
2332
  this.onLoaderChangeWithRace(false);
2324
2333
  this._setState('ready');
2325
2334
  }
@@ -2345,6 +2354,7 @@ class CheckoutInstance extends EventEmitter {
2345
2354
  primerHandler.handleFailure(error?.message || 'Payment processing failed');
2346
2355
  }
2347
2356
  finally {
2357
+ this.isApplePaySheetOpen = false;
2348
2358
  this.emit(EVENTS.PURCHASE_COMPLETED);
2349
2359
  this.onLoaderChangeWithRace(false);
2350
2360
  this._setState('ready');
@@ -2673,6 +2683,7 @@ class CheckoutInstance extends EventEmitter {
2673
2683
  onTokenizeSuccess: this.handleTokenizeSuccess,
2674
2684
  onResumeSuccess: this.handleResumeSuccess,
2675
2685
  onResumeError: error => {
2686
+ this.isApplePaySheetOpen = false;
2676
2687
  if (error.stack?.includes('PROCESSOR_3DS') &&
2677
2688
  error.code === 'RESUME_ERROR' &&
2678
2689
  error.message?.includes('fetch resume key')) {
@@ -2682,15 +2693,23 @@ class CheckoutInstance extends EventEmitter {
2682
2693
  this.emit(EVENTS.PURCHASE_FAILURE, error);
2683
2694
  },
2684
2695
  onCheckoutFail: error => {
2696
+ this.isApplePaySheetOpen = false;
2685
2697
  this.emit(EVENTS.PURCHASE_FAILURE, error);
2686
2698
  },
2687
2699
  onTokenizeError: error => {
2700
+ this.isApplePaySheetOpen = false;
2688
2701
  this.emit(EVENTS.PURCHASE_FAILURE, error);
2689
2702
  },
2690
2703
  onTokenizeStart: () => {
2691
2704
  wasPaymentProcessedStarted = true;
2692
2705
  },
2693
2706
  onTokenizeShouldStart: data => {
2707
+ if (data.paymentMethodType === PaymentMethod.APPLE_PAY) {
2708
+ if (this.isApplePaySheetOpen) {
2709
+ return false;
2710
+ }
2711
+ this.isApplePaySheetOpen = true;
2712
+ }
2694
2713
  this.activePaymentMethodType = data.paymentMethodType;
2695
2714
  this.emit(EVENTS.ERROR, undefined);
2696
2715
  this.emit(EVENTS.START_PURCHASE, data.paymentMethodType);
@@ -2702,6 +2721,7 @@ class CheckoutInstance extends EventEmitter {
2702
2721
  this.emit(EVENTS.ERROR, undefined);
2703
2722
  break;
2704
2723
  case 'PAYMENT_METHOD_UNSELECTED':
2724
+ this.isApplePaySheetOpen = false;
2705
2725
  if (!wasPaymentProcessedStarted) {
2706
2726
  this.emit(EVENTS.PURCHASE_CANCELLED);
2707
2727
  }
@@ -2981,11 +3001,23 @@ class CheckoutInstance extends EventEmitter {
2981
3001
  * checkout, tokenize a vaulted instrument through the vault manager as a stand-in, and in
2982
3002
  * `onTokenizeSuccess` continue with the one-click `action_required_token` instead. Primer then
2983
3003
  * shows its 3DS overlay; `onResumeSuccess` yields the resume token for `resume_payment`.
3004
+ *
3005
+ * With processor 3DS (`PROCESSOR_3DS`) Primer frames the processor's hosted 3DS page and cannot
3006
+ * tell a frictionless check from a challenge, and nothing reaches the page from the cross-origin
3007
+ * frame (FFB-758 spike). A frictionless check finishes within ~5 s, so the overlay stays
3008
+ * invisible for `THREE_DS_OVERLAY_REVEAL_DELAY_MS` and only then counts as a shown challenge.
2984
3009
  */
2985
3010
  /** Primer client-token intents that carry a 3DS step. */
2986
3011
  const PRIMER_3DS_INTENTS = ['3DS_AUTHENTICATION', 'PROCESSOR_3DS'];
2987
3012
  /** Default `threeDSTimeoutMs`. */
2988
3013
  const DEFAULT_THREE_DS_TIMEOUT_MS = 600000;
3014
+ /**
3015
+ * How long Primer's 3DS overlay stays invisible. Frictionless checks on billing-dev took
3016
+ * 4.2-5.0 s from overlay to resume; a real challenge is shown this much later.
3017
+ */
3018
+ const THREE_DS_OVERLAY_REVEAL_DELAY_MS = 6000;
3019
+ /** Primer's 3DS overlay (Primer Web SDK 2.57.3, verified in the FFB-758 spike). */
3020
+ const PRIMER_OVERLAY_SELECTOR = '#primer-overlay';
2989
3021
  /** Close button of Primer's 3DS overlay (Primer Web SDK 2.57.3, verified in the spike). */
2990
3022
  const PRIMER_OVERLAY_CLOSE_SELECTOR = '[data-testid="OverlayContent.closeButton"]';
2991
3023
  /** Decodes the `intent` of a Primer client token (a JWT); `null` if it is not one. */
@@ -3029,6 +3061,26 @@ function dismissPrimerOverlay() {
3029
3061
  const button = document.querySelector(PRIMER_OVERLAY_CLOSE_SELECTOR);
3030
3062
  button?.click();
3031
3063
  }
3064
+ /** Hides Primer's overlay until the returned function is called. */
3065
+ function hidePrimerOverlay() {
3066
+ if (typeof document === 'undefined') {
3067
+ return () => { };
3068
+ }
3069
+ const style = document.createElement('style');
3070
+ style.textContent = `${PRIMER_OVERLAY_SELECTOR}{opacity:0!important;pointer-events:none!important}`;
3071
+ document.head.appendChild(style);
3072
+ return () => style.remove();
3073
+ }
3074
+ /**
3075
+ * A Primer update that renames the overlay would leave it visible during the hidden phase, while
3076
+ * `threeDSChallenged` stays false for a check that finishes in that time.
3077
+ */
3078
+ function warnIfOverlayNotFound() {
3079
+ if (typeof document !== 'undefined' &&
3080
+ !document.querySelector(PRIMER_OVERLAY_SELECTOR)) {
3081
+ console.warn(`[FunnelfoxSDK] Primer 3DS overlay ${PRIMER_OVERLAY_SELECTOR} not found`);
3082
+ }
3083
+ }
3032
3084
  function toPrimerError(message, error) {
3033
3085
  return error instanceof PrimerError ? error : new PrimerError(message, error);
3034
3086
  }
@@ -3059,6 +3111,9 @@ async function runOneClickThreeDS(params) {
3059
3111
  return new Promise(resolve => {
3060
3112
  let settled = false;
3061
3113
  let tokenized = false;
3114
+ let revealed = false;
3115
+ let revealTimer = null;
3116
+ let showOverlay = () => { };
3062
3117
  // True only while create_client_session is in flight.
3063
3118
  let sessionInFlight = false;
3064
3119
  let timer = null;
@@ -3072,12 +3127,17 @@ async function runOneClickThreeDS(params) {
3072
3127
  clearTimeout(timer);
3073
3128
  timer = null;
3074
3129
  }
3130
+ if (revealTimer) {
3131
+ clearTimeout(revealTimer);
3132
+ revealTimer = null;
3133
+ }
3134
+ showOverlay();
3075
3135
  headless = null;
3076
3136
  resolve(result);
3077
3137
  };
3078
- timer = setTimeout(() => {
3138
+ const onTimeout = () => {
3079
3139
  timer = null;
3080
- if (tokenized) {
3140
+ if (revealed) {
3081
3141
  // The challenge was shown and the customer did not finish it.
3082
3142
  settle({ kind: 'abandoned' });
3083
3143
  // Close Primer's overlay; the close error it raises is ignored (already settled).
@@ -3093,17 +3153,37 @@ async function runOneClickThreeDS(params) {
3093
3153
  });
3094
3154
  return;
3095
3155
  }
3156
+ if (tokenized) {
3157
+ // The overlay is about to be shown: the reveal restarts the timer.
3158
+ return;
3159
+ }
3096
3160
  settle({
3097
3161
  kind: 'error',
3098
3162
  error: new PrimerError('Timed out before the 3DS challenge was shown (threeDSTimeoutMs)'),
3099
3163
  });
3100
- }, timeoutMs);
3164
+ };
3165
+ timer = setTimeout(onTimeout, timeoutMs);
3101
3166
  const onTokenizeSuccess = (_data, handler) => {
3102
- if (settled) {
3167
+ // A repeated tokenization would start a second reveal timer, so the challenge
3168
+ // (and the caller's onThreeDSStart) would be reported twice: refuse it.
3169
+ if (settled || tokenized) {
3103
3170
  callSafely(() => handler.handleFailure());
3104
3171
  return;
3105
3172
  }
3106
3173
  tokenized = true;
3174
+ showOverlay = hidePrimerOverlay();
3175
+ revealTimer = setTimeout(() => {
3176
+ revealTimer = null;
3177
+ revealed = true;
3178
+ showOverlay();
3179
+ warnIfOverlayNotFound();
3180
+ callSafely(params.onChallengeShown);
3181
+ // The whole timeout belongs to the challenge the customer can see.
3182
+ if (timer) {
3183
+ clearTimeout(timer);
3184
+ }
3185
+ timer = setTimeout(onTimeout, timeoutMs);
3186
+ }, params.revealDelayMs);
3107
3187
  // Ignore the stand-in vaulted token: run the one-click 3DS action instead.
3108
3188
  handler.continueWithNewClientToken(actionToken);
3109
3189
  };
@@ -3117,6 +3197,10 @@ async function runOneClickThreeDS(params) {
3117
3197
  clearTimeout(timer);
3118
3198
  timer = null;
3119
3199
  }
3200
+ if (revealTimer) {
3201
+ clearTimeout(revealTimer);
3202
+ revealTimer = null;
3203
+ }
3120
3204
  let response;
3121
3205
  try {
3122
3206
  response = await apiClient.resumePaymentOnce({
@@ -3370,7 +3454,80 @@ async function silentPurchaseLegacy(options) {
3370
3454
  }
3371
3455
  const ONE_CLICK_IN_PROGRESS = 'one_click_in_progress';
3372
3456
  const DOUBLE_PURCHASE = 'double_purchase';
3457
+ const IDEMPOTENCY_KEY_IN_PROGRESS = 'idempotency_key_in_progress';
3458
+ const ONE_CLICK_RETRY_DELAYS_MS = [1000, 2000, 4000];
3459
+ /** Longer than the backend's wait for the user's lock (~12.6 s). */
3460
+ const ONE_CLICK_TIMEOUT_MS = 25000;
3373
3461
  const oneClickInFlight = new Set();
3462
+ /** A random UUID v4, or `null` when the browser has no crypto (then one_click is not retried). */
3463
+ function createIdempotencyKey() {
3464
+ const cryptoApi = typeof crypto === 'undefined' ? undefined : crypto;
3465
+ if (typeof cryptoApi?.randomUUID === 'function') {
3466
+ return cryptoApi.randomUUID();
3467
+ }
3468
+ if (typeof cryptoApi?.getRandomValues !== 'function') {
3469
+ return null;
3470
+ }
3471
+ const bytes = cryptoApi.getRandomValues(new Uint8Array(16));
3472
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
3473
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
3474
+ const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0'));
3475
+ return [
3476
+ hex.slice(0, 4).join(''),
3477
+ hex.slice(4, 6).join(''),
3478
+ hex.slice(6, 8).join(''),
3479
+ hex.slice(8, 10).join(''),
3480
+ hex.slice(10, 16).join(''),
3481
+ ].join('-');
3482
+ }
3483
+ /**
3484
+ * Failures after which the backend may or may not have processed the request. Retrying them
3485
+ * with the same idempotency key is safe: the backend never charges a key twice (FFB-757).
3486
+ * A 2xx APIError means the body could not be parsed.
3487
+ */
3488
+ function isRetryableOneClickError(error) {
3489
+ if (error instanceof NetworkError) {
3490
+ return true;
3491
+ }
3492
+ if (!(error instanceof APIError) || error.statusCode === null) {
3493
+ return false;
3494
+ }
3495
+ if (error.statusCode >= 500) {
3496
+ return true;
3497
+ }
3498
+ if (error.statusCode >= 200 && error.statusCode < 300) {
3499
+ return true;
3500
+ }
3501
+ return (error.statusCode === 400 && error.errorCode === IDEMPOTENCY_KEY_IN_PROGRESS);
3502
+ }
3503
+ function isEmptyResponse(response) {
3504
+ return !response || typeof response !== 'object' || !('status' in response);
3505
+ }
3506
+ /** `one_click`, retried with the same idempotency key; sent once when there is no key. */
3507
+ async function postOneClick(apiClient, payload) {
3508
+ if (!payload.idempotency_key) {
3509
+ return apiClient.oneClickOnce(payload);
3510
+ }
3511
+ for (const delay of ONE_CLICK_RETRY_DELAYS_MS) {
3512
+ try {
3513
+ const response = await apiClient.oneClickOnce(payload, ONE_CLICK_TIMEOUT_MS);
3514
+ if (!isEmptyResponse(response)) {
3515
+ return response;
3516
+ }
3517
+ }
3518
+ catch (error) {
3519
+ if (!isRetryableOneClickError(error)) {
3520
+ throw error;
3521
+ }
3522
+ }
3523
+ await sleep(delay);
3524
+ }
3525
+ const response = await apiClient.oneClickOnce(payload, ONE_CLICK_TIMEOUT_MS);
3526
+ if (isEmptyResponse(response)) {
3527
+ throw new NetworkError('one_click returned an empty response');
3528
+ }
3529
+ return response;
3530
+ }
3374
3531
  function declineFields(data) {
3375
3532
  return {
3376
3533
  failedMessageForUser: data.failed_message_for_user ?? null,
@@ -3459,7 +3616,7 @@ function mapOneClickResponse(response) {
3459
3616
  }
3460
3617
  }
3461
3618
  /** Maps a `resume_payment` response after a challenge (rows 5, 6, 6b, 6c, 7, 8). */
3462
- function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS_AUTH_DECLINE_CODES) {
3619
+ function mapResumeResponse(response, orderId, threeDSChallenged, threeDSAuthDeclineCodes = THREE_DS_AUTH_DECLINE_CODES) {
3463
3620
  const data = response?.data;
3464
3621
  if (response?.status !== 'success' || !data) {
3465
3622
  return {
@@ -3467,7 +3624,7 @@ function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS
3467
3624
  result: {
3468
3625
  outcome: 'error',
3469
3626
  orderId,
3470
- threeDSChallenged: true,
3627
+ threeDSChallenged,
3471
3628
  error: envelopeError(response, 'Resume payment failed'),
3472
3629
  failedRequest: 'resume_payment',
3473
3630
  },
@@ -3480,7 +3637,7 @@ function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS
3480
3637
  result: {
3481
3638
  outcome: 'error',
3482
3639
  orderId,
3483
- threeDSChallenged: true,
3640
+ threeDSChallenged,
3484
3641
  error: new FunnefoxSDKError('resume_payment returned another action token; chained 3DS is not supported', 'one_click_chained_action'),
3485
3642
  },
3486
3643
  };
@@ -3489,22 +3646,24 @@ function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS
3489
3646
  case 'succeeded':
3490
3647
  return {
3491
3648
  threeDS: 'passed',
3492
- result: { outcome: 'succeeded', orderId, threeDSChallenged: true },
3649
+ result: { outcome: 'succeeded', orderId, threeDSChallenged },
3493
3650
  };
3494
3651
  case 'processing':
3495
3652
  return {
3496
3653
  threeDS: 'passed',
3497
- result: { outcome: 'processing', orderId, threeDSChallenged: true },
3654
+ result: { outcome: 'processing', orderId, threeDSChallenged },
3498
3655
  };
3499
3656
  case 'failed': {
3500
- const authFailed = threeDSAuthDeclineCodes === null ||
3501
- threeDSAuthDeclineCodes.includes(data.decline_code ?? '');
3657
+ // Without a shown challenge the customer saw no 3DS step: a decline is a plain decline.
3658
+ const authFailed = threeDSChallenged &&
3659
+ (threeDSAuthDeclineCodes === null ||
3660
+ threeDSAuthDeclineCodes.includes(data.decline_code ?? ''));
3502
3661
  return {
3503
3662
  threeDS: authFailed ? 'failed' : 'passed',
3504
3663
  result: {
3505
3664
  outcome: authFailed ? '3ds_failed' : 'declined',
3506
3665
  orderId,
3507
- threeDSChallenged: true,
3666
+ threeDSChallenged,
3508
3667
  ...declineFields(data),
3509
3668
  },
3510
3669
  };
@@ -3515,7 +3674,7 @@ function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS
3515
3674
  result: {
3516
3675
  outcome: 'error',
3517
3676
  orderId,
3518
- threeDSChallenged: true,
3677
+ threeDSChallenged,
3519
3678
  error: new APIError(data.checkout_status === 'cancelled'
3520
3679
  ? 'Payment was cancelled'
3521
3680
  : `Unhandled checkout status: ${data.checkout_status}`, null, { response }),
@@ -3523,30 +3682,30 @@ function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS
3523
3682
  };
3524
3683
  }
3525
3684
  }
3526
- function mapThreeDSRun(run, orderId) {
3685
+ function mapThreeDSRun(run, orderId, threeDSChallenged) {
3527
3686
  switch (run.kind) {
3528
3687
  case 'resumed':
3529
- return mapResumeResponse(run.response, orderId);
3688
+ return mapResumeResponse(run.response, orderId, threeDSChallenged);
3530
3689
  case 'failed':
3531
3690
  return {
3532
3691
  threeDS: 'failed',
3533
3692
  result: {
3534
3693
  outcome: '3ds_failed',
3535
3694
  orderId,
3536
- threeDSChallenged: true,
3695
+ threeDSChallenged,
3537
3696
  error: run.error,
3538
3697
  },
3539
3698
  };
3540
3699
  case 'abandoned':
3541
3700
  return {
3542
3701
  threeDS: 'abandoned',
3543
- result: { outcome: '3ds_abandoned', orderId, threeDSChallenged: true },
3702
+ result: { outcome: '3ds_abandoned', orderId, threeDSChallenged },
3544
3703
  };
3545
3704
  default: {
3546
3705
  const result = {
3547
3706
  outcome: 'error',
3548
3707
  orderId,
3549
- threeDSChallenged: true,
3708
+ threeDSChallenged,
3550
3709
  error: run.error,
3551
3710
  };
3552
3711
  if (run.failedRequest) {
@@ -3609,9 +3768,14 @@ async function runSilentPurchaseDetailed(options) {
3609
3768
  timeout: DEFAULTS.REQUEST_TIMEOUT,
3610
3769
  retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
3611
3770
  });
3771
+ const payload = buildOneClickRequest(options);
3772
+ const idempotencyKey = createIdempotencyKey();
3773
+ if (idempotencyKey) {
3774
+ payload.idempotency_key = idempotencyKey;
3775
+ }
3612
3776
  let response;
3613
3777
  try {
3614
- response = await apiClient.oneClickOnce(buildOneClickRequest(options));
3778
+ response = await postOneClick(apiClient, payload);
3615
3779
  }
3616
3780
  catch (error) {
3617
3781
  if (error instanceof APIError &&
@@ -3622,6 +3786,16 @@ async function runSilentPurchaseDetailed(options) {
3622
3786
  threeDSChallenged: false,
3623
3787
  };
3624
3788
  }
3789
+ if (idempotencyKey && isRetryableOneClickError(error)) {
3790
+ // The charge may have gone through: the caller must not start a new payment.
3791
+ return {
3792
+ outcome: 'processing',
3793
+ orderId: null,
3794
+ threeDSChallenged: false,
3795
+ error: error,
3796
+ failedRequest: 'one_click',
3797
+ };
3798
+ }
3625
3799
  return {
3626
3800
  outcome: 'error',
3627
3801
  orderId: null,
@@ -3635,15 +3809,15 @@ async function runSilentPurchaseDetailed(options) {
3635
3809
  return step.result;
3636
3810
  }
3637
3811
  const { orderId, actionToken } = step;
3812
+ let challenged = false;
3638
3813
  let ended = false;
3639
3814
  const end = (result) => {
3640
- if (ended) {
3815
+ if (!challenged || ended) {
3641
3816
  return;
3642
3817
  }
3643
3818
  ended = true;
3644
3819
  callHook('onThreeDSEnd', options.onThreeDSEnd, { result });
3645
3820
  };
3646
- callHook('onThreeDSStart', options.onThreeDSStart, { orderId });
3647
3821
  try {
3648
3822
  const run = await runOneClickThreeDS({
3649
3823
  apiClient,
@@ -3653,8 +3827,13 @@ async function runSilentPurchaseDetailed(options) {
3653
3827
  orderId,
3654
3828
  actionToken,
3655
3829
  timeoutMs: options.threeDSTimeoutMs ?? DEFAULT_THREE_DS_TIMEOUT_MS,
3830
+ revealDelayMs: THREE_DS_OVERLAY_REVEAL_DELAY_MS,
3831
+ onChallengeShown: () => {
3832
+ challenged = true;
3833
+ callHook('onThreeDSStart', options.onThreeDSStart, { orderId });
3834
+ },
3656
3835
  });
3657
- const mapped = mapThreeDSRun(run, orderId);
3836
+ const mapped = mapThreeDSRun(run, orderId, challenged);
3658
3837
  end(mapped.threeDS);
3659
3838
  return mapped.result;
3660
3839
  }
@@ -3663,7 +3842,7 @@ async function runSilentPurchaseDetailed(options) {
3663
3842
  return {
3664
3843
  outcome: 'error',
3665
3844
  orderId,
3666
- threeDSChallenged: true,
3845
+ threeDSChallenged: challenged,
3667
3846
  error: error instanceof Error
3668
3847
  ? error
3669
3848
  : new FunnefoxSDKError('One-click 3DS step failed', undefined, error),