@paypercut/checkout-js 1.3.1 → 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.mjs CHANGED
@@ -100,6 +100,8 @@ class Emitter {
100
100
  }
101
101
  }
102
102
 
103
+ const SDK_VERSION = "1.4.1";
104
+
103
105
  /**
104
106
  * Build-time configuration
105
107
  *
@@ -111,8 +113,7 @@ class Emitter {
111
113
  * Production configuration (for merchants)
112
114
  */
113
115
  const productionConfig = {
114
- version: "1.3.1",
115
- mode: 'production',
116
+ version: SDK_VERSION,
116
117
  defaultCheckoutOrigin: 'https://buy.paypercut.io',
117
118
  defaultApiOrigin: 'https://api.paypercut.io',
118
119
  defaultVaultApiUrl: 'https://api.basistheory.com',
@@ -2446,6 +2447,7 @@ const ElementsControllerCommandType = {
2446
2447
  CancelComponentSubmission: 'PAYPERCUT_ELEMENTS_CONTROLLER_CANCEL_COMPONENT_SUBMISSION',
2447
2448
  AttachActionChannel: 'PAYPERCUT_ELEMENTS_CONTROLLER_ATTACH_ACTION_CHANNEL',
2448
2449
  UpdateOptions: 'PAYPERCUT_ELEMENTS_CONTROLLER_UPDATE_OPTIONS',
2450
+ DiscoverDeveloperPresets: 'PAYPERCUT_ELEMENTS_CONTROLLER_DISCOVER_DEVELOPER_PRESETS',
2449
2451
  ApplyDeveloperPreset: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLY_DEVELOPER_PRESET',
2450
2452
  ApplePayCapabilities: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLE_PAY_CAPABILITIES',
2451
2453
  ApplePayValidateMerchant: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLE_PAY_VALIDATE_MERCHANT',
@@ -2967,148 +2969,232 @@ const isDeveloperPreset = (value) => isRecord$2(value) &&
2967
2969
  /^\d{4}$/.test(value.last4) &&
2968
2970
  ['success', 'challenge', 'warning', 'danger'].includes(String(value.tone));
2969
2971
 
2970
- const LIGHT_VARIABLES = {
2971
- colorPrimary: '#0570de',
2972
- colorPrimaryText: '#ffffff',
2973
- colorBackground: '#ffffff',
2974
- colorSurface: '#ffffff',
2975
- colorText: '#2b2d2f',
2976
- colorTextSecondary: '#6a6c6f',
2977
- colorTextPlaceholder: '#737474',
2978
- colorDanger: '#cc1818',
2979
- colorSuccess: '#30b130',
2980
- colorWarning: '#e69e2c',
2981
- colorBorder: '#d7dde0',
2982
- colorFocus: '#0570de',
2983
- colorMuted: '#f2f4f5',
2984
- fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
2985
- fontSizeBase: '16px',
2986
- fontWeightNormal: '400',
2987
- fontWeightMedium: '500',
2988
- lineHeight: '1.5',
2989
- spacingUnit: '4px',
2990
- gridColumnSpacing: '12px',
2991
- gridRowSpacing: '12px',
2992
- labelSpacing: '6px',
2993
- borderRadius: '4px',
2994
- buttonBorderRadius: '4px',
2995
- buttonExpressCheckoutBorderRadius: '4px',
2996
- buttonPadding: '12px',
2997
- };
2998
- const DARK_VARIABLES = {
2999
- ...LIGHT_VARIABLES,
3000
- colorBackground: '#15171c',
3001
- colorSurface: '#1d2027',
3002
- colorText: '#f3f4f6',
3003
- colorTextSecondary: '#aeb7c7',
3004
- colorTextPlaceholder: '#8f99aa',
3005
- colorBorder: '#3a404b',
3006
- colorFocus: '#7db7ff',
3007
- colorMuted: '#252932',
3008
- };
3009
- const VARIABLE_NAMES = new Set(Object.keys(LIGHT_VARIABLES));
3010
- const PUBLIC_VARIABLE_REFERENCE = /var\(\s*--([A-Za-z][A-Za-z0-9]*)\s*\)/g;
3011
- function resolveCardFieldAppearance(appearance) {
3012
- const theme = appearance?.theme ?? 'light';
3013
- const themeVariables = theme === 'dark' ? DARK_VARIABLES : LIGHT_VARIABLES;
3014
- const overrides = Object.fromEntries(Object.entries(appearance?.variables ?? {}).filter(([name, value]) => VARIABLE_NAMES.has(name) && typeof value === 'string'));
3015
- return {
3016
- theme,
3017
- disableAnimations: appearance?.disableAnimations ?? false,
3018
- variables: {
3019
- ...themeVariables,
3020
- ...overrides,
3021
- },
3022
- };
2972
+ const DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT = 'paypercut-developer-assistance.iife.min.js';
2973
+ const DEVELOPER_ASSISTANCE_MODULE_ARTIFACT = 'developer-assistance.mjs';
2974
+ const DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC = '[Paypercut Elements] developer_assistance_load_failed: Developer Assistant is unavailable. The SDK and Elements continue to work.';
2975
+ const IIFE_ARTIFACT_PATH = /\/paypercut-checkout(?:-dev)?\.iife\.min\.js$/;
2976
+ // Rollup rewrites import.meta.url for CommonJS and classic-script bundles, so
2977
+ // this remains the URL of the exact core artifact that owns the registration
2978
+ // boundary in every supported format.
2979
+ const coreArtifactUrl = typeof __filename === 'string' ? fileUrlFor(__filename) : import.meta.url;
2980
+ const classicScriptUrl = typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
2981
+ let loadRequested = false;
2982
+ function requestDeveloperAssistance(isInstalled) {
2983
+ if (loadRequested || isInstalled())
2984
+ return;
2985
+ loadRequested = true;
2986
+ if (!canLoadDeveloperAssistance()) {
2987
+ warnDeveloperAssistanceUnavailable();
2988
+ return;
2989
+ }
2990
+ void Promise.resolve()
2991
+ .then(loadDeveloperAssistance)
2992
+ .then(() => {
2993
+ if (!isInstalled())
2994
+ throw new Error();
2995
+ })
2996
+ .catch(warnDeveloperAssistanceUnavailable);
3023
2997
  }
3024
- /** Resolve one semantic public rule to concrete provider/DOM style values. */
3025
- function resolveCardFieldAppearanceRule(appearance, selector) {
3026
- const rule = appearance?.rules?.[selector];
3027
- if (!rule)
3028
- return {};
3029
- const variables = resolveCardFieldAppearance(appearance).variables;
3030
- return Object.fromEntries(Object.entries(rule).flatMap(([property, value]) => {
3031
- if (typeof value !== 'string' || !isSafeElementsAppearanceValue(value))
3032
- return [];
3033
- return [
3034
- [
3035
- property,
3036
- value.replace(PUBLIC_VARIABLE_REFERENCE, (match, name) => name in variables ? variables[name] : match),
3037
- ],
3038
- ];
3039
- }));
2998
+ function warnDeveloperAssistanceUnavailable() {
2999
+ console.warn(DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC);
3040
3000
  }
3041
- /**
3042
- * Compile the secure Basis Theory input style from the Hosted Checkout token
3043
- * baseline. Provider fields cannot inherit merchant-document CSS, so every
3044
- * public token and variable reference is resolved before crossing the provider
3045
- * boundary. Physical end-adornment separation is owned by CardFieldSurface.
3046
- */
3047
- function createBasisTheoryCardFieldStyle(appearance, presentation) {
3048
- const variables = resolveCardFieldAppearance(appearance).variables;
3049
- const inputRule = resolveCardFieldAppearanceRule(appearance, '.Input');
3050
- const invalidRule = resolveCardFieldAppearanceRule(appearance, '.Input--invalid');
3051
- const inputBackgroundColor = inputRule.backgroundColor ?? variables.colorSurface;
3052
- const inputColor = inputRule.color ?? variables.colorText;
3053
- const invalidBackgroundColor = invalidRule.backgroundColor ?? inputBackgroundColor;
3054
- const invalidColor = invalidRule.color ?? inputColor;
3055
- const chromeIosAttributeAutofill = typeof navigator !== 'undefined' && /\bCriOS\//.test(navigator.userAgent);
3056
- const providerStateValue = (value) => chromeIosAttributeAutofill ? `${value} !important` : value;
3001
+ function canLoadDeveloperAssistance() {
3002
+ return (typeof document !== 'undefined' &&
3003
+ typeof document.createElement === 'function' &&
3004
+ Boolean(document.head || document.documentElement));
3005
+ }
3006
+ function loadDeveloperAssistance() {
3007
+ if (classicScriptUrl || isClassicScriptArtifact(coreArtifactUrl)) {
3008
+ return loadClassicScript(resolveBrowserArtifactUrl(coreArtifactUrl));
3009
+ }
3010
+ const moduleUrl = new URL(DEVELOPER_ASSISTANCE_MODULE_ARTIFACT, coreArtifactUrl).href;
3011
+ return import(/* @vite-ignore */ moduleUrl);
3012
+ }
3013
+ function fileUrlFor(filename) {
3014
+ const normalized = filename.replace(/\\/g, '/');
3015
+ return new URL(`file://${normalized.startsWith('/') ? '' : '/'}${normalized}`).href;
3016
+ }
3017
+ function resolveBrowserArtifactUrl(coreUrl) {
3018
+ const url = new URL(coreUrl);
3019
+ if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
3020
+ const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
3021
+ artifactUrl.search = url.search;
3022
+ artifactUrl.hash = '';
3023
+ return artifactUrl.href;
3024
+ }
3025
+ if (/\.js$/.test(url.pathname)) {
3026
+ url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
3027
+ }
3028
+ else if (/\/cdn\/?$/.test(url.pathname)) {
3029
+ url.pathname = url.pathname.replace(/\/cdn\/?$/, `/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`);
3030
+ }
3031
+ else {
3032
+ url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
3033
+ }
3034
+ url.hash = '';
3035
+ return url.href;
3036
+ }
3037
+ function isClassicScriptArtifact(url) {
3038
+ try {
3039
+ return IIFE_ARTIFACT_PATH.test(new URL(url).pathname);
3040
+ }
3041
+ catch {
3042
+ return false;
3043
+ }
3044
+ }
3045
+ function loadClassicScript(src) {
3046
+ return new Promise((resolve, reject) => {
3047
+ const script = document.createElement('script');
3048
+ script.async = true;
3049
+ script.src = src;
3050
+ script.addEventListener('load', () => resolve(), { once: true });
3051
+ script.addEventListener('error', () => reject(new Error()), { once: true });
3052
+ (document.head || document.documentElement).appendChild(script);
3053
+ });
3054
+ }
3055
+
3056
+ const registryKey = Symbol.for('paypercut.checkout-js.developer-assistance');
3057
+ function getRegistry() {
3058
+ const globals = globalThis;
3059
+ globals[registryKey] ?? (globals[registryKey] = {
3060
+ coreVersions: new Set(),
3061
+ provider: null,
3062
+ registrations: new Set(),
3063
+ });
3064
+ return globals[registryKey];
3065
+ }
3066
+ function announceDeveloperAssistantCore() {
3067
+ const registry = getRegistry();
3068
+ if (registry.provider && registry.provider.version !== SDK_VERSION) {
3069
+ for (const entry of registry.registrations) {
3070
+ safelyUnregister(entry);
3071
+ }
3072
+ registry.provider = null;
3073
+ }
3074
+ registry.coreVersions.add(SDK_VERSION);
3075
+ }
3076
+ function safelyUnregister(entry) {
3077
+ try {
3078
+ entry.delegate?.unregister();
3079
+ }
3080
+ catch {
3081
+ // Developer Assistance is optional and must not interrupt owner teardown.
3082
+ }
3083
+ entry.delegate = null;
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
+ }
3149
+ function registerDeveloperAssistantTarget(target) {
3150
+ const registry = getRegistry();
3151
+ announceDeveloperAssistantCore();
3152
+ const entry = { target, delegate: null, registered: true };
3153
+ registry.registrations.add(entry);
3154
+ observeTargetVisibility(registry);
3155
+ syncAttachment(entry, registry);
3057
3156
  return {
3058
- base: {
3059
- // Basis Theory v2 derives its high-specificity browser-autofill paint
3060
- // from the active state's color and backgroundColor. An explicitly
3061
- // opaque surface prevents Chrome/WebKit's native blue fill from showing
3062
- // through only the provider iframe while the SDK-owned badge lane keeps
3063
- // the configured surface color.
3064
- backgroundColor: inputBackgroundColor,
3065
- color: inputColor,
3066
- fontFamily: variables.fontFamily,
3067
- fontSize: variables.fontSizeBase,
3068
- fontWeight: variables.fontWeightNormal,
3069
- lineHeight: variables.lineHeight,
3070
- // The provider is clipped to its own physical region when card brands
3071
- // are visible. Keep ordinary input padding here so provider- or
3072
- // extension-owned controls can use that region's far-right edge.
3073
- padding: !presentation
3074
- ? '12px'
3075
- : presentation.floatingLabels
3076
- ? presentation.floatingLabelActive
3077
- ? '23px 12px 9px 12px'
3078
- : '16px 12px 16px 12px'
3079
- : '12px',
3080
- '::placeholder': {
3081
- color: variables.colorTextPlaceholder,
3082
- },
3083
- ':disabled': {
3084
- backgroundColor: inputBackgroundColor,
3085
- },
3086
- ...inputRule,
3087
- },
3088
- empty: {
3089
- // Chrome on iOS injects a later `[chrome-autofilled]` rule with an
3090
- // !important blue background inside each secure provider iframe. Basis
3091
- // Theory v2 filters custom attribute selectors, but its empty/invalid/
3092
- // complete state rules are deliberately class-qualified three times.
3093
- // On CriOS only, matching importance lets those supported state rules
3094
- // outrank Chrome without disabling native saved-card autofill.
3095
- backgroundColor: providerStateValue(inputBackgroundColor),
3096
- color: providerStateValue(inputColor),
3157
+ unregister() {
3158
+ if (!entry.registered)
3159
+ return;
3160
+ entry.registered = false;
3161
+ registry.registrations.delete(entry);
3162
+ safelyUnregister(entry);
3163
+ stopObservingTargetVisibilityIfIdle(registry);
3097
3164
  },
3098
- invalid: {
3099
- // Paypercut owns the visible validation treatment. Provider text remains
3100
- // neutral while incomplete input is being edited.
3101
- ...invalidRule,
3102
- backgroundColor: providerStateValue(invalidBackgroundColor),
3103
- color: providerStateValue(invalidColor),
3165
+ refresh() {
3166
+ if (!entry.registered)
3167
+ return;
3168
+ syncAttachment(entry, registry);
3169
+ entry.delegate?.refresh();
3104
3170
  },
3105
- complete: {
3106
- backgroundColor: providerStateValue(inputBackgroundColor),
3107
- color: providerStateValue(inputColor),
3171
+ collapse() {
3172
+ if (entry.registered)
3173
+ entry.delegate?.collapse();
3108
3174
  },
3109
3175
  };
3110
3176
  }
3111
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
+
3112
3198
  const FRAME_URL_LENGTH_WARNING_THRESHOLD = 4096;
3113
3199
  let hasWarnedAboutLongFrameUrl = false;
3114
3200
  const ELEMENTS_FRAME_NAVIGATION_QUERY = '__paypercut_navigation';
@@ -4850,12 +4936,41 @@ class CardElementImpl {
4850
4936
  pending.resolve();
4851
4937
  }
4852
4938
  registerDeveloperPresets(presets) {
4853
- {
4854
- return;
4855
- }
4939
+ if (this.group.getClientOptions().developerAssistant !== true) {
4940
+ return;
4941
+ }
4942
+ if (this.developerAssistant) {
4943
+ // Hosted Card republishes the same authorized catalog after an Appearance
4944
+ // replacement. Keep the existing target and controls alive so the pending
4945
+ // request can release its lock and restore focus on the original control.
4946
+ this.developerAssistant.refresh();
4947
+ return;
4948
+ }
4949
+ this.developerAssistant = registerDeveloperAssistantTarget({
4950
+ id: `${this.group.controllerId}:${this.componentId}`,
4951
+ configurationIdentity: this.group.configurationIdentity,
4952
+ appearanceScopeId: this.group.controllerId,
4953
+ presets,
4954
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
4955
+ isAvailable: () => this.canApplyDeveloperPreset(),
4956
+ isAppearanceAvailable: () => this.isMounted(),
4957
+ appearancePreviewClearsTestData: () => true,
4958
+ canPreview: () => this.group.isAppearancePreviewAvailable(),
4959
+ applyPreset: (presetId) => this.applyDeveloperPreset(presetId),
4960
+ getAppearance: () => this.group.getAppearance(),
4961
+ updateAppearance: (appearance) => this.group.updateAppearance(appearance),
4962
+ replaceAppearance: (appearance) => this.group.replaceAppearance(appearance),
4963
+ prepareAppearance: (appearance) => this.group.prepareAppearance(appearance),
4964
+ prepareAppearanceReplacement: (appearance) => this.group.prepareAppearanceReplacement(appearance),
4965
+ });
4856
4966
  }
4857
4967
  canApplyDeveloperPreset() {
4858
- return (config.mode === 'internal');
4968
+ return (this.group.getClientOptions().developerAssistant === true &&
4969
+ this.ready &&
4970
+ !this.destroyed &&
4971
+ !this.group.hasPaymentMethodSubmissionState(this.componentId) &&
4972
+ !this.group.hasCompletedPaymentMethodSubmission(this.componentId) &&
4973
+ !this.pendingDeveloperPreset);
4859
4974
  }
4860
4975
  applyDeveloperPreset(presetId) {
4861
4976
  if (!this.canApplyDeveloperPreset()) {
@@ -5031,6 +5146,100 @@ function patchApplePayModalFocus(modal, attempts = 0) {
5031
5146
  root.appendChild(style);
5032
5147
  }
5033
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
+
5034
5243
  const MAX_IFRAME_HEIGHT = 4096;
5035
5244
  const EXPRESS_PREVIEW_INITIALIZATION_TIMEOUT_MS = 10000;
5036
5245
  const WALLET_OVERLAY_FALLBACK_Z_INDEX = '2147483647';
@@ -5110,6 +5319,7 @@ class ExpressCheckoutElementImpl {
5110
5319
  this.googlePayEnvironment = null;
5111
5320
  this.googlePayRequestId = null;
5112
5321
  this.googlePayProcessingRequestId = null;
5322
+ this.googlePayPopupRecovery = null;
5113
5323
  this.googlePayUpdates = new Map();
5114
5324
  this.googlePayAuthorization = null;
5115
5325
  this.googlePayButtonTarget = null;
@@ -5184,7 +5394,7 @@ class ExpressCheckoutElementImpl {
5184
5394
  this.group.updateExpressCheckoutComponent(this.componentId, this.componentRevision, this.getComponentOptions());
5185
5395
  }
5186
5396
  getComponentOptions() {
5187
- return structuredCloneSafe(this.options);
5397
+ return structuredCloneSafe(this.pendingPreview?.nextOptions ?? this.options);
5188
5398
  }
5189
5399
  isMounted() {
5190
5400
  return this.mounted && !this.destroyed;
@@ -5229,6 +5439,14 @@ class ExpressCheckoutElementImpl {
5229
5439
  this.applePaySession !== null ||
5230
5440
  this.googlePayRequestId !== null);
5231
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
+ }
5232
5450
  handleControllerError(error) {
5233
5451
  if (this.destroyed)
5234
5452
  return;
@@ -5626,9 +5844,27 @@ class ExpressCheckoutElementImpl {
5626
5844
  };
5627
5845
  }
5628
5846
  registerDeveloperAssistant() {
5629
- {
5630
- return;
5631
- }
5847
+ if (this.group.getClientOptions().developerAssistant !== true) {
5848
+ return;
5849
+ }
5850
+ this.developerAssistant = registerDeveloperAssistantTarget({
5851
+ id: `${this.group.controllerId}:${this.componentId}:express-checkout`,
5852
+ configurationIdentity: this.group.configurationIdentity,
5853
+ appearanceScopeId: this.group.controllerId,
5854
+ componentDisplayScopeId: this.componentId,
5855
+ isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
5856
+ isAvailable: () => true,
5857
+ isAppearanceAvailable: () => this.isMounted(),
5858
+ canPreview: () => this.group.isAppearancePreviewAvailable(),
5859
+ getAppearance: () => this.group.getAppearance(),
5860
+ updateAppearance: (appearance) => this.group.updateAppearance(appearance),
5861
+ replaceAppearance: (appearance) => this.group.replaceAppearance(appearance),
5862
+ prepareAppearance: (appearance) => this.group.prepareAppearance(appearance),
5863
+ prepareAppearanceReplacement: (appearance) => this.group.prepareAppearanceReplacement(appearance),
5864
+ getComponentDisplayOptions: () => developerDisplayOptions(this.options),
5865
+ updateComponentDisplayOptions: (options) => this.updateDeveloperDisplayOptions(options),
5866
+ replaceComponentDisplayOptions: (options) => this.replaceDeveloperDisplayOptions(options),
5867
+ });
5632
5868
  }
5633
5869
  onWindowMessage(event) {
5634
5870
  if (this.destroyed ||
@@ -5758,7 +5994,9 @@ class ExpressCheckoutElementImpl {
5758
5994
  const settle = (accepted, options) => {
5759
5995
  if (settled || this.destroyed || this.activeAttempt?.requestId !== requestId)
5760
5996
  return;
5761
- 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;
5762
6000
  settled = true;
5763
6001
  window.clearTimeout(timeout);
5764
6002
  if (accepted && this.activeAttempt?.requestId === requestId) {
@@ -5768,11 +6006,23 @@ class ExpressCheckoutElementImpl {
5768
6006
  ...(validatedOptions ?? {}),
5769
6007
  });
5770
6008
  }
5771
- 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
+ }
5772
6015
  if (!accepted) {
5773
6016
  this.group.endWalletAttempt(this.componentId, requestId);
5774
- this.activeAttempt = null;
5775
- 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
+ }
5776
6026
  }
5777
6027
  };
5778
6028
  // Woo and other commerce adapters may need to validate their checkout and
@@ -6135,10 +6385,22 @@ class ExpressCheckoutElementImpl {
6135
6385
  this.googlePayClient = this.createGooglePayClient(environment, Object.keys(paymentDataCallbacks).length > 0 ? paymentDataCallbacks : undefined);
6136
6386
  // Keep the browser launch synchronous with the relayed click. Awaiting
6137
6387
  // script or merchant work here loses mobile popup/user-activation state.
6138
- 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;
6139
6400
  void Promise.resolve(payment).then((data) => {
6140
6401
  if (this.googlePayRequestId !== requestId || this.destroyed)
6141
6402
  return;
6403
+ this.clearGooglePayPopupRecovery();
6142
6404
  // Google has returned control to the merchant document at this
6143
6405
  // boundary. Keep blocking duplicate checkout interactions, but stop
6144
6406
  // telling the customer that the provider window is still open while
@@ -6149,13 +6411,17 @@ class ExpressCheckoutElementImpl {
6149
6411
  }, (error) => {
6150
6412
  if (this.googlePayRequestId !== requestId || this.destroyed)
6151
6413
  return;
6152
- if (isGooglePayCancellation(error)) {
6153
- 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
+ }
6154
6421
  }
6155
- else {
6156
- this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
6422
+ finally {
6423
+ this.clearGooglePayAttempt(requestId);
6157
6424
  }
6158
- this.clearGooglePayAttempt(requestId);
6159
6425
  });
6160
6426
  }
6161
6427
  catch (error) {
@@ -6242,6 +6508,7 @@ class ExpressCheckoutElementImpl {
6242
6508
  clearGooglePayAttempt(requestId) {
6243
6509
  if (requestId && this.googlePayRequestId !== requestId)
6244
6510
  return;
6511
+ this.clearGooglePayPopupRecovery();
6245
6512
  this.googlePayRequestId = null;
6246
6513
  this.googlePayProcessingRequestId = null;
6247
6514
  for (const pending of this.googlePayUpdates.values()) {
@@ -6256,6 +6523,10 @@ class ExpressCheckoutElementImpl {
6256
6523
  }
6257
6524
  this.positionGooglePayButton();
6258
6525
  }
6526
+ clearGooglePayPopupRecovery() {
6527
+ this.googlePayPopupRecovery?.stop();
6528
+ this.googlePayPopupRecovery = null;
6529
+ }
6259
6530
  startApplePay(requestId, request) {
6260
6531
  this.abortApplePay();
6261
6532
  const ApplePayAPI = window.ApplePaySession;
@@ -6455,6 +6726,16 @@ const OPTION_KEYS = new Set([
6455
6726
  'lineItems',
6456
6727
  'shippingRates',
6457
6728
  ]);
6729
+ function developerDisplayOptions(options) {
6730
+ return structuredCloneSafe({
6731
+ ...(options.paymentMethods ? { paymentMethods: options.paymentMethods } : {}),
6732
+ ...(options.layout ? { layout: options.layout } : {}),
6733
+ ...(options.buttonType ? { buttonType: options.buttonType } : {}),
6734
+ ...(options.buttonTheme ? { buttonTheme: options.buttonTheme } : {}),
6735
+ ...(options.buttonHeight !== undefined ? { buttonHeight: options.buttonHeight } : {}),
6736
+ ...(options.buttonRadius !== undefined ? { buttonRadius: options.buttonRadius } : {}),
6737
+ });
6738
+ }
6458
6739
  function mergeDeveloperDisplayOptions(current, update) {
6459
6740
  return {
6460
6741
  ...current,
@@ -6596,6 +6877,7 @@ function validateClickResolveOptions(options) {
6596
6877
  if (options === undefined)
6597
6878
  return undefined;
6598
6879
  const allowed = new Set([
6880
+ 'amount',
6599
6881
  'lineItems',
6600
6882
  'emailRequired',
6601
6883
  'phoneNumberRequired',
@@ -6607,6 +6889,12 @@ function validateClickResolveOptions(options) {
6607
6889
  if (!isRecord(options) || Object.keys(options).some((key) => !allowed.has(key))) {
6608
6890
  throw invalidOptions();
6609
6891
  }
6892
+ if (options.amount !== undefined &&
6893
+ (typeof options.amount !== 'number' ||
6894
+ !Number.isSafeInteger(options.amount) ||
6895
+ options.amount < 0)) {
6896
+ throw invalidOptions();
6897
+ }
6610
6898
  validateRows(options.lineItems, 'name');
6611
6899
  validateRows(options.shippingRates, 'displayName', true);
6612
6900
  for (const flag of [
@@ -6634,7 +6922,7 @@ function validateClickResolveOptions(options) {
6634
6922
  });
6635
6923
  }
6636
6924
  function validateElementUpdateOptions(options) {
6637
- if (!isRecord(options) || Object.keys(options).length === 0) {
6925
+ if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
6638
6926
  throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
6639
6927
  }
6640
6928
  return validateClickResolveOptions(options);
@@ -7325,6 +7613,148 @@ class ElementsWalletAttemptOverlay {
7325
7613
  }
7326
7614
  }
7327
7615
 
7616
+ const LIGHT_VARIABLES = {
7617
+ colorPrimary: '#0570de',
7618
+ colorPrimaryText: '#ffffff',
7619
+ colorBackground: '#ffffff',
7620
+ colorSurface: '#ffffff',
7621
+ colorText: '#2b2d2f',
7622
+ colorTextSecondary: '#6a6c6f',
7623
+ colorTextPlaceholder: '#737474',
7624
+ colorDanger: '#cc1818',
7625
+ colorSuccess: '#30b130',
7626
+ colorWarning: '#e69e2c',
7627
+ colorBorder: '#d7dde0',
7628
+ colorFocus: '#0570de',
7629
+ colorMuted: '#f2f4f5',
7630
+ fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
7631
+ fontSizeBase: '16px',
7632
+ fontWeightNormal: '400',
7633
+ fontWeightMedium: '500',
7634
+ lineHeight: '1.5',
7635
+ spacingUnit: '4px',
7636
+ gridColumnSpacing: '12px',
7637
+ gridRowSpacing: '12px',
7638
+ labelSpacing: '6px',
7639
+ borderRadius: '4px',
7640
+ buttonBorderRadius: '4px',
7641
+ buttonExpressCheckoutBorderRadius: '4px',
7642
+ buttonPadding: '12px',
7643
+ };
7644
+ const DARK_VARIABLES = {
7645
+ ...LIGHT_VARIABLES,
7646
+ colorBackground: '#15171c',
7647
+ colorSurface: '#1d2027',
7648
+ colorText: '#f3f4f6',
7649
+ colorTextSecondary: '#aeb7c7',
7650
+ colorTextPlaceholder: '#8f99aa',
7651
+ colorBorder: '#3a404b',
7652
+ colorFocus: '#7db7ff',
7653
+ colorMuted: '#252932',
7654
+ };
7655
+ const VARIABLE_NAMES = new Set(Object.keys(LIGHT_VARIABLES));
7656
+ const PUBLIC_VARIABLE_REFERENCE = /var\(\s*--([A-Za-z][A-Za-z0-9]*)\s*\)/g;
7657
+ function resolveCardFieldAppearance(appearance) {
7658
+ const theme = appearance?.theme ?? 'light';
7659
+ const themeVariables = theme === 'dark' ? DARK_VARIABLES : LIGHT_VARIABLES;
7660
+ const overrides = Object.fromEntries(Object.entries(appearance?.variables ?? {}).filter(([name, value]) => VARIABLE_NAMES.has(name) && typeof value === 'string'));
7661
+ return {
7662
+ theme,
7663
+ disableAnimations: appearance?.disableAnimations ?? false,
7664
+ variables: {
7665
+ ...themeVariables,
7666
+ ...overrides,
7667
+ },
7668
+ };
7669
+ }
7670
+ /** Resolve one semantic public rule to concrete provider/DOM style values. */
7671
+ function resolveCardFieldAppearanceRule(appearance, selector) {
7672
+ const rule = appearance?.rules?.[selector];
7673
+ if (!rule)
7674
+ return {};
7675
+ const variables = resolveCardFieldAppearance(appearance).variables;
7676
+ return Object.fromEntries(Object.entries(rule).flatMap(([property, value]) => {
7677
+ if (typeof value !== 'string' || !isSafeElementsAppearanceValue(value))
7678
+ return [];
7679
+ return [
7680
+ [
7681
+ property,
7682
+ value.replace(PUBLIC_VARIABLE_REFERENCE, (match, name) => name in variables ? variables[name] : match),
7683
+ ],
7684
+ ];
7685
+ }));
7686
+ }
7687
+ /**
7688
+ * Compile the secure Basis Theory input style from the Hosted Checkout token
7689
+ * baseline. Provider fields cannot inherit merchant-document CSS, so every
7690
+ * public token and variable reference is resolved before crossing the provider
7691
+ * boundary. Physical end-adornment separation is owned by CardFieldSurface.
7692
+ */
7693
+ function createBasisTheoryCardFieldStyle(appearance, presentation) {
7694
+ const variables = resolveCardFieldAppearance(appearance).variables;
7695
+ const inputRule = resolveCardFieldAppearanceRule(appearance, '.Input');
7696
+ const invalidRule = resolveCardFieldAppearanceRule(appearance, '.Input--invalid');
7697
+ const inputBackgroundColor = inputRule.backgroundColor ?? variables.colorSurface;
7698
+ const inputColor = inputRule.color ?? variables.colorText;
7699
+ const invalidBackgroundColor = invalidRule.backgroundColor ?? inputBackgroundColor;
7700
+ const invalidColor = invalidRule.color ?? inputColor;
7701
+ const chromeIosAttributeAutofill = typeof navigator !== 'undefined' && /\bCriOS\//.test(navigator.userAgent);
7702
+ const providerStateValue = (value) => chromeIosAttributeAutofill ? `${value} !important` : value;
7703
+ return {
7704
+ base: {
7705
+ // Basis Theory v2 derives its high-specificity browser-autofill paint
7706
+ // from the active state's color and backgroundColor. An explicitly
7707
+ // opaque surface prevents Chrome/WebKit's native blue fill from showing
7708
+ // through only the provider iframe while the SDK-owned badge lane keeps
7709
+ // the configured surface color.
7710
+ backgroundColor: inputBackgroundColor,
7711
+ color: inputColor,
7712
+ fontFamily: variables.fontFamily,
7713
+ fontSize: variables.fontSizeBase,
7714
+ fontWeight: variables.fontWeightNormal,
7715
+ lineHeight: variables.lineHeight,
7716
+ // The provider is clipped to its own physical region when card brands
7717
+ // are visible. Keep ordinary input padding here so provider- or
7718
+ // extension-owned controls can use that region's far-right edge.
7719
+ padding: !presentation
7720
+ ? '12px'
7721
+ : presentation.floatingLabels
7722
+ ? presentation.floatingLabelActive
7723
+ ? '23px 12px 9px 12px'
7724
+ : '16px 12px 16px 12px'
7725
+ : '12px',
7726
+ '::placeholder': {
7727
+ color: variables.colorTextPlaceholder,
7728
+ },
7729
+ ':disabled': {
7730
+ backgroundColor: inputBackgroundColor,
7731
+ },
7732
+ ...inputRule,
7733
+ },
7734
+ empty: {
7735
+ // Chrome on iOS injects a later `[chrome-autofilled]` rule with an
7736
+ // !important blue background inside each secure provider iframe. Basis
7737
+ // Theory v2 filters custom attribute selectors, but its empty/invalid/
7738
+ // complete state rules are deliberately class-qualified three times.
7739
+ // On CriOS only, matching importance lets those supported state rules
7740
+ // outrank Chrome without disabling native saved-card autofill.
7741
+ backgroundColor: providerStateValue(inputBackgroundColor),
7742
+ color: providerStateValue(inputColor),
7743
+ },
7744
+ invalid: {
7745
+ // Paypercut owns the visible validation treatment. Provider text remains
7746
+ // neutral while incomplete input is being edited.
7747
+ ...invalidRule,
7748
+ backgroundColor: providerStateValue(invalidBackgroundColor),
7749
+ color: providerStateValue(invalidColor),
7750
+ },
7751
+ complete: {
7752
+ backgroundColor: providerStateValue(inputBackgroundColor),
7753
+ color: providerStateValue(inputColor),
7754
+ },
7755
+ };
7756
+ }
7757
+
7328
7758
  const CARD_BRAND_BADGE_WIDTH_PX = 48;
7329
7759
  const CARD_BRAND_BADGE_HEIGHT_PX = 28;
7330
7760
  const INVALID_CARD_BADGE_WIDTH_PX = 36;
@@ -8055,6 +8485,9 @@ class CardFieldElementImpl {
8055
8485
  isMounted() {
8056
8486
  return this.mounted && !this.destroyed;
8057
8487
  }
8488
+ isVisible() {
8489
+ return isElementVisible(this.surface?.root ?? null);
8490
+ }
8058
8491
  destroy() {
8059
8492
  if (this.destroyed)
8060
8493
  return;
@@ -10393,7 +10826,7 @@ class CardCollectionRuntime {
10393
10826
  this.cancelPendingAppearancePreview(error);
10394
10827
  }
10395
10828
  supportsDeveloperPresets() {
10396
- return config.mode === 'internal';
10829
+ return this.bootstrap?.livemode === false;
10397
10830
  }
10398
10831
  announceAppearanceCommit() {
10399
10832
  if (this.destroyed)
@@ -11095,9 +11528,6 @@ class ElementsGroupImpl {
11095
11528
  return element;
11096
11529
  }
11097
11530
  if (type === 'expressCheckout') {
11098
- if (this.elementsOptions.mode !== 'payment') {
11099
- throw createElementsError('elements_component_configuration_invalid', 'Express Checkout is currently supported only in payment mode.', false);
11100
- }
11101
11531
  const element = new ExpressCheckoutElementImpl(this, options);
11102
11532
  this.elements.set(element.componentId, element);
11103
11533
  return element;
@@ -11544,7 +11974,9 @@ class ElementsGroupImpl {
11544
11974
  };
11545
11975
  this.postControl(control);
11546
11976
  }
11547
- resolveWalletClick(componentId, requestId, accepted, options) {
11977
+ resolveWalletClick(componentId, requestId, accepted, options, amount) {
11978
+ if (accepted && amount !== undefined)
11979
+ this.commitAmountUpdate(amount);
11548
11980
  const snapshot = this.getUpdateSnapshot().options;
11549
11981
  const message = {
11550
11982
  channel: ELEMENTS_COMPONENT_CHANNEL,
@@ -11613,7 +12045,16 @@ class ElementsGroupImpl {
11613
12045
  this.postControl(message);
11614
12046
  }
11615
12047
  discoverDeveloperPresets(componentId) {
11616
- return;
12048
+ if (this.clientOptions.developerAssistant !== true)
12049
+ return;
12050
+ const message = {
12051
+ channel: ELEMENTS_COMPONENT_CHANNEL,
12052
+ type: ElementsControllerCommandType.DiscoverDeveloperPresets,
12053
+ controllerId: this.controllerId,
12054
+ componentId,
12055
+ componentType: 'card',
12056
+ };
12057
+ this.postControl(message);
11617
12058
  }
11618
12059
  applyDeveloperPreset(componentId, requestId, presetId) {
11619
12060
  const message = {
@@ -11754,18 +12195,22 @@ class ElementsGroupImpl {
11754
12195
  if (this.destroyed) {
11755
12196
  throw new Error('[Paypercut Elements] Cannot update a destroyed group.');
11756
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());
11757
12202
  if (this.pendingValidation !== null ||
11758
12203
  this.paymentMethodSubmission.hasActiveSubmission() ||
11759
- Array.from(this.elements.values()).some((element) => element.hasActiveSubmission())) {
12204
+ (options.appearance !== undefined ? activeElementSubmission : activeProviderSubmission)) {
11760
12205
  if (options.appearance !== undefined) {
11761
12206
  throw new AppearancePreviewError('elements_appearance_preview_refused', 'Appearance Preview is unavailable while payment validation, Card authentication, or a wallet attempt is active.');
11762
12207
  }
11763
- 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);
11764
12209
  }
11765
12210
  const update = normalizeUpdateOptions(options, this.appearance, this.amount);
11766
12211
  const appearanceWasRequested = options.appearance !== undefined;
11767
12212
  const appearancePreviewEnabled = this.elementsOptions.appearanceUpdates === 'remount' ||
11768
- (config.mode === 'internal');
12213
+ this.clientOptions.developerAssistant === true;
11769
12214
  const hasMountedPaymentAppearanceTarget = this.hasMountedCardFields() ||
11770
12215
  this.getMountedCardElements().length > 0 ||
11771
12216
  this.getMountedExpressCheckoutElements().length > 0;
@@ -11785,6 +12230,10 @@ class ElementsGroupImpl {
11785
12230
  if (update.amount === this.amount && !appearanceChanged) {
11786
12231
  return Promise.resolve();
11787
12232
  }
12233
+ if (!appearanceChanged) {
12234
+ this.commitAmountUpdate(update.amount);
12235
+ return Promise.resolve();
12236
+ }
11788
12237
  if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
11789
12238
  throw new Error('[Paypercut Elements] The update revision limit has been reached.');
11790
12239
  }
@@ -11816,6 +12265,26 @@ class ElementsGroupImpl {
11816
12265
  this.postControl(message);
11817
12266
  return Promise.resolve();
11818
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
+ }
11819
12288
  startAppearancePreview(appearance, deferCommit = false) {
11820
12289
  const generation = ++this.appearancePreviewGeneration;
11821
12290
  const previous = cloneElementsAppearance(this.appearance);
@@ -11977,6 +12446,9 @@ class ElementsGroupImpl {
11977
12446
  hasMountedCardFields() {
11978
12447
  return Array.from(this.cardFields.values()).some((field) => field.isMounted());
11979
12448
  }
12449
+ hasVisibleCardFields() {
12450
+ return Array.from(this.cardFields.values()).some((field) => field.isVisible());
12451
+ }
11980
12452
  warnAppearancePreview(error) {
11981
12453
  if (error.code === 'elements_appearance_preview_superseded')
11982
12454
  return;
@@ -12061,9 +12533,30 @@ class ElementsGroupImpl {
12061
12533
  }
12062
12534
  ensureSplitCardDeveloperAssistant() {
12063
12535
  if (this.splitCardDeveloperAssistant ||
12064
- config.mode !== 'internal') {
12065
- return;
12066
- }
12536
+ this.clientOptions.developerAssistant !== true ||
12537
+ this.cardFields.size === 0 ||
12538
+ !this.cardCollectionRuntime.supportsDeveloperPresets() ||
12539
+ typeof window === 'undefined' ||
12540
+ typeof document === 'undefined') {
12541
+ return;
12542
+ }
12543
+ this.splitCardDeveloperAssistant = registerDeveloperAssistantTarget({
12544
+ id: `${this.controllerId}:split-card-fields`,
12545
+ configurationIdentity: this.configurationIdentity,
12546
+ appearanceScopeId: this.controllerId,
12547
+ presetSource: 'split-card',
12548
+ isVisible: () => !this.destroyed && this.hasVisibleCardFields(),
12549
+ isAvailable: () => !this.destroyed && this.cardCollectionRuntime.canApplyDeveloperPreset(),
12550
+ isAppearanceAvailable: () => !this.destroyed && this.hasMountedCardFields(),
12551
+ appearancePreviewClearsTestData: () => true,
12552
+ canPreview: () => this.isAppearancePreviewAvailable(),
12553
+ applyCardValue: (value) => this.cardCollectionRuntime.applyDeveloperPreset(value),
12554
+ getAppearance: () => this.getAppearance(),
12555
+ updateAppearance: (appearance) => this.updateAppearance(appearance),
12556
+ replaceAppearance: (appearance) => this.replaceAppearance(appearance),
12557
+ prepareAppearance: (appearance) => this.prepareAppearance(appearance),
12558
+ prepareAppearanceReplacement: (appearance) => this.prepareAppearanceReplacement(appearance),
12559
+ });
12067
12560
  }
12068
12561
  unregisterSplitCardDeveloperAssistant() {
12069
12562
  this.splitCardDeveloperAssistant?.unregister();
@@ -12735,6 +13228,7 @@ class PaymentConfirmationCoordinator {
12735
13228
  }
12736
13229
  }
12737
13230
 
13231
+ announceDeveloperAssistantCore();
12738
13232
  const MAX_PAYMENT_METHOD_BILLING_CACHE_SIZE = 16;
12739
13233
  const MAX_PUBLISHABLE_KEY_LENGTH = 512;
12740
13234
  const MAX_CREATE_PAYMENT_METHOD_OPTION_KEYS = 2;