@paypercut/checkout-js 1.4.0 → 1.4.1

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.d.cts CHANGED
@@ -796,8 +796,8 @@ interface ExpressCheckoutClickEvent {
796
796
  resolve(options?: ExpressCheckoutClickResolveOptions): void;
797
797
  reject(): void;
798
798
  }
799
- /** Current checkout details supplied immediately before a wallet is opened. */
800
- interface ExpressCheckoutClickResolveOptions {
799
+ /** Mutable checkout details for an already mounted Express Checkout Element. */
800
+ interface ExpressCheckoutElementUpdateOptions {
801
801
  lineItems?: ExpressCheckoutLineItem[];
802
802
  emailRequired?: boolean;
803
803
  phoneNumberRequired?: boolean;
@@ -807,13 +807,13 @@ interface ExpressCheckoutClickResolveOptions {
807
807
  shippingRates?: ExpressCheckoutShippingRate[];
808
808
  }
809
809
  /**
810
- * Mutable checkout data for an already mounted Express Checkout Element.
811
- *
812
- * Provider selection, layout, and button styling remain immutable for the
813
- * lifetime of the Element. Commerce state can be replaced before the next
814
- * wallet gesture without remounting the secure component.
810
+ * Current checkout details supplied immediately before a wallet is opened.
811
+ * The amount and wallet details are applied to the same attempt atomically.
815
812
  */
816
- type ExpressCheckoutElementUpdateOptions = ExpressCheckoutClickResolveOptions;
813
+ interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
814
+ /** Authoritative order total in the group's currency, in minor units. */
815
+ amount?: number;
816
+ }
817
817
  /** Updated checkout details returned after a wallet address or rate changes. */
818
818
  interface ExpressCheckoutShippingUpdate {
819
819
  /** Recalculated order total in the group's currency, in minor units. */
package/dist/index.d.mts CHANGED
@@ -796,8 +796,8 @@ interface ExpressCheckoutClickEvent {
796
796
  resolve(options?: ExpressCheckoutClickResolveOptions): void;
797
797
  reject(): void;
798
798
  }
799
- /** Current checkout details supplied immediately before a wallet is opened. */
800
- interface ExpressCheckoutClickResolveOptions {
799
+ /** Mutable checkout details for an already mounted Express Checkout Element. */
800
+ interface ExpressCheckoutElementUpdateOptions {
801
801
  lineItems?: ExpressCheckoutLineItem[];
802
802
  emailRequired?: boolean;
803
803
  phoneNumberRequired?: boolean;
@@ -807,13 +807,13 @@ interface ExpressCheckoutClickResolveOptions {
807
807
  shippingRates?: ExpressCheckoutShippingRate[];
808
808
  }
809
809
  /**
810
- * Mutable checkout data for an already mounted Express Checkout Element.
811
- *
812
- * Provider selection, layout, and button styling remain immutable for the
813
- * lifetime of the Element. Commerce state can be replaced before the next
814
- * wallet gesture without remounting the secure component.
810
+ * Current checkout details supplied immediately before a wallet is opened.
811
+ * The amount and wallet details are applied to the same attempt atomically.
815
812
  */
816
- type ExpressCheckoutElementUpdateOptions = ExpressCheckoutClickResolveOptions;
813
+ interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
814
+ /** Authoritative order total in the group's currency, in minor units. */
815
+ amount?: number;
816
+ }
817
817
  /** Updated checkout details returned after a wallet address or rate changes. */
818
818
  interface ExpressCheckoutShippingUpdate {
819
819
  /** Recalculated order total in the group's currency, in minor units. */
package/dist/index.d.ts CHANGED
@@ -796,8 +796,8 @@ interface ExpressCheckoutClickEvent {
796
796
  resolve(options?: ExpressCheckoutClickResolveOptions): void;
797
797
  reject(): void;
798
798
  }
799
- /** Current checkout details supplied immediately before a wallet is opened. */
800
- interface ExpressCheckoutClickResolveOptions {
799
+ /** Mutable checkout details for an already mounted Express Checkout Element. */
800
+ interface ExpressCheckoutElementUpdateOptions {
801
801
  lineItems?: ExpressCheckoutLineItem[];
802
802
  emailRequired?: boolean;
803
803
  phoneNumberRequired?: boolean;
@@ -807,13 +807,13 @@ interface ExpressCheckoutClickResolveOptions {
807
807
  shippingRates?: ExpressCheckoutShippingRate[];
808
808
  }
809
809
  /**
810
- * Mutable checkout data for an already mounted Express Checkout Element.
811
- *
812
- * Provider selection, layout, and button styling remain immutable for the
813
- * lifetime of the Element. Commerce state can be replaced before the next
814
- * wallet gesture without remounting the secure component.
810
+ * Current checkout details supplied immediately before a wallet is opened.
811
+ * The amount and wallet details are applied to the same attempt atomically.
815
812
  */
816
- type ExpressCheckoutElementUpdateOptions = ExpressCheckoutClickResolveOptions;
813
+ interface ExpressCheckoutClickResolveOptions extends ExpressCheckoutElementUpdateOptions {
814
+ /** Authoritative order total in the group's currency, in minor units. */
815
+ amount?: number;
816
+ }
817
817
  /** Updated checkout details returned after a wallet address or rate changes. */
818
818
  interface ExpressCheckoutShippingUpdate {
819
819
  /** Recalculated order total in the group's currency, in minor units. */
package/dist/index.mjs CHANGED
@@ -100,7 +100,7 @@ class Emitter {
100
100
  }
101
101
  }
102
102
 
103
- const SDK_VERSION = "1.4.0";
103
+ const SDK_VERSION = "1.4.1";
104
104
 
105
105
  /**
106
106
  * Build-time configuration
@@ -3017,7 +3017,10 @@ function fileUrlFor(filename) {
3017
3017
  function resolveBrowserArtifactUrl(coreUrl) {
3018
3018
  const url = new URL(coreUrl);
3019
3019
  if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
3020
- return new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url).href;
3020
+ const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
3021
+ artifactUrl.search = url.search;
3022
+ artifactUrl.hash = '';
3023
+ return artifactUrl.href;
3021
3024
  }
3022
3025
  if (/\.js$/.test(url.pathname)) {
3023
3026
  url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
@@ -3028,7 +3031,6 @@ function resolveBrowserArtifactUrl(coreUrl) {
3028
3031
  else {
3029
3032
  url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
3030
3033
  }
3031
- url.search = '';
3032
3034
  url.hash = '';
3033
3035
  return url.href;
3034
3036
  }
@@ -3080,21 +3082,77 @@ function safelyUnregister(entry) {
3080
3082
  }
3081
3083
  entry.delegate = null;
3082
3084
  }
3085
+ function safelyAttach(entry, provider) {
3086
+ if (!entry.registered || entry.delegate)
3087
+ return;
3088
+ try {
3089
+ entry.delegate = provider.register(entry.target);
3090
+ }
3091
+ catch {
3092
+ // A target can register before its hosted component is ready. Keep the
3093
+ // provider available for the other targets and retry this one on refresh.
3094
+ }
3095
+ }
3096
+ function isTargetVisible(entry) {
3097
+ try {
3098
+ return entry.target.isVisible?.() ?? true;
3099
+ }
3100
+ catch {
3101
+ // Developer Assistance is optional. A stale owner node must never make the
3102
+ // merchant page fail while its visibility is being reconciled.
3103
+ return false;
3104
+ }
3105
+ }
3106
+ function syncAttachment(entry, registry) {
3107
+ if (!entry.registered)
3108
+ return;
3109
+ if (!isTargetVisible(entry)) {
3110
+ safelyUnregister(entry);
3111
+ return;
3112
+ }
3113
+ if (registry.provider?.version === SDK_VERSION) {
3114
+ safelyAttach(entry, registry.provider);
3115
+ return;
3116
+ }
3117
+ requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
3118
+ }
3119
+ let visibilityObserver = null;
3120
+ function observeTargetVisibility(registry) {
3121
+ if (visibilityObserver ||
3122
+ typeof MutationObserver === 'undefined' ||
3123
+ typeof document === 'undefined' ||
3124
+ !document.documentElement) {
3125
+ return;
3126
+ }
3127
+ visibilityObserver = new MutationObserver(() => {
3128
+ for (const entry of registry.registrations)
3129
+ syncAttachment(entry, registry);
3130
+ });
3131
+ visibilityObserver.observe(document.documentElement, {
3132
+ attributes: true,
3133
+ attributeFilter: ['aria-hidden', 'class', 'hidden', 'style'],
3134
+ childList: true,
3135
+ subtree: true,
3136
+ });
3137
+ }
3138
+ function stopObservingTargetVisibilityIfIdle(registry) {
3139
+ if (registry.registrations.size > 0)
3140
+ return;
3141
+ visibilityObserver?.disconnect();
3142
+ visibilityObserver = null;
3143
+ }
3144
+ function hasAttachedDeveloperAssistant(registry) {
3145
+ if (registry.provider?.version !== SDK_VERSION)
3146
+ return false;
3147
+ return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
3148
+ }
3083
3149
  function registerDeveloperAssistantTarget(target) {
3084
3150
  const registry = getRegistry();
3085
3151
  announceDeveloperAssistantCore();
3086
3152
  const entry = { target, delegate: null, registered: true };
3087
3153
  registry.registrations.add(entry);
3088
- requestDeveloperAssistance(() => registry.provider?.version === SDK_VERSION);
3089
- if (registry.provider?.version === SDK_VERSION) {
3090
- try {
3091
- entry.delegate = registry.provider.register(target);
3092
- }
3093
- catch {
3094
- // Developer Assistance is optional. A registration failure must not
3095
- // interrupt the Element lifecycle or payment flow.
3096
- }
3097
- }
3154
+ observeTargetVisibility(registry);
3155
+ syncAttachment(entry, registry);
3098
3156
  return {
3099
3157
  unregister() {
3100
3158
  if (!entry.registered)
@@ -3102,10 +3160,13 @@ function registerDeveloperAssistantTarget(target) {
3102
3160
  entry.registered = false;
3103
3161
  registry.registrations.delete(entry);
3104
3162
  safelyUnregister(entry);
3163
+ stopObservingTargetVisibilityIfIdle(registry);
3105
3164
  },
3106
3165
  refresh() {
3107
- if (entry.registered)
3108
- entry.delegate?.refresh();
3166
+ if (!entry.registered)
3167
+ return;
3168
+ syncAttachment(entry, registry);
3169
+ entry.delegate?.refresh();
3109
3170
  },
3110
3171
  collapse() {
3111
3172
  if (entry.registered)
@@ -3114,6 +3175,26 @@ function registerDeveloperAssistantTarget(target) {
3114
3175
  };
3115
3176
  }
3116
3177
 
3178
+ function isElementVisible(element) {
3179
+ if (!element?.isConnected)
3180
+ return false;
3181
+ for (let current = element; current; current = current.parentElement) {
3182
+ if (current.hidden ||
3183
+ current.inert ||
3184
+ current.getAttribute('aria-hidden') === 'true') {
3185
+ return false;
3186
+ }
3187
+ const style = current.ownerDocument.defaultView?.getComputedStyle(current);
3188
+ if (style?.display === 'none' ||
3189
+ style?.visibility === 'hidden' ||
3190
+ style?.visibility === 'collapse' ||
3191
+ style?.contentVisibility === 'hidden') {
3192
+ return false;
3193
+ }
3194
+ }
3195
+ return true;
3196
+ }
3197
+
3117
3198
  const FRAME_URL_LENGTH_WARNING_THRESHOLD = 4096;
3118
3199
  let hasWarnedAboutLongFrameUrl = false;
3119
3200
  const ELEMENTS_FRAME_NAVIGATION_QUERY = '__paypercut_navigation';
@@ -4870,6 +4951,7 @@ class CardElementImpl {
4870
4951
  configurationIdentity: this.group.configurationIdentity,
4871
4952
  appearanceScopeId: this.group.controllerId,
4872
4953
  presets,
4954
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
4873
4955
  isAvailable: () => this.canApplyDeveloperPreset(),
4874
4956
  isAppearanceAvailable: () => this.isMounted(),
4875
4957
  appearancePreviewClearsTestData: () => true,
@@ -5064,6 +5146,100 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5064
5146
  root.appendChild(style);
5065
5147
  }
5066
5148
 
5149
+ const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
5150
+ closedPollIntervalMs: 250,
5151
+ providerSettlementGraceMs: 3500,
5152
+ };
5153
+ /**
5154
+ * Captures the popup synchronously opened by a provider launch and supplies a
5155
+ * bounded fallback when the provider leaves its result promise pending after
5156
+ * the popup has actually closed.
5157
+ */
5158
+ const launchWithProviderPopupRecovery = (launch, onAbandoned, host = window) => {
5159
+ const originalOpen = host.open;
5160
+ let capturedPopup = null;
5161
+ let captureInstalled = false;
5162
+ let stopped = false;
5163
+ let pollTimer = null;
5164
+ let settlementTimer = null;
5165
+ const captureOpen = ((url, target, features) => {
5166
+ const popup = originalOpen.call(host, url, target, features);
5167
+ if (!capturedPopup && popup)
5168
+ capturedPopup = popup;
5169
+ return popup;
5170
+ });
5171
+ try {
5172
+ host.open = captureOpen;
5173
+ captureInstalled = host.open === captureOpen;
5174
+ }
5175
+ catch {
5176
+ captureInstalled = false;
5177
+ }
5178
+ let result;
5179
+ try {
5180
+ result = launch();
5181
+ }
5182
+ finally {
5183
+ if (captureInstalled && host.open === captureOpen)
5184
+ host.open = originalOpen;
5185
+ }
5186
+ const stop = () => {
5187
+ if (stopped)
5188
+ return;
5189
+ stopped = true;
5190
+ if (pollTimer !== null)
5191
+ host.clearTimeout(pollTimer);
5192
+ if (settlementTimer !== null)
5193
+ host.clearTimeout(settlementTimer);
5194
+ pollTimer = null;
5195
+ settlementTimer = null;
5196
+ capturedPopup = null;
5197
+ };
5198
+ const merchantDocumentHasFocus = () => {
5199
+ try {
5200
+ return host.document?.hasFocus() ?? true;
5201
+ }
5202
+ catch {
5203
+ return false;
5204
+ }
5205
+ };
5206
+ const poll = () => {
5207
+ if (stopped || !capturedPopup)
5208
+ return;
5209
+ let closed = false;
5210
+ try {
5211
+ closed = capturedPopup.closed;
5212
+ }
5213
+ catch {
5214
+ stop();
5215
+ return;
5216
+ }
5217
+ // Chrome can close Google's short-lived launcher window after handing the
5218
+ // flow to its native payment-handler window. The launcher closing is only
5219
+ // a customer dismissal once focus has returned to the merchant document.
5220
+ if (!closed || !merchantDocumentHasFocus()) {
5221
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5222
+ return;
5223
+ }
5224
+ pollTimer = null;
5225
+ settlementTimer = host.setTimeout(() => {
5226
+ if (stopped)
5227
+ return;
5228
+ settlementTimer = null;
5229
+ if (!merchantDocumentHasFocus()) {
5230
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5231
+ return;
5232
+ }
5233
+ stop();
5234
+ onAbandoned();
5235
+ }, GOOGLE_PAY_POPUP_RECOVERY_POLICY.providerSettlementGraceMs);
5236
+ };
5237
+ if (capturedPopup) {
5238
+ pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
5239
+ }
5240
+ return { result, stop };
5241
+ };
5242
+
5067
5243
  const MAX_IFRAME_HEIGHT = 4096;
5068
5244
  const EXPRESS_PREVIEW_INITIALIZATION_TIMEOUT_MS = 10000;
5069
5245
  const WALLET_OVERLAY_FALLBACK_Z_INDEX = '2147483647';
@@ -5143,6 +5319,7 @@ class ExpressCheckoutElementImpl {
5143
5319
  this.googlePayEnvironment = null;
5144
5320
  this.googlePayRequestId = null;
5145
5321
  this.googlePayProcessingRequestId = null;
5322
+ this.googlePayPopupRecovery = null;
5146
5323
  this.googlePayUpdates = new Map();
5147
5324
  this.googlePayAuthorization = null;
5148
5325
  this.googlePayButtonTarget = null;
@@ -5262,6 +5439,14 @@ class ExpressCheckoutElementImpl {
5262
5439
  this.applePaySession !== null ||
5263
5440
  this.googlePayRequestId !== null);
5264
5441
  }
5442
+ hasActiveProviderSubmission() {
5443
+ const googlePayAwaitingMerchantApproval = this.googlePayRequestId !== null &&
5444
+ this.activeAttempt?.requestId === this.googlePayRequestId &&
5445
+ this.activeAttempt.approved === false;
5446
+ return (this.activeAttempt?.approved === true ||
5447
+ this.applePaySession !== null ||
5448
+ (this.googlePayRequestId !== null && !googlePayAwaitingMerchantApproval));
5449
+ }
5265
5450
  handleControllerError(error) {
5266
5451
  if (this.destroyed)
5267
5452
  return;
@@ -5667,6 +5852,7 @@ class ExpressCheckoutElementImpl {
5667
5852
  configurationIdentity: this.group.configurationIdentity,
5668
5853
  appearanceScopeId: this.group.controllerId,
5669
5854
  componentDisplayScopeId: this.componentId,
5855
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
5670
5856
  isAvailable: () => true,
5671
5857
  isAppearanceAvailable: () => this.isMounted(),
5672
5858
  canPreview: () => this.group.isAppearancePreviewAvailable(),
@@ -5808,7 +5994,9 @@ class ExpressCheckoutElementImpl {
5808
5994
  const settle = (accepted, options) => {
5809
5995
  if (settled || this.destroyed || this.activeAttempt?.requestId !== requestId)
5810
5996
  return;
5811
- const validatedOptions = accepted ? validateClickResolveOptions(options) : undefined;
5997
+ const validatedResolution = accepted ? validateClickResolveOptions(options) : undefined;
5998
+ const { amount, ...checkoutDetails } = validatedResolution ?? {};
5999
+ const validatedOptions = Object.keys(checkoutDetails).length > 0 ? checkoutDetails : undefined;
5812
6000
  settled = true;
5813
6001
  window.clearTimeout(timeout);
5814
6002
  if (accepted && this.activeAttempt?.requestId === requestId) {
@@ -5818,11 +6006,23 @@ class ExpressCheckoutElementImpl {
5818
6006
  ...(validatedOptions ?? {}),
5819
6007
  });
5820
6008
  }
5821
- this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
6009
+ if (amount === undefined) {
6010
+ this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
6011
+ }
6012
+ else {
6013
+ this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions, amount);
6014
+ }
5822
6015
  if (!accepted) {
5823
6016
  this.group.endWalletAttempt(this.componentId, requestId);
5824
- this.activeAttempt = null;
5825
- this.activeOptions = null;
6017
+ // A top-level Google Pay sheet is already open before the async
6018
+ // merchant click decision returns. Keep the request identity until the
6019
+ // controller's wallet_cancel arrives so integrations receive their
6020
+ // normal cancel lifecycle and can release their own attempt lock.
6021
+ if (wallet !== 'google_pay' ||
6022
+ this.googlePayRequestId !== requestId) {
6023
+ this.activeAttempt = null;
6024
+ this.activeOptions = null;
6025
+ }
5826
6026
  }
5827
6027
  };
5828
6028
  // Woo and other commerce adapters may need to validate their checkout and
@@ -6185,10 +6385,22 @@ class ExpressCheckoutElementImpl {
6185
6385
  this.googlePayClient = this.createGooglePayClient(environment, Object.keys(paymentDataCallbacks).length > 0 ? paymentDataCallbacks : undefined);
6186
6386
  // Keep the browser launch synchronous with the relayed click. Awaiting
6187
6387
  // script or merchant work here loses mobile popup/user-activation state.
6188
- const payment = this.googlePayClient.loadPaymentData(request);
6388
+ const popupRecovery = launchWithProviderPopupRecovery(() => this.googlePayClient.loadPaymentData(request), () => {
6389
+ if (this.googlePayRequestId !== requestId || this.destroyed)
6390
+ return;
6391
+ try {
6392
+ this.group.sendGooglePayCanceled(this.componentId, requestId);
6393
+ }
6394
+ finally {
6395
+ this.clearGooglePayAttempt(requestId);
6396
+ }
6397
+ });
6398
+ this.googlePayPopupRecovery = popupRecovery;
6399
+ const payment = popupRecovery.result;
6189
6400
  void Promise.resolve(payment).then((data) => {
6190
6401
  if (this.googlePayRequestId !== requestId || this.destroyed)
6191
6402
  return;
6403
+ this.clearGooglePayPopupRecovery();
6192
6404
  // Google has returned control to the merchant document at this
6193
6405
  // boundary. Keep blocking duplicate checkout interactions, but stop
6194
6406
  // telling the customer that the provider window is still open while
@@ -6199,13 +6411,17 @@ class ExpressCheckoutElementImpl {
6199
6411
  }, (error) => {
6200
6412
  if (this.googlePayRequestId !== requestId || this.destroyed)
6201
6413
  return;
6202
- if (isGooglePayCancellation(error)) {
6203
- this.group.sendGooglePayCanceled(this.componentId, requestId);
6414
+ try {
6415
+ if (isGooglePayCancellation(error)) {
6416
+ this.group.sendGooglePayCanceled(this.componentId, requestId);
6417
+ }
6418
+ else {
6419
+ this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
6420
+ }
6204
6421
  }
6205
- else {
6206
- this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
6422
+ finally {
6423
+ this.clearGooglePayAttempt(requestId);
6207
6424
  }
6208
- this.clearGooglePayAttempt(requestId);
6209
6425
  });
6210
6426
  }
6211
6427
  catch (error) {
@@ -6292,6 +6508,7 @@ class ExpressCheckoutElementImpl {
6292
6508
  clearGooglePayAttempt(requestId) {
6293
6509
  if (requestId && this.googlePayRequestId !== requestId)
6294
6510
  return;
6511
+ this.clearGooglePayPopupRecovery();
6295
6512
  this.googlePayRequestId = null;
6296
6513
  this.googlePayProcessingRequestId = null;
6297
6514
  for (const pending of this.googlePayUpdates.values()) {
@@ -6306,6 +6523,10 @@ class ExpressCheckoutElementImpl {
6306
6523
  }
6307
6524
  this.positionGooglePayButton();
6308
6525
  }
6526
+ clearGooglePayPopupRecovery() {
6527
+ this.googlePayPopupRecovery?.stop();
6528
+ this.googlePayPopupRecovery = null;
6529
+ }
6309
6530
  startApplePay(requestId, request) {
6310
6531
  this.abortApplePay();
6311
6532
  const ApplePayAPI = window.ApplePaySession;
@@ -6656,6 +6877,7 @@ function validateClickResolveOptions(options) {
6656
6877
  if (options === undefined)
6657
6878
  return undefined;
6658
6879
  const allowed = new Set([
6880
+ 'amount',
6659
6881
  'lineItems',
6660
6882
  'emailRequired',
6661
6883
  'phoneNumberRequired',
@@ -6667,6 +6889,12 @@ function validateClickResolveOptions(options) {
6667
6889
  if (!isRecord(options) || Object.keys(options).some((key) => !allowed.has(key))) {
6668
6890
  throw invalidOptions();
6669
6891
  }
6892
+ if (options.amount !== undefined &&
6893
+ (typeof options.amount !== 'number' ||
6894
+ !Number.isSafeInteger(options.amount) ||
6895
+ options.amount < 0)) {
6896
+ throw invalidOptions();
6897
+ }
6670
6898
  validateRows(options.lineItems, 'name');
6671
6899
  validateRows(options.shippingRates, 'displayName', true);
6672
6900
  for (const flag of [
@@ -6694,7 +6922,7 @@ function validateClickResolveOptions(options) {
6694
6922
  });
6695
6923
  }
6696
6924
  function validateElementUpdateOptions(options) {
6697
- if (!isRecord(options) || Object.keys(options).length === 0) {
6925
+ if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
6698
6926
  throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
6699
6927
  }
6700
6928
  return validateClickResolveOptions(options);
@@ -8257,6 +8485,9 @@ class CardFieldElementImpl {
8257
8485
  isMounted() {
8258
8486
  return this.mounted && !this.destroyed;
8259
8487
  }
8488
+ isVisible() {
8489
+ return isElementVisible(this.surface?.root ?? null);
8490
+ }
8260
8491
  destroy() {
8261
8492
  if (this.destroyed)
8262
8493
  return;
@@ -11297,9 +11528,6 @@ class ElementsGroupImpl {
11297
11528
  return element;
11298
11529
  }
11299
11530
  if (type === 'expressCheckout') {
11300
- if (this.elementsOptions.mode !== 'payment') {
11301
- throw createElementsError('elements_component_configuration_invalid', 'Express Checkout is currently supported only in payment mode.', false);
11302
- }
11303
11531
  const element = new ExpressCheckoutElementImpl(this, options);
11304
11532
  this.elements.set(element.componentId, element);
11305
11533
  return element;
@@ -11746,7 +11974,9 @@ class ElementsGroupImpl {
11746
11974
  };
11747
11975
  this.postControl(control);
11748
11976
  }
11749
- resolveWalletClick(componentId, requestId, accepted, options) {
11977
+ resolveWalletClick(componentId, requestId, accepted, options, amount) {
11978
+ if (accepted && amount !== undefined)
11979
+ this.commitAmountUpdate(amount);
11750
11980
  const snapshot = this.getUpdateSnapshot().options;
11751
11981
  const message = {
11752
11982
  channel: ELEMENTS_COMPONENT_CHANNEL,
@@ -11965,13 +12195,17 @@ class ElementsGroupImpl {
11965
12195
  if (this.destroyed) {
11966
12196
  throw new Error('[Paypercut Elements] Cannot update a destroyed group.');
11967
12197
  }
12198
+ const activeElementSubmission = Array.from(this.elements.values()).some((element) => element.hasActiveSubmission());
12199
+ const activeProviderSubmission = Array.from(this.elements.values()).some((element) => element.componentType === 'express_checkout'
12200
+ ? element.hasActiveProviderSubmission()
12201
+ : element.hasActiveSubmission());
11968
12202
  if (this.pendingValidation !== null ||
11969
12203
  this.paymentMethodSubmission.hasActiveSubmission() ||
11970
- Array.from(this.elements.values()).some((element) => element.hasActiveSubmission())) {
12204
+ (options.appearance !== undefined ? activeElementSubmission : activeProviderSubmission)) {
11971
12205
  if (options.appearance !== undefined) {
11972
12206
  throw new AppearancePreviewError('elements_appearance_preview_refused', 'Appearance Preview is unavailable while payment validation, Card authentication, or a wallet attempt is active.');
11973
12207
  }
11974
- throw new Error('[Paypercut Elements] Cannot update Elements while payment details are being submitted.');
12208
+ throw createElementsError('elements_submission_in_progress', '[Paypercut Elements] Cannot update Elements while payment details are being submitted.', true);
11975
12209
  }
11976
12210
  const update = normalizeUpdateOptions(options, this.appearance, this.amount);
11977
12211
  const appearanceWasRequested = options.appearance !== undefined;
@@ -11996,6 +12230,10 @@ class ElementsGroupImpl {
11996
12230
  if (update.amount === this.amount && !appearanceChanged) {
11997
12231
  return Promise.resolve();
11998
12232
  }
12233
+ if (!appearanceChanged) {
12234
+ this.commitAmountUpdate(update.amount);
12235
+ return Promise.resolve();
12236
+ }
11999
12237
  if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
12000
12238
  throw new Error('[Paypercut Elements] The update revision limit has been reached.');
12001
12239
  }
@@ -12027,6 +12265,26 @@ class ElementsGroupImpl {
12027
12265
  this.postControl(message);
12028
12266
  return Promise.resolve();
12029
12267
  }
12268
+ commitAmountUpdate(amount) {
12269
+ if (amount === this.amount)
12270
+ return;
12271
+ if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
12272
+ throw new Error('[Paypercut Elements] The update revision limit has been reached.');
12273
+ }
12274
+ this.amount = amount;
12275
+ this.invalidateSubmissionValidation();
12276
+ this.updateRevision += 1;
12277
+ if (!this.controllerInitialized)
12278
+ return;
12279
+ const snapshot = this.getUpdateSnapshot();
12280
+ this.postControl({
12281
+ channel: ELEMENTS_COMPONENT_CHANNEL,
12282
+ type: ElementsControllerCommandType.UpdateOptions,
12283
+ controllerId: this.controllerId,
12284
+ updateRevision: snapshot.updateRevision,
12285
+ options: snapshot.options,
12286
+ });
12287
+ }
12030
12288
  startAppearancePreview(appearance, deferCommit = false) {
12031
12289
  const generation = ++this.appearancePreviewGeneration;
12032
12290
  const previous = cloneElementsAppearance(this.appearance);
@@ -12188,6 +12446,9 @@ class ElementsGroupImpl {
12188
12446
  hasMountedCardFields() {
12189
12447
  return Array.from(this.cardFields.values()).some((field) => field.isMounted());
12190
12448
  }
12449
+ hasVisibleCardFields() {
12450
+ return Array.from(this.cardFields.values()).some((field) => field.isVisible());
12451
+ }
12191
12452
  warnAppearancePreview(error) {
12192
12453
  if (error.code === 'elements_appearance_preview_superseded')
12193
12454
  return;
@@ -12284,6 +12545,7 @@ class ElementsGroupImpl {
12284
12545
  configurationIdentity: this.configurationIdentity,
12285
12546
  appearanceScopeId: this.controllerId,
12286
12547
  presetSource: 'split-card',
12548
+ isVisible: () => !this.destroyed && this.hasVisibleCardFields(),
12287
12549
  isAvailable: () => !this.destroyed && this.cardCollectionRuntime.canApplyDeveloperPreset(),
12288
12550
  isAppearanceAvailable: () => !this.destroyed && this.hasMountedCardFields(),
12289
12551
  appearancePreviewClearsTestData: () => true,