@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/README.md +72 -1
- package/dist/developer-assistance.cjs +2769 -0
- package/dist/developer-assistance.cjs.map +1 -0
- package/dist/developer-assistance.d.cts +2 -0
- package/dist/developer-assistance.d.mts +2 -0
- package/dist/developer-assistance.mjs +2766 -0
- package/dist/developer-assistance.mjs.map +1 -0
- package/dist/index.cjs +661 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +898 -0
- package/dist/index.d.mts +898 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +660 -166
- package/dist/index.mjs.map +1 -1
- package/dist/paypercut-checkout.iife.min.js +1 -1
- package/dist/paypercut-checkout.iife.min.js.map +1 -1
- package/dist/paypercut-developer-assistance.iife.min.js +2 -0
- package/dist/paypercut-developer-assistance.iife.min.js.map +1 -0
- package/package.json +16 -6
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
5
6
|
/**
|
|
6
7
|
* Simple event emitter for handling checkout events
|
|
7
8
|
* Supports subscribing, unsubscribing, and emitting events
|
|
@@ -104,6 +105,8 @@ class Emitter {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
const SDK_VERSION = "1.4.1";
|
|
109
|
+
|
|
107
110
|
/**
|
|
108
111
|
* Build-time configuration
|
|
109
112
|
*
|
|
@@ -115,8 +118,7 @@ class Emitter {
|
|
|
115
118
|
* Production configuration (for merchants)
|
|
116
119
|
*/
|
|
117
120
|
const productionConfig = {
|
|
118
|
-
version:
|
|
119
|
-
mode: 'production',
|
|
121
|
+
version: SDK_VERSION,
|
|
120
122
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
121
123
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
122
124
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -2450,6 +2452,7 @@ const ElementsControllerCommandType = {
|
|
|
2450
2452
|
CancelComponentSubmission: 'PAYPERCUT_ELEMENTS_CONTROLLER_CANCEL_COMPONENT_SUBMISSION',
|
|
2451
2453
|
AttachActionChannel: 'PAYPERCUT_ELEMENTS_CONTROLLER_ATTACH_ACTION_CHANNEL',
|
|
2452
2454
|
UpdateOptions: 'PAYPERCUT_ELEMENTS_CONTROLLER_UPDATE_OPTIONS',
|
|
2455
|
+
DiscoverDeveloperPresets: 'PAYPERCUT_ELEMENTS_CONTROLLER_DISCOVER_DEVELOPER_PRESETS',
|
|
2453
2456
|
ApplyDeveloperPreset: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLY_DEVELOPER_PRESET',
|
|
2454
2457
|
ApplePayCapabilities: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLE_PAY_CAPABILITIES',
|
|
2455
2458
|
ApplePayValidateMerchant: 'PAYPERCUT_ELEMENTS_CONTROLLER_APPLE_PAY_VALIDATE_MERCHANT',
|
|
@@ -2971,148 +2974,232 @@ const isDeveloperPreset = (value) => isRecord$2(value) &&
|
|
|
2971
2974
|
/^\d{4}$/.test(value.last4) &&
|
|
2972
2975
|
['success', 'challenge', 'warning', 'danger'].includes(String(value.tone));
|
|
2973
2976
|
|
|
2974
|
-
const
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
buttonExpressCheckoutBorderRadius: '4px',
|
|
3000
|
-
buttonPadding: '12px',
|
|
3001
|
-
};
|
|
3002
|
-
const DARK_VARIABLES = {
|
|
3003
|
-
...LIGHT_VARIABLES,
|
|
3004
|
-
colorBackground: '#15171c',
|
|
3005
|
-
colorSurface: '#1d2027',
|
|
3006
|
-
colorText: '#f3f4f6',
|
|
3007
|
-
colorTextSecondary: '#aeb7c7',
|
|
3008
|
-
colorTextPlaceholder: '#8f99aa',
|
|
3009
|
-
colorBorder: '#3a404b',
|
|
3010
|
-
colorFocus: '#7db7ff',
|
|
3011
|
-
colorMuted: '#252932',
|
|
3012
|
-
};
|
|
3013
|
-
const VARIABLE_NAMES = new Set(Object.keys(LIGHT_VARIABLES));
|
|
3014
|
-
const PUBLIC_VARIABLE_REFERENCE = /var\(\s*--([A-Za-z][A-Za-z0-9]*)\s*\)/g;
|
|
3015
|
-
function resolveCardFieldAppearance(appearance) {
|
|
3016
|
-
const theme = appearance?.theme ?? 'light';
|
|
3017
|
-
const themeVariables = theme === 'dark' ? DARK_VARIABLES : LIGHT_VARIABLES;
|
|
3018
|
-
const overrides = Object.fromEntries(Object.entries(appearance?.variables ?? {}).filter(([name, value]) => VARIABLE_NAMES.has(name) && typeof value === 'string'));
|
|
3019
|
-
return {
|
|
3020
|
-
theme,
|
|
3021
|
-
disableAnimations: appearance?.disableAnimations ?? false,
|
|
3022
|
-
variables: {
|
|
3023
|
-
...themeVariables,
|
|
3024
|
-
...overrides,
|
|
3025
|
-
},
|
|
3026
|
-
};
|
|
2977
|
+
const DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT = 'paypercut-developer-assistance.iife.min.js';
|
|
2978
|
+
const DEVELOPER_ASSISTANCE_MODULE_ARTIFACT = 'developer-assistance.mjs';
|
|
2979
|
+
const DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC = '[Paypercut Elements] developer_assistance_load_failed: Developer Assistant is unavailable. The SDK and Elements continue to work.';
|
|
2980
|
+
const IIFE_ARTIFACT_PATH = /\/paypercut-checkout(?:-dev)?\.iife\.min\.js$/;
|
|
2981
|
+
// Rollup rewrites import.meta.url for CommonJS and classic-script bundles, so
|
|
2982
|
+
// this remains the URL of the exact core artifact that owns the registration
|
|
2983
|
+
// boundary in every supported format.
|
|
2984
|
+
const coreArtifactUrl = typeof __filename === 'string' ? fileUrlFor(__filename) : (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href));
|
|
2985
|
+
const classicScriptUrl = typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
|
|
2986
|
+
let loadRequested = false;
|
|
2987
|
+
function requestDeveloperAssistance(isInstalled) {
|
|
2988
|
+
if (loadRequested || isInstalled())
|
|
2989
|
+
return;
|
|
2990
|
+
loadRequested = true;
|
|
2991
|
+
if (!canLoadDeveloperAssistance()) {
|
|
2992
|
+
warnDeveloperAssistanceUnavailable();
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
void Promise.resolve()
|
|
2996
|
+
.then(loadDeveloperAssistance)
|
|
2997
|
+
.then(() => {
|
|
2998
|
+
if (!isInstalled())
|
|
2999
|
+
throw new Error();
|
|
3000
|
+
})
|
|
3001
|
+
.catch(warnDeveloperAssistanceUnavailable);
|
|
3027
3002
|
}
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
const rule = appearance?.rules?.[selector];
|
|
3031
|
-
if (!rule)
|
|
3032
|
-
return {};
|
|
3033
|
-
const variables = resolveCardFieldAppearance(appearance).variables;
|
|
3034
|
-
return Object.fromEntries(Object.entries(rule).flatMap(([property, value]) => {
|
|
3035
|
-
if (typeof value !== 'string' || !isSafeElementsAppearanceValue(value))
|
|
3036
|
-
return [];
|
|
3037
|
-
return [
|
|
3038
|
-
[
|
|
3039
|
-
property,
|
|
3040
|
-
value.replace(PUBLIC_VARIABLE_REFERENCE, (match, name) => name in variables ? variables[name] : match),
|
|
3041
|
-
],
|
|
3042
|
-
];
|
|
3043
|
-
}));
|
|
3003
|
+
function warnDeveloperAssistanceUnavailable() {
|
|
3004
|
+
console.warn(DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC);
|
|
3044
3005
|
}
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
const
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
const
|
|
3059
|
-
|
|
3060
|
-
|
|
3006
|
+
function canLoadDeveloperAssistance() {
|
|
3007
|
+
return (typeof document !== 'undefined' &&
|
|
3008
|
+
typeof document.createElement === 'function' &&
|
|
3009
|
+
Boolean(document.head || document.documentElement));
|
|
3010
|
+
}
|
|
3011
|
+
function loadDeveloperAssistance() {
|
|
3012
|
+
if (classicScriptUrl || isClassicScriptArtifact(coreArtifactUrl)) {
|
|
3013
|
+
return loadClassicScript(resolveBrowserArtifactUrl(coreArtifactUrl));
|
|
3014
|
+
}
|
|
3015
|
+
const moduleUrl = new URL(DEVELOPER_ASSISTANCE_MODULE_ARTIFACT, coreArtifactUrl).href;
|
|
3016
|
+
return import(/* @vite-ignore */ moduleUrl);
|
|
3017
|
+
}
|
|
3018
|
+
function fileUrlFor(filename) {
|
|
3019
|
+
const normalized = filename.replace(/\\/g, '/');
|
|
3020
|
+
return new URL(`file://${normalized.startsWith('/') ? '' : '/'}${normalized}`).href;
|
|
3021
|
+
}
|
|
3022
|
+
function resolveBrowserArtifactUrl(coreUrl) {
|
|
3023
|
+
const url = new URL(coreUrl);
|
|
3024
|
+
if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
|
|
3025
|
+
const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
|
|
3026
|
+
artifactUrl.search = url.search;
|
|
3027
|
+
artifactUrl.hash = '';
|
|
3028
|
+
return artifactUrl.href;
|
|
3029
|
+
}
|
|
3030
|
+
if (/\.js$/.test(url.pathname)) {
|
|
3031
|
+
url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
|
|
3032
|
+
}
|
|
3033
|
+
else if (/\/cdn\/?$/.test(url.pathname)) {
|
|
3034
|
+
url.pathname = url.pathname.replace(/\/cdn\/?$/, `/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`);
|
|
3035
|
+
}
|
|
3036
|
+
else {
|
|
3037
|
+
url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
|
|
3038
|
+
}
|
|
3039
|
+
url.hash = '';
|
|
3040
|
+
return url.href;
|
|
3041
|
+
}
|
|
3042
|
+
function isClassicScriptArtifact(url) {
|
|
3043
|
+
try {
|
|
3044
|
+
return IIFE_ARTIFACT_PATH.test(new URL(url).pathname);
|
|
3045
|
+
}
|
|
3046
|
+
catch {
|
|
3047
|
+
return false;
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
function loadClassicScript(src) {
|
|
3051
|
+
return new Promise((resolve, reject) => {
|
|
3052
|
+
const script = document.createElement('script');
|
|
3053
|
+
script.async = true;
|
|
3054
|
+
script.src = src;
|
|
3055
|
+
script.addEventListener('load', () => resolve(), { once: true });
|
|
3056
|
+
script.addEventListener('error', () => reject(new Error()), { once: true });
|
|
3057
|
+
(document.head || document.documentElement).appendChild(script);
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
const registryKey = Symbol.for('paypercut.checkout-js.developer-assistance');
|
|
3062
|
+
function getRegistry() {
|
|
3063
|
+
const globals = globalThis;
|
|
3064
|
+
globals[registryKey] ?? (globals[registryKey] = {
|
|
3065
|
+
coreVersions: new Set(),
|
|
3066
|
+
provider: null,
|
|
3067
|
+
registrations: new Set(),
|
|
3068
|
+
});
|
|
3069
|
+
return globals[registryKey];
|
|
3070
|
+
}
|
|
3071
|
+
function announceDeveloperAssistantCore() {
|
|
3072
|
+
const registry = getRegistry();
|
|
3073
|
+
if (registry.provider && registry.provider.version !== SDK_VERSION) {
|
|
3074
|
+
for (const entry of registry.registrations) {
|
|
3075
|
+
safelyUnregister(entry);
|
|
3076
|
+
}
|
|
3077
|
+
registry.provider = null;
|
|
3078
|
+
}
|
|
3079
|
+
registry.coreVersions.add(SDK_VERSION);
|
|
3080
|
+
}
|
|
3081
|
+
function safelyUnregister(entry) {
|
|
3082
|
+
try {
|
|
3083
|
+
entry.delegate?.unregister();
|
|
3084
|
+
}
|
|
3085
|
+
catch {
|
|
3086
|
+
// Developer Assistance is optional and must not interrupt owner teardown.
|
|
3087
|
+
}
|
|
3088
|
+
entry.delegate = null;
|
|
3089
|
+
}
|
|
3090
|
+
function safelyAttach(entry, provider) {
|
|
3091
|
+
if (!entry.registered || entry.delegate)
|
|
3092
|
+
return;
|
|
3093
|
+
try {
|
|
3094
|
+
entry.delegate = provider.register(entry.target);
|
|
3095
|
+
}
|
|
3096
|
+
catch {
|
|
3097
|
+
// A target can register before its hosted component is ready. Keep the
|
|
3098
|
+
// provider available for the other targets and retry this one on refresh.
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
function isTargetVisible(entry) {
|
|
3102
|
+
try {
|
|
3103
|
+
return entry.target.isVisible?.() ?? true;
|
|
3104
|
+
}
|
|
3105
|
+
catch {
|
|
3106
|
+
// Developer Assistance is optional. A stale owner node must never make the
|
|
3107
|
+
// merchant page fail while its visibility is being reconciled.
|
|
3108
|
+
return false;
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
function syncAttachment(entry, registry) {
|
|
3112
|
+
if (!entry.registered)
|
|
3113
|
+
return;
|
|
3114
|
+
if (!isTargetVisible(entry)) {
|
|
3115
|
+
safelyUnregister(entry);
|
|
3116
|
+
return;
|
|
3117
|
+
}
|
|
3118
|
+
if (registry.provider?.version === SDK_VERSION) {
|
|
3119
|
+
safelyAttach(entry, registry.provider);
|
|
3120
|
+
return;
|
|
3121
|
+
}
|
|
3122
|
+
requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
|
|
3123
|
+
}
|
|
3124
|
+
let visibilityObserver = null;
|
|
3125
|
+
function observeTargetVisibility(registry) {
|
|
3126
|
+
if (visibilityObserver ||
|
|
3127
|
+
typeof MutationObserver === 'undefined' ||
|
|
3128
|
+
typeof document === 'undefined' ||
|
|
3129
|
+
!document.documentElement) {
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
visibilityObserver = new MutationObserver(() => {
|
|
3133
|
+
for (const entry of registry.registrations)
|
|
3134
|
+
syncAttachment(entry, registry);
|
|
3135
|
+
});
|
|
3136
|
+
visibilityObserver.observe(document.documentElement, {
|
|
3137
|
+
attributes: true,
|
|
3138
|
+
attributeFilter: ['aria-hidden', 'class', 'hidden', 'style'],
|
|
3139
|
+
childList: true,
|
|
3140
|
+
subtree: true,
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
function stopObservingTargetVisibilityIfIdle(registry) {
|
|
3144
|
+
if (registry.registrations.size > 0)
|
|
3145
|
+
return;
|
|
3146
|
+
visibilityObserver?.disconnect();
|
|
3147
|
+
visibilityObserver = null;
|
|
3148
|
+
}
|
|
3149
|
+
function hasAttachedDeveloperAssistant(registry) {
|
|
3150
|
+
if (registry.provider?.version !== SDK_VERSION)
|
|
3151
|
+
return false;
|
|
3152
|
+
return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
|
|
3153
|
+
}
|
|
3154
|
+
function registerDeveloperAssistantTarget(target) {
|
|
3155
|
+
const registry = getRegistry();
|
|
3156
|
+
announceDeveloperAssistantCore();
|
|
3157
|
+
const entry = { target, delegate: null, registered: true };
|
|
3158
|
+
registry.registrations.add(entry);
|
|
3159
|
+
observeTargetVisibility(registry);
|
|
3160
|
+
syncAttachment(entry, registry);
|
|
3061
3161
|
return {
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
color: inputColor,
|
|
3070
|
-
fontFamily: variables.fontFamily,
|
|
3071
|
-
fontSize: variables.fontSizeBase,
|
|
3072
|
-
fontWeight: variables.fontWeightNormal,
|
|
3073
|
-
lineHeight: variables.lineHeight,
|
|
3074
|
-
// The provider is clipped to its own physical region when card brands
|
|
3075
|
-
// are visible. Keep ordinary input padding here so provider- or
|
|
3076
|
-
// extension-owned controls can use that region's far-right edge.
|
|
3077
|
-
padding: !presentation
|
|
3078
|
-
? '12px'
|
|
3079
|
-
: presentation.floatingLabels
|
|
3080
|
-
? presentation.floatingLabelActive
|
|
3081
|
-
? '23px 12px 9px 12px'
|
|
3082
|
-
: '16px 12px 16px 12px'
|
|
3083
|
-
: '12px',
|
|
3084
|
-
'::placeholder': {
|
|
3085
|
-
color: variables.colorTextPlaceholder,
|
|
3086
|
-
},
|
|
3087
|
-
':disabled': {
|
|
3088
|
-
backgroundColor: inputBackgroundColor,
|
|
3089
|
-
},
|
|
3090
|
-
...inputRule,
|
|
3091
|
-
},
|
|
3092
|
-
empty: {
|
|
3093
|
-
// Chrome on iOS injects a later `[chrome-autofilled]` rule with an
|
|
3094
|
-
// !important blue background inside each secure provider iframe. Basis
|
|
3095
|
-
// Theory v2 filters custom attribute selectors, but its empty/invalid/
|
|
3096
|
-
// complete state rules are deliberately class-qualified three times.
|
|
3097
|
-
// On CriOS only, matching importance lets those supported state rules
|
|
3098
|
-
// outrank Chrome without disabling native saved-card autofill.
|
|
3099
|
-
backgroundColor: providerStateValue(inputBackgroundColor),
|
|
3100
|
-
color: providerStateValue(inputColor),
|
|
3162
|
+
unregister() {
|
|
3163
|
+
if (!entry.registered)
|
|
3164
|
+
return;
|
|
3165
|
+
entry.registered = false;
|
|
3166
|
+
registry.registrations.delete(entry);
|
|
3167
|
+
safelyUnregister(entry);
|
|
3168
|
+
stopObservingTargetVisibilityIfIdle(registry);
|
|
3101
3169
|
},
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
color: providerStateValue(invalidColor),
|
|
3170
|
+
refresh() {
|
|
3171
|
+
if (!entry.registered)
|
|
3172
|
+
return;
|
|
3173
|
+
syncAttachment(entry, registry);
|
|
3174
|
+
entry.delegate?.refresh();
|
|
3108
3175
|
},
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3176
|
+
collapse() {
|
|
3177
|
+
if (entry.registered)
|
|
3178
|
+
entry.delegate?.collapse();
|
|
3112
3179
|
},
|
|
3113
3180
|
};
|
|
3114
3181
|
}
|
|
3115
3182
|
|
|
3183
|
+
function isElementVisible(element) {
|
|
3184
|
+
if (!element?.isConnected)
|
|
3185
|
+
return false;
|
|
3186
|
+
for (let current = element; current; current = current.parentElement) {
|
|
3187
|
+
if (current.hidden ||
|
|
3188
|
+
current.inert ||
|
|
3189
|
+
current.getAttribute('aria-hidden') === 'true') {
|
|
3190
|
+
return false;
|
|
3191
|
+
}
|
|
3192
|
+
const style = current.ownerDocument.defaultView?.getComputedStyle(current);
|
|
3193
|
+
if (style?.display === 'none' ||
|
|
3194
|
+
style?.visibility === 'hidden' ||
|
|
3195
|
+
style?.visibility === 'collapse' ||
|
|
3196
|
+
style?.contentVisibility === 'hidden') {
|
|
3197
|
+
return false;
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
return true;
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3116
3203
|
const FRAME_URL_LENGTH_WARNING_THRESHOLD = 4096;
|
|
3117
3204
|
let hasWarnedAboutLongFrameUrl = false;
|
|
3118
3205
|
const ELEMENTS_FRAME_NAVIGATION_QUERY = '__paypercut_navigation';
|
|
@@ -4854,12 +4941,41 @@ class CardElementImpl {
|
|
|
4854
4941
|
pending.resolve();
|
|
4855
4942
|
}
|
|
4856
4943
|
registerDeveloperPresets(presets) {
|
|
4857
|
-
{
|
|
4858
|
-
return;
|
|
4859
|
-
}
|
|
4944
|
+
if (this.group.getClientOptions().developerAssistant !== true) {
|
|
4945
|
+
return;
|
|
4946
|
+
}
|
|
4947
|
+
if (this.developerAssistant) {
|
|
4948
|
+
// Hosted Card republishes the same authorized catalog after an Appearance
|
|
4949
|
+
// replacement. Keep the existing target and controls alive so the pending
|
|
4950
|
+
// request can release its lock and restore focus on the original control.
|
|
4951
|
+
this.developerAssistant.refresh();
|
|
4952
|
+
return;
|
|
4953
|
+
}
|
|
4954
|
+
this.developerAssistant = registerDeveloperAssistantTarget({
|
|
4955
|
+
id: `${this.group.controllerId}:${this.componentId}`,
|
|
4956
|
+
configurationIdentity: this.group.configurationIdentity,
|
|
4957
|
+
appearanceScopeId: this.group.controllerId,
|
|
4958
|
+
presets,
|
|
4959
|
+
isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
|
|
4960
|
+
isAvailable: () => this.canApplyDeveloperPreset(),
|
|
4961
|
+
isAppearanceAvailable: () => this.isMounted(),
|
|
4962
|
+
appearancePreviewClearsTestData: () => true,
|
|
4963
|
+
canPreview: () => this.group.isAppearancePreviewAvailable(),
|
|
4964
|
+
applyPreset: (presetId) => this.applyDeveloperPreset(presetId),
|
|
4965
|
+
getAppearance: () => this.group.getAppearance(),
|
|
4966
|
+
updateAppearance: (appearance) => this.group.updateAppearance(appearance),
|
|
4967
|
+
replaceAppearance: (appearance) => this.group.replaceAppearance(appearance),
|
|
4968
|
+
prepareAppearance: (appearance) => this.group.prepareAppearance(appearance),
|
|
4969
|
+
prepareAppearanceReplacement: (appearance) => this.group.prepareAppearanceReplacement(appearance),
|
|
4970
|
+
});
|
|
4860
4971
|
}
|
|
4861
4972
|
canApplyDeveloperPreset() {
|
|
4862
|
-
return (
|
|
4973
|
+
return (this.group.getClientOptions().developerAssistant === true &&
|
|
4974
|
+
this.ready &&
|
|
4975
|
+
!this.destroyed &&
|
|
4976
|
+
!this.group.hasPaymentMethodSubmissionState(this.componentId) &&
|
|
4977
|
+
!this.group.hasCompletedPaymentMethodSubmission(this.componentId) &&
|
|
4978
|
+
!this.pendingDeveloperPreset);
|
|
4863
4979
|
}
|
|
4864
4980
|
applyDeveloperPreset(presetId) {
|
|
4865
4981
|
if (!this.canApplyDeveloperPreset()) {
|
|
@@ -5035,6 +5151,100 @@ function patchApplePayModalFocus(modal, attempts = 0) {
|
|
|
5035
5151
|
root.appendChild(style);
|
|
5036
5152
|
}
|
|
5037
5153
|
|
|
5154
|
+
const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
|
|
5155
|
+
closedPollIntervalMs: 250,
|
|
5156
|
+
providerSettlementGraceMs: 3500,
|
|
5157
|
+
};
|
|
5158
|
+
/**
|
|
5159
|
+
* Captures the popup synchronously opened by a provider launch and supplies a
|
|
5160
|
+
* bounded fallback when the provider leaves its result promise pending after
|
|
5161
|
+
* the popup has actually closed.
|
|
5162
|
+
*/
|
|
5163
|
+
const launchWithProviderPopupRecovery = (launch, onAbandoned, host = window) => {
|
|
5164
|
+
const originalOpen = host.open;
|
|
5165
|
+
let capturedPopup = null;
|
|
5166
|
+
let captureInstalled = false;
|
|
5167
|
+
let stopped = false;
|
|
5168
|
+
let pollTimer = null;
|
|
5169
|
+
let settlementTimer = null;
|
|
5170
|
+
const captureOpen = ((url, target, features) => {
|
|
5171
|
+
const popup = originalOpen.call(host, url, target, features);
|
|
5172
|
+
if (!capturedPopup && popup)
|
|
5173
|
+
capturedPopup = popup;
|
|
5174
|
+
return popup;
|
|
5175
|
+
});
|
|
5176
|
+
try {
|
|
5177
|
+
host.open = captureOpen;
|
|
5178
|
+
captureInstalled = host.open === captureOpen;
|
|
5179
|
+
}
|
|
5180
|
+
catch {
|
|
5181
|
+
captureInstalled = false;
|
|
5182
|
+
}
|
|
5183
|
+
let result;
|
|
5184
|
+
try {
|
|
5185
|
+
result = launch();
|
|
5186
|
+
}
|
|
5187
|
+
finally {
|
|
5188
|
+
if (captureInstalled && host.open === captureOpen)
|
|
5189
|
+
host.open = originalOpen;
|
|
5190
|
+
}
|
|
5191
|
+
const stop = () => {
|
|
5192
|
+
if (stopped)
|
|
5193
|
+
return;
|
|
5194
|
+
stopped = true;
|
|
5195
|
+
if (pollTimer !== null)
|
|
5196
|
+
host.clearTimeout(pollTimer);
|
|
5197
|
+
if (settlementTimer !== null)
|
|
5198
|
+
host.clearTimeout(settlementTimer);
|
|
5199
|
+
pollTimer = null;
|
|
5200
|
+
settlementTimer = null;
|
|
5201
|
+
capturedPopup = null;
|
|
5202
|
+
};
|
|
5203
|
+
const merchantDocumentHasFocus = () => {
|
|
5204
|
+
try {
|
|
5205
|
+
return host.document?.hasFocus() ?? true;
|
|
5206
|
+
}
|
|
5207
|
+
catch {
|
|
5208
|
+
return false;
|
|
5209
|
+
}
|
|
5210
|
+
};
|
|
5211
|
+
const poll = () => {
|
|
5212
|
+
if (stopped || !capturedPopup)
|
|
5213
|
+
return;
|
|
5214
|
+
let closed = false;
|
|
5215
|
+
try {
|
|
5216
|
+
closed = capturedPopup.closed;
|
|
5217
|
+
}
|
|
5218
|
+
catch {
|
|
5219
|
+
stop();
|
|
5220
|
+
return;
|
|
5221
|
+
}
|
|
5222
|
+
// Chrome can close Google's short-lived launcher window after handing the
|
|
5223
|
+
// flow to its native payment-handler window. The launcher closing is only
|
|
5224
|
+
// a customer dismissal once focus has returned to the merchant document.
|
|
5225
|
+
if (!closed || !merchantDocumentHasFocus()) {
|
|
5226
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5227
|
+
return;
|
|
5228
|
+
}
|
|
5229
|
+
pollTimer = null;
|
|
5230
|
+
settlementTimer = host.setTimeout(() => {
|
|
5231
|
+
if (stopped)
|
|
5232
|
+
return;
|
|
5233
|
+
settlementTimer = null;
|
|
5234
|
+
if (!merchantDocumentHasFocus()) {
|
|
5235
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5236
|
+
return;
|
|
5237
|
+
}
|
|
5238
|
+
stop();
|
|
5239
|
+
onAbandoned();
|
|
5240
|
+
}, GOOGLE_PAY_POPUP_RECOVERY_POLICY.providerSettlementGraceMs);
|
|
5241
|
+
};
|
|
5242
|
+
if (capturedPopup) {
|
|
5243
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5244
|
+
}
|
|
5245
|
+
return { result, stop };
|
|
5246
|
+
};
|
|
5247
|
+
|
|
5038
5248
|
const MAX_IFRAME_HEIGHT = 4096;
|
|
5039
5249
|
const EXPRESS_PREVIEW_INITIALIZATION_TIMEOUT_MS = 10000;
|
|
5040
5250
|
const WALLET_OVERLAY_FALLBACK_Z_INDEX = '2147483647';
|
|
@@ -5114,6 +5324,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5114
5324
|
this.googlePayEnvironment = null;
|
|
5115
5325
|
this.googlePayRequestId = null;
|
|
5116
5326
|
this.googlePayProcessingRequestId = null;
|
|
5327
|
+
this.googlePayPopupRecovery = null;
|
|
5117
5328
|
this.googlePayUpdates = new Map();
|
|
5118
5329
|
this.googlePayAuthorization = null;
|
|
5119
5330
|
this.googlePayButtonTarget = null;
|
|
@@ -5188,7 +5399,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5188
5399
|
this.group.updateExpressCheckoutComponent(this.componentId, this.componentRevision, this.getComponentOptions());
|
|
5189
5400
|
}
|
|
5190
5401
|
getComponentOptions() {
|
|
5191
|
-
return structuredCloneSafe(this.options);
|
|
5402
|
+
return structuredCloneSafe(this.pendingPreview?.nextOptions ?? this.options);
|
|
5192
5403
|
}
|
|
5193
5404
|
isMounted() {
|
|
5194
5405
|
return this.mounted && !this.destroyed;
|
|
@@ -5233,6 +5444,14 @@ class ExpressCheckoutElementImpl {
|
|
|
5233
5444
|
this.applePaySession !== null ||
|
|
5234
5445
|
this.googlePayRequestId !== null);
|
|
5235
5446
|
}
|
|
5447
|
+
hasActiveProviderSubmission() {
|
|
5448
|
+
const googlePayAwaitingMerchantApproval = this.googlePayRequestId !== null &&
|
|
5449
|
+
this.activeAttempt?.requestId === this.googlePayRequestId &&
|
|
5450
|
+
this.activeAttempt.approved === false;
|
|
5451
|
+
return (this.activeAttempt?.approved === true ||
|
|
5452
|
+
this.applePaySession !== null ||
|
|
5453
|
+
(this.googlePayRequestId !== null && !googlePayAwaitingMerchantApproval));
|
|
5454
|
+
}
|
|
5236
5455
|
handleControllerError(error) {
|
|
5237
5456
|
if (this.destroyed)
|
|
5238
5457
|
return;
|
|
@@ -5630,9 +5849,27 @@ class ExpressCheckoutElementImpl {
|
|
|
5630
5849
|
};
|
|
5631
5850
|
}
|
|
5632
5851
|
registerDeveloperAssistant() {
|
|
5633
|
-
{
|
|
5634
|
-
return;
|
|
5635
|
-
}
|
|
5852
|
+
if (this.group.getClientOptions().developerAssistant !== true) {
|
|
5853
|
+
return;
|
|
5854
|
+
}
|
|
5855
|
+
this.developerAssistant = registerDeveloperAssistantTarget({
|
|
5856
|
+
id: `${this.group.controllerId}:${this.componentId}:express-checkout`,
|
|
5857
|
+
configurationIdentity: this.group.configurationIdentity,
|
|
5858
|
+
appearanceScopeId: this.group.controllerId,
|
|
5859
|
+
componentDisplayScopeId: this.componentId,
|
|
5860
|
+
isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
|
|
5861
|
+
isAvailable: () => true,
|
|
5862
|
+
isAppearanceAvailable: () => this.isMounted(),
|
|
5863
|
+
canPreview: () => this.group.isAppearancePreviewAvailable(),
|
|
5864
|
+
getAppearance: () => this.group.getAppearance(),
|
|
5865
|
+
updateAppearance: (appearance) => this.group.updateAppearance(appearance),
|
|
5866
|
+
replaceAppearance: (appearance) => this.group.replaceAppearance(appearance),
|
|
5867
|
+
prepareAppearance: (appearance) => this.group.prepareAppearance(appearance),
|
|
5868
|
+
prepareAppearanceReplacement: (appearance) => this.group.prepareAppearanceReplacement(appearance),
|
|
5869
|
+
getComponentDisplayOptions: () => developerDisplayOptions(this.options),
|
|
5870
|
+
updateComponentDisplayOptions: (options) => this.updateDeveloperDisplayOptions(options),
|
|
5871
|
+
replaceComponentDisplayOptions: (options) => this.replaceDeveloperDisplayOptions(options),
|
|
5872
|
+
});
|
|
5636
5873
|
}
|
|
5637
5874
|
onWindowMessage(event) {
|
|
5638
5875
|
if (this.destroyed ||
|
|
@@ -5762,7 +5999,9 @@ class ExpressCheckoutElementImpl {
|
|
|
5762
5999
|
const settle = (accepted, options) => {
|
|
5763
6000
|
if (settled || this.destroyed || this.activeAttempt?.requestId !== requestId)
|
|
5764
6001
|
return;
|
|
5765
|
-
const
|
|
6002
|
+
const validatedResolution = accepted ? validateClickResolveOptions(options) : undefined;
|
|
6003
|
+
const { amount, ...checkoutDetails } = validatedResolution ?? {};
|
|
6004
|
+
const validatedOptions = Object.keys(checkoutDetails).length > 0 ? checkoutDetails : undefined;
|
|
5766
6005
|
settled = true;
|
|
5767
6006
|
window.clearTimeout(timeout);
|
|
5768
6007
|
if (accepted && this.activeAttempt?.requestId === requestId) {
|
|
@@ -5772,11 +6011,23 @@ class ExpressCheckoutElementImpl {
|
|
|
5772
6011
|
...(validatedOptions ?? {}),
|
|
5773
6012
|
});
|
|
5774
6013
|
}
|
|
5775
|
-
|
|
6014
|
+
if (amount === undefined) {
|
|
6015
|
+
this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
|
|
6016
|
+
}
|
|
6017
|
+
else {
|
|
6018
|
+
this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions, amount);
|
|
6019
|
+
}
|
|
5776
6020
|
if (!accepted) {
|
|
5777
6021
|
this.group.endWalletAttempt(this.componentId, requestId);
|
|
5778
|
-
|
|
5779
|
-
|
|
6022
|
+
// A top-level Google Pay sheet is already open before the async
|
|
6023
|
+
// merchant click decision returns. Keep the request identity until the
|
|
6024
|
+
// controller's wallet_cancel arrives so integrations receive their
|
|
6025
|
+
// normal cancel lifecycle and can release their own attempt lock.
|
|
6026
|
+
if (wallet !== 'google_pay' ||
|
|
6027
|
+
this.googlePayRequestId !== requestId) {
|
|
6028
|
+
this.activeAttempt = null;
|
|
6029
|
+
this.activeOptions = null;
|
|
6030
|
+
}
|
|
5780
6031
|
}
|
|
5781
6032
|
};
|
|
5782
6033
|
// Woo and other commerce adapters may need to validate their checkout and
|
|
@@ -6139,10 +6390,22 @@ class ExpressCheckoutElementImpl {
|
|
|
6139
6390
|
this.googlePayClient = this.createGooglePayClient(environment, Object.keys(paymentDataCallbacks).length > 0 ? paymentDataCallbacks : undefined);
|
|
6140
6391
|
// Keep the browser launch synchronous with the relayed click. Awaiting
|
|
6141
6392
|
// script or merchant work here loses mobile popup/user-activation state.
|
|
6142
|
-
const
|
|
6393
|
+
const popupRecovery = launchWithProviderPopupRecovery(() => this.googlePayClient.loadPaymentData(request), () => {
|
|
6394
|
+
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6395
|
+
return;
|
|
6396
|
+
try {
|
|
6397
|
+
this.group.sendGooglePayCanceled(this.componentId, requestId);
|
|
6398
|
+
}
|
|
6399
|
+
finally {
|
|
6400
|
+
this.clearGooglePayAttempt(requestId);
|
|
6401
|
+
}
|
|
6402
|
+
});
|
|
6403
|
+
this.googlePayPopupRecovery = popupRecovery;
|
|
6404
|
+
const payment = popupRecovery.result;
|
|
6143
6405
|
void Promise.resolve(payment).then((data) => {
|
|
6144
6406
|
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6145
6407
|
return;
|
|
6408
|
+
this.clearGooglePayPopupRecovery();
|
|
6146
6409
|
// Google has returned control to the merchant document at this
|
|
6147
6410
|
// boundary. Keep blocking duplicate checkout interactions, but stop
|
|
6148
6411
|
// telling the customer that the provider window is still open while
|
|
@@ -6153,13 +6416,17 @@ class ExpressCheckoutElementImpl {
|
|
|
6153
6416
|
}, (error) => {
|
|
6154
6417
|
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6155
6418
|
return;
|
|
6156
|
-
|
|
6157
|
-
|
|
6419
|
+
try {
|
|
6420
|
+
if (isGooglePayCancellation(error)) {
|
|
6421
|
+
this.group.sendGooglePayCanceled(this.componentId, requestId);
|
|
6422
|
+
}
|
|
6423
|
+
else {
|
|
6424
|
+
this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
|
|
6425
|
+
}
|
|
6158
6426
|
}
|
|
6159
|
-
|
|
6160
|
-
this.
|
|
6427
|
+
finally {
|
|
6428
|
+
this.clearGooglePayAttempt(requestId);
|
|
6161
6429
|
}
|
|
6162
|
-
this.clearGooglePayAttempt(requestId);
|
|
6163
6430
|
});
|
|
6164
6431
|
}
|
|
6165
6432
|
catch (error) {
|
|
@@ -6246,6 +6513,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6246
6513
|
clearGooglePayAttempt(requestId) {
|
|
6247
6514
|
if (requestId && this.googlePayRequestId !== requestId)
|
|
6248
6515
|
return;
|
|
6516
|
+
this.clearGooglePayPopupRecovery();
|
|
6249
6517
|
this.googlePayRequestId = null;
|
|
6250
6518
|
this.googlePayProcessingRequestId = null;
|
|
6251
6519
|
for (const pending of this.googlePayUpdates.values()) {
|
|
@@ -6260,6 +6528,10 @@ class ExpressCheckoutElementImpl {
|
|
|
6260
6528
|
}
|
|
6261
6529
|
this.positionGooglePayButton();
|
|
6262
6530
|
}
|
|
6531
|
+
clearGooglePayPopupRecovery() {
|
|
6532
|
+
this.googlePayPopupRecovery?.stop();
|
|
6533
|
+
this.googlePayPopupRecovery = null;
|
|
6534
|
+
}
|
|
6263
6535
|
startApplePay(requestId, request) {
|
|
6264
6536
|
this.abortApplePay();
|
|
6265
6537
|
const ApplePayAPI = window.ApplePaySession;
|
|
@@ -6459,6 +6731,16 @@ const OPTION_KEYS = new Set([
|
|
|
6459
6731
|
'lineItems',
|
|
6460
6732
|
'shippingRates',
|
|
6461
6733
|
]);
|
|
6734
|
+
function developerDisplayOptions(options) {
|
|
6735
|
+
return structuredCloneSafe({
|
|
6736
|
+
...(options.paymentMethods ? { paymentMethods: options.paymentMethods } : {}),
|
|
6737
|
+
...(options.layout ? { layout: options.layout } : {}),
|
|
6738
|
+
...(options.buttonType ? { buttonType: options.buttonType } : {}),
|
|
6739
|
+
...(options.buttonTheme ? { buttonTheme: options.buttonTheme } : {}),
|
|
6740
|
+
...(options.buttonHeight !== undefined ? { buttonHeight: options.buttonHeight } : {}),
|
|
6741
|
+
...(options.buttonRadius !== undefined ? { buttonRadius: options.buttonRadius } : {}),
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6462
6744
|
function mergeDeveloperDisplayOptions(current, update) {
|
|
6463
6745
|
return {
|
|
6464
6746
|
...current,
|
|
@@ -6600,6 +6882,7 @@ function validateClickResolveOptions(options) {
|
|
|
6600
6882
|
if (options === undefined)
|
|
6601
6883
|
return undefined;
|
|
6602
6884
|
const allowed = new Set([
|
|
6885
|
+
'amount',
|
|
6603
6886
|
'lineItems',
|
|
6604
6887
|
'emailRequired',
|
|
6605
6888
|
'phoneNumberRequired',
|
|
@@ -6611,6 +6894,12 @@ function validateClickResolveOptions(options) {
|
|
|
6611
6894
|
if (!isRecord(options) || Object.keys(options).some((key) => !allowed.has(key))) {
|
|
6612
6895
|
throw invalidOptions();
|
|
6613
6896
|
}
|
|
6897
|
+
if (options.amount !== undefined &&
|
|
6898
|
+
(typeof options.amount !== 'number' ||
|
|
6899
|
+
!Number.isSafeInteger(options.amount) ||
|
|
6900
|
+
options.amount < 0)) {
|
|
6901
|
+
throw invalidOptions();
|
|
6902
|
+
}
|
|
6614
6903
|
validateRows(options.lineItems, 'name');
|
|
6615
6904
|
validateRows(options.shippingRates, 'displayName', true);
|
|
6616
6905
|
for (const flag of [
|
|
@@ -6638,7 +6927,7 @@ function validateClickResolveOptions(options) {
|
|
|
6638
6927
|
});
|
|
6639
6928
|
}
|
|
6640
6929
|
function validateElementUpdateOptions(options) {
|
|
6641
|
-
if (!isRecord(options) || Object.keys(options).length === 0) {
|
|
6930
|
+
if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
|
|
6642
6931
|
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
|
|
6643
6932
|
}
|
|
6644
6933
|
return validateClickResolveOptions(options);
|
|
@@ -7329,6 +7618,148 @@ class ElementsWalletAttemptOverlay {
|
|
|
7329
7618
|
}
|
|
7330
7619
|
}
|
|
7331
7620
|
|
|
7621
|
+
const LIGHT_VARIABLES = {
|
|
7622
|
+
colorPrimary: '#0570de',
|
|
7623
|
+
colorPrimaryText: '#ffffff',
|
|
7624
|
+
colorBackground: '#ffffff',
|
|
7625
|
+
colorSurface: '#ffffff',
|
|
7626
|
+
colorText: '#2b2d2f',
|
|
7627
|
+
colorTextSecondary: '#6a6c6f',
|
|
7628
|
+
colorTextPlaceholder: '#737474',
|
|
7629
|
+
colorDanger: '#cc1818',
|
|
7630
|
+
colorSuccess: '#30b130',
|
|
7631
|
+
colorWarning: '#e69e2c',
|
|
7632
|
+
colorBorder: '#d7dde0',
|
|
7633
|
+
colorFocus: '#0570de',
|
|
7634
|
+
colorMuted: '#f2f4f5',
|
|
7635
|
+
fontFamily: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
7636
|
+
fontSizeBase: '16px',
|
|
7637
|
+
fontWeightNormal: '400',
|
|
7638
|
+
fontWeightMedium: '500',
|
|
7639
|
+
lineHeight: '1.5',
|
|
7640
|
+
spacingUnit: '4px',
|
|
7641
|
+
gridColumnSpacing: '12px',
|
|
7642
|
+
gridRowSpacing: '12px',
|
|
7643
|
+
labelSpacing: '6px',
|
|
7644
|
+
borderRadius: '4px',
|
|
7645
|
+
buttonBorderRadius: '4px',
|
|
7646
|
+
buttonExpressCheckoutBorderRadius: '4px',
|
|
7647
|
+
buttonPadding: '12px',
|
|
7648
|
+
};
|
|
7649
|
+
const DARK_VARIABLES = {
|
|
7650
|
+
...LIGHT_VARIABLES,
|
|
7651
|
+
colorBackground: '#15171c',
|
|
7652
|
+
colorSurface: '#1d2027',
|
|
7653
|
+
colorText: '#f3f4f6',
|
|
7654
|
+
colorTextSecondary: '#aeb7c7',
|
|
7655
|
+
colorTextPlaceholder: '#8f99aa',
|
|
7656
|
+
colorBorder: '#3a404b',
|
|
7657
|
+
colorFocus: '#7db7ff',
|
|
7658
|
+
colorMuted: '#252932',
|
|
7659
|
+
};
|
|
7660
|
+
const VARIABLE_NAMES = new Set(Object.keys(LIGHT_VARIABLES));
|
|
7661
|
+
const PUBLIC_VARIABLE_REFERENCE = /var\(\s*--([A-Za-z][A-Za-z0-9]*)\s*\)/g;
|
|
7662
|
+
function resolveCardFieldAppearance(appearance) {
|
|
7663
|
+
const theme = appearance?.theme ?? 'light';
|
|
7664
|
+
const themeVariables = theme === 'dark' ? DARK_VARIABLES : LIGHT_VARIABLES;
|
|
7665
|
+
const overrides = Object.fromEntries(Object.entries(appearance?.variables ?? {}).filter(([name, value]) => VARIABLE_NAMES.has(name) && typeof value === 'string'));
|
|
7666
|
+
return {
|
|
7667
|
+
theme,
|
|
7668
|
+
disableAnimations: appearance?.disableAnimations ?? false,
|
|
7669
|
+
variables: {
|
|
7670
|
+
...themeVariables,
|
|
7671
|
+
...overrides,
|
|
7672
|
+
},
|
|
7673
|
+
};
|
|
7674
|
+
}
|
|
7675
|
+
/** Resolve one semantic public rule to concrete provider/DOM style values. */
|
|
7676
|
+
function resolveCardFieldAppearanceRule(appearance, selector) {
|
|
7677
|
+
const rule = appearance?.rules?.[selector];
|
|
7678
|
+
if (!rule)
|
|
7679
|
+
return {};
|
|
7680
|
+
const variables = resolveCardFieldAppearance(appearance).variables;
|
|
7681
|
+
return Object.fromEntries(Object.entries(rule).flatMap(([property, value]) => {
|
|
7682
|
+
if (typeof value !== 'string' || !isSafeElementsAppearanceValue(value))
|
|
7683
|
+
return [];
|
|
7684
|
+
return [
|
|
7685
|
+
[
|
|
7686
|
+
property,
|
|
7687
|
+
value.replace(PUBLIC_VARIABLE_REFERENCE, (match, name) => name in variables ? variables[name] : match),
|
|
7688
|
+
],
|
|
7689
|
+
];
|
|
7690
|
+
}));
|
|
7691
|
+
}
|
|
7692
|
+
/**
|
|
7693
|
+
* Compile the secure Basis Theory input style from the Hosted Checkout token
|
|
7694
|
+
* baseline. Provider fields cannot inherit merchant-document CSS, so every
|
|
7695
|
+
* public token and variable reference is resolved before crossing the provider
|
|
7696
|
+
* boundary. Physical end-adornment separation is owned by CardFieldSurface.
|
|
7697
|
+
*/
|
|
7698
|
+
function createBasisTheoryCardFieldStyle(appearance, presentation) {
|
|
7699
|
+
const variables = resolveCardFieldAppearance(appearance).variables;
|
|
7700
|
+
const inputRule = resolveCardFieldAppearanceRule(appearance, '.Input');
|
|
7701
|
+
const invalidRule = resolveCardFieldAppearanceRule(appearance, '.Input--invalid');
|
|
7702
|
+
const inputBackgroundColor = inputRule.backgroundColor ?? variables.colorSurface;
|
|
7703
|
+
const inputColor = inputRule.color ?? variables.colorText;
|
|
7704
|
+
const invalidBackgroundColor = invalidRule.backgroundColor ?? inputBackgroundColor;
|
|
7705
|
+
const invalidColor = invalidRule.color ?? inputColor;
|
|
7706
|
+
const chromeIosAttributeAutofill = typeof navigator !== 'undefined' && /\bCriOS\//.test(navigator.userAgent);
|
|
7707
|
+
const providerStateValue = (value) => chromeIosAttributeAutofill ? `${value} !important` : value;
|
|
7708
|
+
return {
|
|
7709
|
+
base: {
|
|
7710
|
+
// Basis Theory v2 derives its high-specificity browser-autofill paint
|
|
7711
|
+
// from the active state's color and backgroundColor. An explicitly
|
|
7712
|
+
// opaque surface prevents Chrome/WebKit's native blue fill from showing
|
|
7713
|
+
// through only the provider iframe while the SDK-owned badge lane keeps
|
|
7714
|
+
// the configured surface color.
|
|
7715
|
+
backgroundColor: inputBackgroundColor,
|
|
7716
|
+
color: inputColor,
|
|
7717
|
+
fontFamily: variables.fontFamily,
|
|
7718
|
+
fontSize: variables.fontSizeBase,
|
|
7719
|
+
fontWeight: variables.fontWeightNormal,
|
|
7720
|
+
lineHeight: variables.lineHeight,
|
|
7721
|
+
// The provider is clipped to its own physical region when card brands
|
|
7722
|
+
// are visible. Keep ordinary input padding here so provider- or
|
|
7723
|
+
// extension-owned controls can use that region's far-right edge.
|
|
7724
|
+
padding: !presentation
|
|
7725
|
+
? '12px'
|
|
7726
|
+
: presentation.floatingLabels
|
|
7727
|
+
? presentation.floatingLabelActive
|
|
7728
|
+
? '23px 12px 9px 12px'
|
|
7729
|
+
: '16px 12px 16px 12px'
|
|
7730
|
+
: '12px',
|
|
7731
|
+
'::placeholder': {
|
|
7732
|
+
color: variables.colorTextPlaceholder,
|
|
7733
|
+
},
|
|
7734
|
+
':disabled': {
|
|
7735
|
+
backgroundColor: inputBackgroundColor,
|
|
7736
|
+
},
|
|
7737
|
+
...inputRule,
|
|
7738
|
+
},
|
|
7739
|
+
empty: {
|
|
7740
|
+
// Chrome on iOS injects a later `[chrome-autofilled]` rule with an
|
|
7741
|
+
// !important blue background inside each secure provider iframe. Basis
|
|
7742
|
+
// Theory v2 filters custom attribute selectors, but its empty/invalid/
|
|
7743
|
+
// complete state rules are deliberately class-qualified three times.
|
|
7744
|
+
// On CriOS only, matching importance lets those supported state rules
|
|
7745
|
+
// outrank Chrome without disabling native saved-card autofill.
|
|
7746
|
+
backgroundColor: providerStateValue(inputBackgroundColor),
|
|
7747
|
+
color: providerStateValue(inputColor),
|
|
7748
|
+
},
|
|
7749
|
+
invalid: {
|
|
7750
|
+
// Paypercut owns the visible validation treatment. Provider text remains
|
|
7751
|
+
// neutral while incomplete input is being edited.
|
|
7752
|
+
...invalidRule,
|
|
7753
|
+
backgroundColor: providerStateValue(invalidBackgroundColor),
|
|
7754
|
+
color: providerStateValue(invalidColor),
|
|
7755
|
+
},
|
|
7756
|
+
complete: {
|
|
7757
|
+
backgroundColor: providerStateValue(inputBackgroundColor),
|
|
7758
|
+
color: providerStateValue(inputColor),
|
|
7759
|
+
},
|
|
7760
|
+
};
|
|
7761
|
+
}
|
|
7762
|
+
|
|
7332
7763
|
const CARD_BRAND_BADGE_WIDTH_PX = 48;
|
|
7333
7764
|
const CARD_BRAND_BADGE_HEIGHT_PX = 28;
|
|
7334
7765
|
const INVALID_CARD_BADGE_WIDTH_PX = 36;
|
|
@@ -8059,6 +8490,9 @@ class CardFieldElementImpl {
|
|
|
8059
8490
|
isMounted() {
|
|
8060
8491
|
return this.mounted && !this.destroyed;
|
|
8061
8492
|
}
|
|
8493
|
+
isVisible() {
|
|
8494
|
+
return isElementVisible(this.surface?.root ?? null);
|
|
8495
|
+
}
|
|
8062
8496
|
destroy() {
|
|
8063
8497
|
if (this.destroyed)
|
|
8064
8498
|
return;
|
|
@@ -10397,7 +10831,7 @@ class CardCollectionRuntime {
|
|
|
10397
10831
|
this.cancelPendingAppearancePreview(error);
|
|
10398
10832
|
}
|
|
10399
10833
|
supportsDeveloperPresets() {
|
|
10400
|
-
return
|
|
10834
|
+
return this.bootstrap?.livemode === false;
|
|
10401
10835
|
}
|
|
10402
10836
|
announceAppearanceCommit() {
|
|
10403
10837
|
if (this.destroyed)
|
|
@@ -11099,9 +11533,6 @@ class ElementsGroupImpl {
|
|
|
11099
11533
|
return element;
|
|
11100
11534
|
}
|
|
11101
11535
|
if (type === 'expressCheckout') {
|
|
11102
|
-
if (this.elementsOptions.mode !== 'payment') {
|
|
11103
|
-
throw createElementsError('elements_component_configuration_invalid', 'Express Checkout is currently supported only in payment mode.', false);
|
|
11104
|
-
}
|
|
11105
11536
|
const element = new ExpressCheckoutElementImpl(this, options);
|
|
11106
11537
|
this.elements.set(element.componentId, element);
|
|
11107
11538
|
return element;
|
|
@@ -11548,7 +11979,9 @@ class ElementsGroupImpl {
|
|
|
11548
11979
|
};
|
|
11549
11980
|
this.postControl(control);
|
|
11550
11981
|
}
|
|
11551
|
-
resolveWalletClick(componentId, requestId, accepted, options) {
|
|
11982
|
+
resolveWalletClick(componentId, requestId, accepted, options, amount) {
|
|
11983
|
+
if (accepted && amount !== undefined)
|
|
11984
|
+
this.commitAmountUpdate(amount);
|
|
11552
11985
|
const snapshot = this.getUpdateSnapshot().options;
|
|
11553
11986
|
const message = {
|
|
11554
11987
|
channel: ELEMENTS_COMPONENT_CHANNEL,
|
|
@@ -11617,7 +12050,16 @@ class ElementsGroupImpl {
|
|
|
11617
12050
|
this.postControl(message);
|
|
11618
12051
|
}
|
|
11619
12052
|
discoverDeveloperPresets(componentId) {
|
|
11620
|
-
|
|
12053
|
+
if (this.clientOptions.developerAssistant !== true)
|
|
12054
|
+
return;
|
|
12055
|
+
const message = {
|
|
12056
|
+
channel: ELEMENTS_COMPONENT_CHANNEL,
|
|
12057
|
+
type: ElementsControllerCommandType.DiscoverDeveloperPresets,
|
|
12058
|
+
controllerId: this.controllerId,
|
|
12059
|
+
componentId,
|
|
12060
|
+
componentType: 'card',
|
|
12061
|
+
};
|
|
12062
|
+
this.postControl(message);
|
|
11621
12063
|
}
|
|
11622
12064
|
applyDeveloperPreset(componentId, requestId, presetId) {
|
|
11623
12065
|
const message = {
|
|
@@ -11758,18 +12200,22 @@ class ElementsGroupImpl {
|
|
|
11758
12200
|
if (this.destroyed) {
|
|
11759
12201
|
throw new Error('[Paypercut Elements] Cannot update a destroyed group.');
|
|
11760
12202
|
}
|
|
12203
|
+
const activeElementSubmission = Array.from(this.elements.values()).some((element) => element.hasActiveSubmission());
|
|
12204
|
+
const activeProviderSubmission = Array.from(this.elements.values()).some((element) => element.componentType === 'express_checkout'
|
|
12205
|
+
? element.hasActiveProviderSubmission()
|
|
12206
|
+
: element.hasActiveSubmission());
|
|
11761
12207
|
if (this.pendingValidation !== null ||
|
|
11762
12208
|
this.paymentMethodSubmission.hasActiveSubmission() ||
|
|
11763
|
-
|
|
12209
|
+
(options.appearance !== undefined ? activeElementSubmission : activeProviderSubmission)) {
|
|
11764
12210
|
if (options.appearance !== undefined) {
|
|
11765
12211
|
throw new AppearancePreviewError('elements_appearance_preview_refused', 'Appearance Preview is unavailable while payment validation, Card authentication, or a wallet attempt is active.');
|
|
11766
12212
|
}
|
|
11767
|
-
throw
|
|
12213
|
+
throw createElementsError('elements_submission_in_progress', '[Paypercut Elements] Cannot update Elements while payment details are being submitted.', true);
|
|
11768
12214
|
}
|
|
11769
12215
|
const update = normalizeUpdateOptions(options, this.appearance, this.amount);
|
|
11770
12216
|
const appearanceWasRequested = options.appearance !== undefined;
|
|
11771
12217
|
const appearancePreviewEnabled = this.elementsOptions.appearanceUpdates === 'remount' ||
|
|
11772
|
-
|
|
12218
|
+
this.clientOptions.developerAssistant === true;
|
|
11773
12219
|
const hasMountedPaymentAppearanceTarget = this.hasMountedCardFields() ||
|
|
11774
12220
|
this.getMountedCardElements().length > 0 ||
|
|
11775
12221
|
this.getMountedExpressCheckoutElements().length > 0;
|
|
@@ -11789,6 +12235,10 @@ class ElementsGroupImpl {
|
|
|
11789
12235
|
if (update.amount === this.amount && !appearanceChanged) {
|
|
11790
12236
|
return Promise.resolve();
|
|
11791
12237
|
}
|
|
12238
|
+
if (!appearanceChanged) {
|
|
12239
|
+
this.commitAmountUpdate(update.amount);
|
|
12240
|
+
return Promise.resolve();
|
|
12241
|
+
}
|
|
11792
12242
|
if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
|
|
11793
12243
|
throw new Error('[Paypercut Elements] The update revision limit has been reached.');
|
|
11794
12244
|
}
|
|
@@ -11820,6 +12270,26 @@ class ElementsGroupImpl {
|
|
|
11820
12270
|
this.postControl(message);
|
|
11821
12271
|
return Promise.resolve();
|
|
11822
12272
|
}
|
|
12273
|
+
commitAmountUpdate(amount) {
|
|
12274
|
+
if (amount === this.amount)
|
|
12275
|
+
return;
|
|
12276
|
+
if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
|
|
12277
|
+
throw new Error('[Paypercut Elements] The update revision limit has been reached.');
|
|
12278
|
+
}
|
|
12279
|
+
this.amount = amount;
|
|
12280
|
+
this.invalidateSubmissionValidation();
|
|
12281
|
+
this.updateRevision += 1;
|
|
12282
|
+
if (!this.controllerInitialized)
|
|
12283
|
+
return;
|
|
12284
|
+
const snapshot = this.getUpdateSnapshot();
|
|
12285
|
+
this.postControl({
|
|
12286
|
+
channel: ELEMENTS_COMPONENT_CHANNEL,
|
|
12287
|
+
type: ElementsControllerCommandType.UpdateOptions,
|
|
12288
|
+
controllerId: this.controllerId,
|
|
12289
|
+
updateRevision: snapshot.updateRevision,
|
|
12290
|
+
options: snapshot.options,
|
|
12291
|
+
});
|
|
12292
|
+
}
|
|
11823
12293
|
startAppearancePreview(appearance, deferCommit = false) {
|
|
11824
12294
|
const generation = ++this.appearancePreviewGeneration;
|
|
11825
12295
|
const previous = cloneElementsAppearance(this.appearance);
|
|
@@ -11981,6 +12451,9 @@ class ElementsGroupImpl {
|
|
|
11981
12451
|
hasMountedCardFields() {
|
|
11982
12452
|
return Array.from(this.cardFields.values()).some((field) => field.isMounted());
|
|
11983
12453
|
}
|
|
12454
|
+
hasVisibleCardFields() {
|
|
12455
|
+
return Array.from(this.cardFields.values()).some((field) => field.isVisible());
|
|
12456
|
+
}
|
|
11984
12457
|
warnAppearancePreview(error) {
|
|
11985
12458
|
if (error.code === 'elements_appearance_preview_superseded')
|
|
11986
12459
|
return;
|
|
@@ -12065,9 +12538,30 @@ class ElementsGroupImpl {
|
|
|
12065
12538
|
}
|
|
12066
12539
|
ensureSplitCardDeveloperAssistant() {
|
|
12067
12540
|
if (this.splitCardDeveloperAssistant ||
|
|
12068
|
-
|
|
12069
|
-
|
|
12070
|
-
|
|
12541
|
+
this.clientOptions.developerAssistant !== true ||
|
|
12542
|
+
this.cardFields.size === 0 ||
|
|
12543
|
+
!this.cardCollectionRuntime.supportsDeveloperPresets() ||
|
|
12544
|
+
typeof window === 'undefined' ||
|
|
12545
|
+
typeof document === 'undefined') {
|
|
12546
|
+
return;
|
|
12547
|
+
}
|
|
12548
|
+
this.splitCardDeveloperAssistant = registerDeveloperAssistantTarget({
|
|
12549
|
+
id: `${this.controllerId}:split-card-fields`,
|
|
12550
|
+
configurationIdentity: this.configurationIdentity,
|
|
12551
|
+
appearanceScopeId: this.controllerId,
|
|
12552
|
+
presetSource: 'split-card',
|
|
12553
|
+
isVisible: () => !this.destroyed && this.hasVisibleCardFields(),
|
|
12554
|
+
isAvailable: () => !this.destroyed && this.cardCollectionRuntime.canApplyDeveloperPreset(),
|
|
12555
|
+
isAppearanceAvailable: () => !this.destroyed && this.hasMountedCardFields(),
|
|
12556
|
+
appearancePreviewClearsTestData: () => true,
|
|
12557
|
+
canPreview: () => this.isAppearancePreviewAvailable(),
|
|
12558
|
+
applyCardValue: (value) => this.cardCollectionRuntime.applyDeveloperPreset(value),
|
|
12559
|
+
getAppearance: () => this.getAppearance(),
|
|
12560
|
+
updateAppearance: (appearance) => this.updateAppearance(appearance),
|
|
12561
|
+
replaceAppearance: (appearance) => this.replaceAppearance(appearance),
|
|
12562
|
+
prepareAppearance: (appearance) => this.prepareAppearance(appearance),
|
|
12563
|
+
prepareAppearanceReplacement: (appearance) => this.prepareAppearanceReplacement(appearance),
|
|
12564
|
+
});
|
|
12071
12565
|
}
|
|
12072
12566
|
unregisterSplitCardDeveloperAssistant() {
|
|
12073
12567
|
this.splitCardDeveloperAssistant?.unregister();
|
|
@@ -12739,6 +13233,7 @@ class PaymentConfirmationCoordinator {
|
|
|
12739
13233
|
}
|
|
12740
13234
|
}
|
|
12741
13235
|
|
|
13236
|
+
announceDeveloperAssistantCore();
|
|
12742
13237
|
const MAX_PAYMENT_METHOD_BILLING_CACHE_SIZE = 16;
|
|
12743
13238
|
const MAX_PUBLISHABLE_KEY_LENGTH = 512;
|
|
12744
13239
|
const MAX_CREATE_PAYMENT_METHOD_OPTION_KEYS = 2;
|