@paypercut/checkout-js 1.4.0 → 1.4.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.
package/dist/index.cjs CHANGED
@@ -105,7 +105,7 @@ class Emitter {
105
105
  }
106
106
  }
107
107
 
108
- const SDK_VERSION = "1.4.0";
108
+ const SDK_VERSION = "1.4.2";
109
109
 
110
110
  /**
111
111
  * Build-time configuration
@@ -897,6 +897,7 @@ class ExpressCheckoutImpl {
897
897
  merchantMcc: data.merchant?.mcc ?? '',
898
898
  merchantCountry: data.merchant?.country ?? '',
899
899
  merchantUrl: data.merchant?.business_url ?? '',
900
+ threeDSecure: data.three_d_secure ?? null,
900
901
  };
901
902
  }
902
903
  catch (err) {
@@ -1569,6 +1570,7 @@ class ExpressCheckoutImpl {
1569
1570
  country: this.expressConfig?.merchantCountry ?? '',
1570
1571
  url: this.expressConfig?.merchantUrl ?? '',
1571
1572
  },
1573
+ threeDSecure: this.expressConfig?.threeDSecure ?? null,
1572
1574
  });
1573
1575
  };
1574
1576
  session.oncancel = () => {
@@ -1884,6 +1886,7 @@ class ExpressCheckoutImpl {
1884
1886
  country: this.expressConfig?.merchantCountry ?? '',
1885
1887
  url: this.expressConfig?.merchantUrl ?? '',
1886
1888
  },
1889
+ threeDSecure: this.expressConfig?.threeDSecure ?? null,
1887
1890
  });
1888
1891
  });
1889
1892
  // 3DS was triggered — sheet already closed, payment method creation handled in message handler
@@ -3022,7 +3025,10 @@ function fileUrlFor(filename) {
3022
3025
  function resolveBrowserArtifactUrl(coreUrl) {
3023
3026
  const url = new URL(coreUrl);
3024
3027
  if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
3025
- return new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url).href;
3028
+ const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
3029
+ artifactUrl.search = url.search;
3030
+ artifactUrl.hash = '';
3031
+ return artifactUrl.href;
3026
3032
  }
3027
3033
  if (/\.js$/.test(url.pathname)) {
3028
3034
  url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
@@ -3033,7 +3039,6 @@ function resolveBrowserArtifactUrl(coreUrl) {
3033
3039
  else {
3034
3040
  url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
3035
3041
  }
3036
- url.search = '';
3037
3042
  url.hash = '';
3038
3043
  return url.href;
3039
3044
  }
@@ -3085,21 +3090,77 @@ function safelyUnregister(entry) {
3085
3090
  }
3086
3091
  entry.delegate = null;
3087
3092
  }
3093
+ function safelyAttach(entry, provider) {
3094
+ if (!entry.registered || entry.delegate)
3095
+ return;
3096
+ try {
3097
+ entry.delegate = provider.register(entry.target);
3098
+ }
3099
+ catch {
3100
+ // A target can register before its hosted component is ready. Keep the
3101
+ // provider available for the other targets and retry this one on refresh.
3102
+ }
3103
+ }
3104
+ function isTargetVisible(entry) {
3105
+ try {
3106
+ return entry.target.isVisible?.() ?? true;
3107
+ }
3108
+ catch {
3109
+ // Developer Assistance is optional. A stale owner node must never make the
3110
+ // merchant page fail while its visibility is being reconciled.
3111
+ return false;
3112
+ }
3113
+ }
3114
+ function syncAttachment(entry, registry) {
3115
+ if (!entry.registered)
3116
+ return;
3117
+ if (!isTargetVisible(entry)) {
3118
+ safelyUnregister(entry);
3119
+ return;
3120
+ }
3121
+ if (registry.provider?.version === SDK_VERSION) {
3122
+ safelyAttach(entry, registry.provider);
3123
+ return;
3124
+ }
3125
+ requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
3126
+ }
3127
+ let visibilityObserver = null;
3128
+ function observeTargetVisibility(registry) {
3129
+ if (visibilityObserver ||
3130
+ typeof MutationObserver === 'undefined' ||
3131
+ typeof document === 'undefined' ||
3132
+ !document.documentElement) {
3133
+ return;
3134
+ }
3135
+ visibilityObserver = new MutationObserver(() => {
3136
+ for (const entry of registry.registrations)
3137
+ syncAttachment(entry, registry);
3138
+ });
3139
+ visibilityObserver.observe(document.documentElement, {
3140
+ attributes: true,
3141
+ attributeFilter: ['aria-hidden', 'class', 'hidden', 'style'],
3142
+ childList: true,
3143
+ subtree: true,
3144
+ });
3145
+ }
3146
+ function stopObservingTargetVisibilityIfIdle(registry) {
3147
+ if (registry.registrations.size > 0)
3148
+ return;
3149
+ visibilityObserver?.disconnect();
3150
+ visibilityObserver = null;
3151
+ }
3152
+ function hasAttachedDeveloperAssistant(registry) {
3153
+ if (registry.provider?.version !== SDK_VERSION)
3154
+ return false;
3155
+ return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
3156
+ }
3088
3157
  function registerDeveloperAssistantTarget(target) {
3089
3158
  const registry = getRegistry();
3090
3159
  announceDeveloperAssistantCore();
3091
3160
  const entry = { target, delegate: null, registered: true };
3092
3161
  registry.registrations.add(entry);
3093
- requestDeveloperAssistance(() => registry.provider?.version === SDK_VERSION);
3094
- if (registry.provider?.version === SDK_VERSION) {
3095
- try {
3096
- entry.delegate = registry.provider.register(target);
3097
- }
3098
- catch {
3099
- // Developer Assistance is optional. A registration failure must not
3100
- // interrupt the Element lifecycle or payment flow.
3101
- }
3102
- }
3162
+ observeTargetVisibility(registry);
3163
+ syncAttachment(entry, registry);
3103
3164
  return {
3104
3165
  unregister() {
3105
3166
  if (!entry.registered)
@@ -3107,10 +3168,13 @@ function registerDeveloperAssistantTarget(target) {
3107
3168
  entry.registered = false;
3108
3169
  registry.registrations.delete(entry);
3109
3170
  safelyUnregister(entry);
3171
+ stopObservingTargetVisibilityIfIdle(registry);
3110
3172
  },
3111
3173
  refresh() {
3112
- if (entry.registered)
3113
- entry.delegate?.refresh();
3174
+ if (!entry.registered)
3175
+ return;
3176
+ syncAttachment(entry, registry);
3177
+ entry.delegate?.refresh();
3114
3178
  },
3115
3179
  collapse() {
3116
3180
  if (entry.registered)
@@ -3119,6 +3183,26 @@ function registerDeveloperAssistantTarget(target) {
3119
3183
  };
3120
3184
  }
3121
3185
 
3186
+ function isElementVisible(element) {
3187
+ if (!element?.isConnected)
3188
+ return false;
3189
+ for (let current = element; current; current = current.parentElement) {
3190
+ if (current.hidden ||
3191
+ current.inert ||
3192
+ current.getAttribute('aria-hidden') === 'true') {
3193
+ return false;
3194
+ }
3195
+ const style = current.ownerDocument.defaultView?.getComputedStyle(current);
3196
+ if (style?.display === 'none' ||
3197
+ style?.visibility === 'hidden' ||
3198
+ style?.visibility === 'collapse' ||
3199
+ style?.contentVisibility === 'hidden') {
3200
+ return false;
3201
+ }
3202
+ }
3203
+ return true;
3204
+ }
3205
+
3122
3206
  const FRAME_URL_LENGTH_WARNING_THRESHOLD = 4096;
3123
3207
  let hasWarnedAboutLongFrameUrl = false;
3124
3208
  const ELEMENTS_FRAME_NAVIGATION_QUERY = '__paypercut_navigation';
@@ -3188,6 +3272,7 @@ function buildCardElementFrameUrl(input) {
3188
3272
  function setSharedParams(params, input, includeKeyMode = true) {
3189
3273
  params.set('controllerId', input.controllerId);
3190
3274
  params.set('apiKey', input.clientOptions.publishableKey);
3275
+ set(params, 'account', input.clientOptions.account);
3191
3276
  if (includeKeyMode)
3192
3277
  params.set('keyMode', inferKeyMode(input.clientOptions.publishableKey));
3193
3278
  params.set('locale', input.elementsOptions.locale || navigatorLocale());
@@ -4875,6 +4960,7 @@ class CardElementImpl {
4875
4960
  configurationIdentity: this.group.configurationIdentity,
4876
4961
  appearanceScopeId: this.group.controllerId,
4877
4962
  presets,
4963
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
4878
4964
  isAvailable: () => this.canApplyDeveloperPreset(),
4879
4965
  isAppearanceAvailable: () => this.isMounted(),
4880
4966
  appearancePreviewClearsTestData: () => true,
@@ -5069,6 +5155,100 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5069
5155
  root.appendChild(style);
5070
5156
  }
5071
5157
 
5158
+ const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
5159
+ closedPollIntervalMs: 250,
5160
+ providerSettlementGraceMs: 3500,
5161
+ };
5162
+ /**
5163
+ * Captures the popup synchronously opened by a provider launch and supplies a
5164
+ * bounded fallback when the provider leaves its result promise pending after
5165
+ * the popup has actually closed.
5166
+ */
5167
+ const launchWithProviderPopupRecovery = (launch, onAbandoned, host = window) => {
5168
+ const originalOpen = host.open;
5169
+ let capturedPopup = null;
5170
+ let captureInstalled = false;
5171
+ let stopped = false;
5172
+ let pollTimer = null;
5173
+ let settlementTimer = null;
5174
+ const captureOpen = ((url, target, features) => {
5175
+ const popup = originalOpen.call(host, url, target, features);
5176
+ if (!capturedPopup && popup)
5177
+ capturedPopup = popup;
5178
+ return popup;
5179
+ });
5180
+ try {
5181
+ host.open = captureOpen;
5182
+ captureInstalled = host.open === captureOpen;
5183
+ }
5184
+ catch {
5185
+ captureInstalled = false;
5186
+ }
5187
+ let result;
5188
+ try {
5189
+ result = launch();
5190
+ }
5191
+ finally {
5192
+ if (captureInstalled && host.open === captureOpen)
5193
+ host.open = originalOpen;
5194
+ }
5195
+ const stop = () => {
5196
+ if (stopped)
5197
+ return;
5198
+ stopped = true;
5199
+ if (pollTimer !== null)
5200
+ host.clearTimeout(pollTimer);
5201
+ if (settlementTimer !== null)
5202
+ host.clearTimeout(settlementTimer);
5203
+ pollTimer = null;
5204
+ settlementTimer = null;
5205
+ capturedPopup = null;
5206
+ };
5207
+ const merchantDocumentHasFocus = () => {
5208
+ try {
5209
+ return host.document?.hasFocus() ?? true;
5210
+ }
5211
+ catch {
5212
+ return false;
5213
+ }
5214
+ };
5215
+ const poll = () => {
5216
+ if (stopped || !capturedPopup)
5217
+ return;
5218
+ let closed = false;
5219
+ try {
5220
+ closed = capturedPopup.closed;
5221
+ }
5222
+ catch {
5223
+ stop();
5224
+ return;
5225
+ }
5226
+ // Chrome can close Google's short-lived launcher window after handing the
5227
+ // flow to its native payment-handler window. The launcher closing is only
5228
+ // a customer dismissal once focus has returned to the merchant document.
5229
+ if (!closed || !merchantDocumentHasFocus()) {
5230
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5231
+ return;
5232
+ }
5233
+ pollTimer = null;
5234
+ settlementTimer = host.setTimeout(() => {
5235
+ if (stopped)
5236
+ return;
5237
+ settlementTimer = null;
5238
+ if (!merchantDocumentHasFocus()) {
5239
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5240
+ return;
5241
+ }
5242
+ stop();
5243
+ onAbandoned();
5244
+ }, GOOGLE_PAY_POPUP_RECOVERY_POLICY.providerSettlementGraceMs);
5245
+ };
5246
+ if (capturedPopup) {
5247
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5248
+ }
5249
+ return { result, stop };
5250
+ };
5251
+
5072
5252
  const MAX_IFRAME_HEIGHT = 4096;
5073
5253
  const EXPRESS_PREVIEW_INITIALIZATION_TIMEOUT_MS = 10000;
5074
5254
  const WALLET_OVERLAY_FALLBACK_Z_INDEX = '2147483647';
@@ -5148,6 +5328,7 @@ class ExpressCheckoutElementImpl {
5148
5328
  this.googlePayEnvironment = null;
5149
5329
  this.googlePayRequestId = null;
5150
5330
  this.googlePayProcessingRequestId = null;
5331
+ this.googlePayPopupRecovery = null;
5151
5332
  this.googlePayUpdates = new Map();
5152
5333
  this.googlePayAuthorization = null;
5153
5334
  this.googlePayButtonTarget = null;
@@ -5267,6 +5448,14 @@ class ExpressCheckoutElementImpl {
5267
5448
  this.applePaySession !== null ||
5268
5449
  this.googlePayRequestId !== null);
5269
5450
  }
5451
+ hasActiveProviderSubmission() {
5452
+ const googlePayAwaitingMerchantApproval = this.googlePayRequestId !== null &&
5453
+ this.activeAttempt?.requestId === this.googlePayRequestId &&
5454
+ this.activeAttempt.approved === false;
5455
+ return (this.activeAttempt?.approved === true ||
5456
+ this.applePaySession !== null ||
5457
+ (this.googlePayRequestId !== null && !googlePayAwaitingMerchantApproval));
5458
+ }
5270
5459
  handleControllerError(error) {
5271
5460
  if (this.destroyed)
5272
5461
  return;
@@ -5672,6 +5861,7 @@ class ExpressCheckoutElementImpl {
5672
5861
  configurationIdentity: this.group.configurationIdentity,
5673
5862
  appearanceScopeId: this.group.controllerId,
5674
5863
  componentDisplayScopeId: this.componentId,
5864
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
5675
5865
  isAvailable: () => true,
5676
5866
  isAppearanceAvailable: () => this.isMounted(),
5677
5867
  canPreview: () => this.group.isAppearancePreviewAvailable(),
@@ -5813,7 +6003,9 @@ class ExpressCheckoutElementImpl {
5813
6003
  const settle = (accepted, options) => {
5814
6004
  if (settled || this.destroyed || this.activeAttempt?.requestId !== requestId)
5815
6005
  return;
5816
- const validatedOptions = accepted ? validateClickResolveOptions(options) : undefined;
6006
+ const validatedResolution = accepted ? validateClickResolveOptions(options) : undefined;
6007
+ const { amount, ...checkoutDetails } = validatedResolution ?? {};
6008
+ const validatedOptions = Object.keys(checkoutDetails).length > 0 ? checkoutDetails : undefined;
5817
6009
  settled = true;
5818
6010
  window.clearTimeout(timeout);
5819
6011
  if (accepted && this.activeAttempt?.requestId === requestId) {
@@ -5823,11 +6015,23 @@ class ExpressCheckoutElementImpl {
5823
6015
  ...(validatedOptions ?? {}),
5824
6016
  });
5825
6017
  }
5826
- this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
6018
+ if (amount === undefined) {
6019
+ this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
6020
+ }
6021
+ else {
6022
+ this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions, amount);
6023
+ }
5827
6024
  if (!accepted) {
5828
6025
  this.group.endWalletAttempt(this.componentId, requestId);
5829
- this.activeAttempt = null;
5830
- this.activeOptions = null;
6026
+ // A top-level Google Pay sheet is already open before the async
6027
+ // merchant click decision returns. Keep the request identity until the
6028
+ // controller's wallet_cancel arrives so integrations receive their
6029
+ // normal cancel lifecycle and can release their own attempt lock.
6030
+ if (wallet !== 'google_pay' ||
6031
+ this.googlePayRequestId !== requestId) {
6032
+ this.activeAttempt = null;
6033
+ this.activeOptions = null;
6034
+ }
5831
6035
  }
5832
6036
  };
5833
6037
  // Woo and other commerce adapters may need to validate their checkout and
@@ -6190,10 +6394,22 @@ class ExpressCheckoutElementImpl {
6190
6394
  this.googlePayClient = this.createGooglePayClient(environment, Object.keys(paymentDataCallbacks).length > 0 ? paymentDataCallbacks : undefined);
6191
6395
  // Keep the browser launch synchronous with the relayed click. Awaiting
6192
6396
  // script or merchant work here loses mobile popup/user-activation state.
6193
- const payment = this.googlePayClient.loadPaymentData(request);
6397
+ const popupRecovery = launchWithProviderPopupRecovery(() => this.googlePayClient.loadPaymentData(request), () => {
6398
+ if (this.googlePayRequestId !== requestId || this.destroyed)
6399
+ return;
6400
+ try {
6401
+ this.group.sendGooglePayCanceled(this.componentId, requestId);
6402
+ }
6403
+ finally {
6404
+ this.clearGooglePayAttempt(requestId);
6405
+ }
6406
+ });
6407
+ this.googlePayPopupRecovery = popupRecovery;
6408
+ const payment = popupRecovery.result;
6194
6409
  void Promise.resolve(payment).then((data) => {
6195
6410
  if (this.googlePayRequestId !== requestId || this.destroyed)
6196
6411
  return;
6412
+ this.clearGooglePayPopupRecovery();
6197
6413
  // Google has returned control to the merchant document at this
6198
6414
  // boundary. Keep blocking duplicate checkout interactions, but stop
6199
6415
  // telling the customer that the provider window is still open while
@@ -6204,13 +6420,17 @@ class ExpressCheckoutElementImpl {
6204
6420
  }, (error) => {
6205
6421
  if (this.googlePayRequestId !== requestId || this.destroyed)
6206
6422
  return;
6207
- if (isGooglePayCancellation(error)) {
6208
- this.group.sendGooglePayCanceled(this.componentId, requestId);
6423
+ try {
6424
+ if (isGooglePayCancellation(error)) {
6425
+ this.group.sendGooglePayCanceled(this.componentId, requestId);
6426
+ }
6427
+ else {
6428
+ this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
6429
+ }
6209
6430
  }
6210
- else {
6211
- this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
6431
+ finally {
6432
+ this.clearGooglePayAttempt(requestId);
6212
6433
  }
6213
- this.clearGooglePayAttempt(requestId);
6214
6434
  });
6215
6435
  }
6216
6436
  catch (error) {
@@ -6297,6 +6517,7 @@ class ExpressCheckoutElementImpl {
6297
6517
  clearGooglePayAttempt(requestId) {
6298
6518
  if (requestId && this.googlePayRequestId !== requestId)
6299
6519
  return;
6520
+ this.clearGooglePayPopupRecovery();
6300
6521
  this.googlePayRequestId = null;
6301
6522
  this.googlePayProcessingRequestId = null;
6302
6523
  for (const pending of this.googlePayUpdates.values()) {
@@ -6311,6 +6532,10 @@ class ExpressCheckoutElementImpl {
6311
6532
  }
6312
6533
  this.positionGooglePayButton();
6313
6534
  }
6535
+ clearGooglePayPopupRecovery() {
6536
+ this.googlePayPopupRecovery?.stop();
6537
+ this.googlePayPopupRecovery = null;
6538
+ }
6314
6539
  startApplePay(requestId, request) {
6315
6540
  this.abortApplePay();
6316
6541
  const ApplePayAPI = window.ApplePaySession;
@@ -6661,6 +6886,7 @@ function validateClickResolveOptions(options) {
6661
6886
  if (options === undefined)
6662
6887
  return undefined;
6663
6888
  const allowed = new Set([
6889
+ 'amount',
6664
6890
  'lineItems',
6665
6891
  'emailRequired',
6666
6892
  'phoneNumberRequired',
@@ -6672,6 +6898,12 @@ function validateClickResolveOptions(options) {
6672
6898
  if (!isRecord(options) || Object.keys(options).some((key) => !allowed.has(key))) {
6673
6899
  throw invalidOptions();
6674
6900
  }
6901
+ if (options.amount !== undefined &&
6902
+ (typeof options.amount !== 'number' ||
6903
+ !Number.isSafeInteger(options.amount) ||
6904
+ options.amount < 0)) {
6905
+ throw invalidOptions();
6906
+ }
6675
6907
  validateRows(options.lineItems, 'name');
6676
6908
  validateRows(options.shippingRates, 'displayName', true);
6677
6909
  for (const flag of [
@@ -6699,7 +6931,7 @@ function validateClickResolveOptions(options) {
6699
6931
  });
6700
6932
  }
6701
6933
  function validateElementUpdateOptions(options) {
6702
- if (!isRecord(options) || Object.keys(options).length === 0) {
6934
+ if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
6703
6935
  throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
6704
6936
  }
6705
6937
  return validateClickResolveOptions(options);
@@ -8262,6 +8494,9 @@ class CardFieldElementImpl {
8262
8494
  isMounted() {
8263
8495
  return this.mounted && !this.destroyed;
8264
8496
  }
8497
+ isVisible() {
8498
+ return isElementVisible(this.surface?.root ?? null);
8499
+ }
8265
8500
  destroy() {
8266
8501
  if (this.destroyed)
8267
8502
  return;
@@ -11302,9 +11537,6 @@ class ElementsGroupImpl {
11302
11537
  return element;
11303
11538
  }
11304
11539
  if (type === 'expressCheckout') {
11305
- if (this.elementsOptions.mode !== 'payment') {
11306
- throw createElementsError('elements_component_configuration_invalid', 'Express Checkout is currently supported only in payment mode.', false);
11307
- }
11308
11540
  const element = new ExpressCheckoutElementImpl(this, options);
11309
11541
  this.elements.set(element.componentId, element);
11310
11542
  return element;
@@ -11751,7 +11983,9 @@ class ElementsGroupImpl {
11751
11983
  };
11752
11984
  this.postControl(control);
11753
11985
  }
11754
- resolveWalletClick(componentId, requestId, accepted, options) {
11986
+ resolveWalletClick(componentId, requestId, accepted, options, amount) {
11987
+ if (accepted && amount !== undefined)
11988
+ this.commitAmountUpdate(amount);
11755
11989
  const snapshot = this.getUpdateSnapshot().options;
11756
11990
  const message = {
11757
11991
  channel: ELEMENTS_COMPONENT_CHANNEL,
@@ -11970,13 +12204,17 @@ class ElementsGroupImpl {
11970
12204
  if (this.destroyed) {
11971
12205
  throw new Error('[Paypercut Elements] Cannot update a destroyed group.');
11972
12206
  }
12207
+ const activeElementSubmission = Array.from(this.elements.values()).some((element) => element.hasActiveSubmission());
12208
+ const activeProviderSubmission = Array.from(this.elements.values()).some((element) => element.componentType === 'express_checkout'
12209
+ ? element.hasActiveProviderSubmission()
12210
+ : element.hasActiveSubmission());
11973
12211
  if (this.pendingValidation !== null ||
11974
12212
  this.paymentMethodSubmission.hasActiveSubmission() ||
11975
- Array.from(this.elements.values()).some((element) => element.hasActiveSubmission())) {
12213
+ (options.appearance !== undefined ? activeElementSubmission : activeProviderSubmission)) {
11976
12214
  if (options.appearance !== undefined) {
11977
12215
  throw new AppearancePreviewError('elements_appearance_preview_refused', 'Appearance Preview is unavailable while payment validation, Card authentication, or a wallet attempt is active.');
11978
12216
  }
11979
- throw new Error('[Paypercut Elements] Cannot update Elements while payment details are being submitted.');
12217
+ throw createElementsError('elements_submission_in_progress', '[Paypercut Elements] Cannot update Elements while payment details are being submitted.', true);
11980
12218
  }
11981
12219
  const update = normalizeUpdateOptions(options, this.appearance, this.amount);
11982
12220
  const appearanceWasRequested = options.appearance !== undefined;
@@ -12001,6 +12239,10 @@ class ElementsGroupImpl {
12001
12239
  if (update.amount === this.amount && !appearanceChanged) {
12002
12240
  return Promise.resolve();
12003
12241
  }
12242
+ if (!appearanceChanged) {
12243
+ this.commitAmountUpdate(update.amount);
12244
+ return Promise.resolve();
12245
+ }
12004
12246
  if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
12005
12247
  throw new Error('[Paypercut Elements] The update revision limit has been reached.');
12006
12248
  }
@@ -12032,6 +12274,26 @@ class ElementsGroupImpl {
12032
12274
  this.postControl(message);
12033
12275
  return Promise.resolve();
12034
12276
  }
12277
+ commitAmountUpdate(amount) {
12278
+ if (amount === this.amount)
12279
+ return;
12280
+ if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
12281
+ throw new Error('[Paypercut Elements] The update revision limit has been reached.');
12282
+ }
12283
+ this.amount = amount;
12284
+ this.invalidateSubmissionValidation();
12285
+ this.updateRevision += 1;
12286
+ if (!this.controllerInitialized)
12287
+ return;
12288
+ const snapshot = this.getUpdateSnapshot();
12289
+ this.postControl({
12290
+ channel: ELEMENTS_COMPONENT_CHANNEL,
12291
+ type: ElementsControllerCommandType.UpdateOptions,
12292
+ controllerId: this.controllerId,
12293
+ updateRevision: snapshot.updateRevision,
12294
+ options: snapshot.options,
12295
+ });
12296
+ }
12035
12297
  startAppearancePreview(appearance, deferCommit = false) {
12036
12298
  const generation = ++this.appearancePreviewGeneration;
12037
12299
  const previous = cloneElementsAppearance(this.appearance);
@@ -12193,6 +12455,9 @@ class ElementsGroupImpl {
12193
12455
  hasMountedCardFields() {
12194
12456
  return Array.from(this.cardFields.values()).some((field) => field.isMounted());
12195
12457
  }
12458
+ hasVisibleCardFields() {
12459
+ return Array.from(this.cardFields.values()).some((field) => field.isVisible());
12460
+ }
12196
12461
  warnAppearancePreview(error) {
12197
12462
  if (error.code === 'elements_appearance_preview_superseded')
12198
12463
  return;
@@ -12289,6 +12554,7 @@ class ElementsGroupImpl {
12289
12554
  configurationIdentity: this.configurationIdentity,
12290
12555
  appearanceScopeId: this.controllerId,
12291
12556
  presetSource: 'split-card',
12557
+ isVisible: () => !this.destroyed && this.hasVisibleCardFields(),
12292
12558
  isAvailable: () => !this.destroyed && this.cardCollectionRuntime.canApplyDeveloperPreset(),
12293
12559
  isAppearanceAvailable: () => !this.destroyed && this.hasMountedCardFields(),
12294
12560
  appearancePreviewClearsTestData: () => true,
@@ -12531,7 +12797,7 @@ const MAX_CONFIRM_ATTEMPTS = 3;
12531
12797
  const CLIENT_SECRET_MARKER = '_secret_';
12532
12798
  const CLIENT_SECRET_PREFIX_LENGTH = 3;
12533
12799
  const MAX_CLIENT_SECRET_LENGTH = 4096;
12534
- // Shared with Paycore's payment-resource client-secret issuer. Checkout IDs are
12800
+ // Shared with Paypercut's payment-resource client-secret issuer. Checkout IDs are
12535
12801
  // embedded only so the SDK can address the authoritative resource; merchants
12536
12802
  // must continue to treat the complete client secret as opaque.
12537
12803
  const MAX_RESOURCE_ID_LENGTH = 200;
@@ -12749,6 +13015,7 @@ class PaymentConfirmationCoordinator {
12749
13015
  this.billingDetailsFor = billingDetailsFor;
12750
13016
  this.inFlight = new Map();
12751
13017
  this.activeAction = null;
13018
+ this.account = options.account;
12752
13019
  this.apiUrl = getApiOrigin(options.apiUrl);
12753
13020
  this.hostedOrigin = new URL(getCheckoutOrigin(options.hostedCheckoutUrl)).origin;
12754
13021
  this.actionShell = new ElementsActionShell(this.hostedOrigin, (actionId) => this.rejectActiveAction(actionId, 'elements_action_canceled', 'Payment authentication was canceled.', true), (actionId, code, message, recoverable) => this.rejectActiveAction(actionId, code, message, recoverable));
@@ -12826,6 +13093,7 @@ class PaymentConfirmationCoordinator {
12826
13093
  method: 'GET',
12827
13094
  headers: {
12828
13095
  Accept: 'application/json',
13096
+ ...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
12829
13097
  },
12830
13098
  }, 'elements_checkout_status_failed', { deadlineAt });
12831
13099
  return parseCheckoutStatus(value, parsed.checkoutSessionId);
@@ -12839,6 +13107,7 @@ class PaymentConfirmationCoordinator {
12839
13107
  Accept: 'application/json',
12840
13108
  'Content-Type': 'application/json',
12841
13109
  'Idempotency-Key': idempotencyKey,
13110
+ ...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
12842
13111
  },
12843
13112
  body: JSON.stringify({
12844
13113
  key: this.publishableKey,
@@ -12919,6 +13188,7 @@ class PaymentConfirmationCoordinator {
12919
13188
  payload: {
12920
13189
  protocolVersion: ELEMENTS_PAYMENT_CONFIRMATION_PROTOCOL_VERSION,
12921
13190
  publishableKey: this.publishableKey,
13191
+ ...(this.account !== undefined ? { account: this.account } : {}),
12922
13192
  apiUrl: this.apiUrl,
12923
13193
  sdkVersion: config.version,
12924
13194
  deadlineAt,
@@ -12994,6 +13264,7 @@ class PaypercutImpl {
12994
13264
  this.paymentConfirmation = null;
12995
13265
  this.configurationIdentity = JSON.stringify([
12996
13266
  options.publishableKey,
13267
+ options.account ?? null,
12997
13268
  getApiOrigin(options.apiUrl),
12998
13269
  getCheckoutOrigin(options.hostedCheckoutUrl),
12999
13270
  ]);
@@ -13067,6 +13338,7 @@ class PaypercutImpl {
13067
13338
  return Promise.reject(createSubmitError('elements_client_secret_invalid', 'confirmPayment requires only a Checkout Session clientSecret.', false));
13068
13339
  }
13069
13340
  this.paymentConfirmation ?? (this.paymentConfirmation = new PaymentConfirmationCoordinator(this.options.publishableKey, {
13341
+ ...(this.options.account !== undefined ? { account: this.options.account } : {}),
13070
13342
  ...(this.options.apiUrl ? { apiUrl: this.options.apiUrl } : {}),
13071
13343
  ...(this.options.hostedCheckoutUrl
13072
13344
  ? { hostedCheckoutUrl: this.options.hostedCheckoutUrl }
@@ -13078,12 +13350,22 @@ class PaypercutImpl {
13078
13350
  function isSetupFutureUsage(value) {
13079
13351
  return value === undefined || value === 'on_session' || value === 'off_session';
13080
13352
  }
13081
- const Paypercut = function (options) {
13082
- return new PaypercutImpl(validateClientOptions(options));
13353
+ const Paypercut = function (optionsOrKey, options) {
13354
+ if (typeof optionsOrKey === 'string') {
13355
+ if (options !== undefined &&
13356
+ (!options || typeof options !== 'object' || Array.isArray(options))) {
13357
+ throw new Error('[Paypercut Elements] Client options must be an object.');
13358
+ }
13359
+ return new PaypercutImpl(validateClientOptions({ ...options, publishableKey: optionsOrKey }));
13360
+ }
13361
+ if (options !== undefined) {
13362
+ throw new Error('[Paypercut Elements] Pass client options in one initializer object.');
13363
+ }
13364
+ return new PaypercutImpl(validateClientOptions(optionsOrKey));
13083
13365
  };
13084
13366
  Paypercut.version = config.version;
13085
13367
  function validateClientOptions(options) {
13086
- if (!options || typeof options !== 'object') {
13368
+ if (!options || typeof options !== 'object' || Array.isArray(options)) {
13087
13369
  throw new Error('[Paypercut Elements] Client options are required.');
13088
13370
  }
13089
13371
  const publishableKey = options.publishableKey;