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