@paypercut/checkout-js 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -1
- package/dist/developer-assistance.cjs +119 -18
- package/dist/developer-assistance.cjs.map +1 -1
- package/dist/developer-assistance.mjs +119 -18
- package/dist/developer-assistance.mjs.map +1 -1
- package/dist/index.cjs +318 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -9
- package/dist/index.d.mts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.mjs +318 -36
- 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 +1 -1
- package/dist/paypercut-developer-assistance.iife.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -100,7 +100,7 @@ class Emitter {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const SDK_VERSION = "1.4.
|
|
103
|
+
const SDK_VERSION = "1.4.2";
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Build-time configuration
|
|
@@ -892,6 +892,7 @@ class ExpressCheckoutImpl {
|
|
|
892
892
|
merchantMcc: data.merchant?.mcc ?? '',
|
|
893
893
|
merchantCountry: data.merchant?.country ?? '',
|
|
894
894
|
merchantUrl: data.merchant?.business_url ?? '',
|
|
895
|
+
threeDSecure: data.three_d_secure ?? null,
|
|
895
896
|
};
|
|
896
897
|
}
|
|
897
898
|
catch (err) {
|
|
@@ -1564,6 +1565,7 @@ class ExpressCheckoutImpl {
|
|
|
1564
1565
|
country: this.expressConfig?.merchantCountry ?? '',
|
|
1565
1566
|
url: this.expressConfig?.merchantUrl ?? '',
|
|
1566
1567
|
},
|
|
1568
|
+
threeDSecure: this.expressConfig?.threeDSecure ?? null,
|
|
1567
1569
|
});
|
|
1568
1570
|
};
|
|
1569
1571
|
session.oncancel = () => {
|
|
@@ -1879,6 +1881,7 @@ class ExpressCheckoutImpl {
|
|
|
1879
1881
|
country: this.expressConfig?.merchantCountry ?? '',
|
|
1880
1882
|
url: this.expressConfig?.merchantUrl ?? '',
|
|
1881
1883
|
},
|
|
1884
|
+
threeDSecure: this.expressConfig?.threeDSecure ?? null,
|
|
1882
1885
|
});
|
|
1883
1886
|
});
|
|
1884
1887
|
// 3DS was triggered — sheet already closed, payment method creation handled in message handler
|
|
@@ -3017,7 +3020,10 @@ function fileUrlFor(filename) {
|
|
|
3017
3020
|
function resolveBrowserArtifactUrl(coreUrl) {
|
|
3018
3021
|
const url = new URL(coreUrl);
|
|
3019
3022
|
if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
|
|
3020
|
-
|
|
3023
|
+
const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
|
|
3024
|
+
artifactUrl.search = url.search;
|
|
3025
|
+
artifactUrl.hash = '';
|
|
3026
|
+
return artifactUrl.href;
|
|
3021
3027
|
}
|
|
3022
3028
|
if (/\.js$/.test(url.pathname)) {
|
|
3023
3029
|
url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
|
|
@@ -3028,7 +3034,6 @@ function resolveBrowserArtifactUrl(coreUrl) {
|
|
|
3028
3034
|
else {
|
|
3029
3035
|
url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
|
|
3030
3036
|
}
|
|
3031
|
-
url.search = '';
|
|
3032
3037
|
url.hash = '';
|
|
3033
3038
|
return url.href;
|
|
3034
3039
|
}
|
|
@@ -3080,21 +3085,77 @@ function safelyUnregister(entry) {
|
|
|
3080
3085
|
}
|
|
3081
3086
|
entry.delegate = null;
|
|
3082
3087
|
}
|
|
3088
|
+
function safelyAttach(entry, provider) {
|
|
3089
|
+
if (!entry.registered || entry.delegate)
|
|
3090
|
+
return;
|
|
3091
|
+
try {
|
|
3092
|
+
entry.delegate = provider.register(entry.target);
|
|
3093
|
+
}
|
|
3094
|
+
catch {
|
|
3095
|
+
// A target can register before its hosted component is ready. Keep the
|
|
3096
|
+
// provider available for the other targets and retry this one on refresh.
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
function isTargetVisible(entry) {
|
|
3100
|
+
try {
|
|
3101
|
+
return entry.target.isVisible?.() ?? true;
|
|
3102
|
+
}
|
|
3103
|
+
catch {
|
|
3104
|
+
// Developer Assistance is optional. A stale owner node must never make the
|
|
3105
|
+
// merchant page fail while its visibility is being reconciled.
|
|
3106
|
+
return false;
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
function syncAttachment(entry, registry) {
|
|
3110
|
+
if (!entry.registered)
|
|
3111
|
+
return;
|
|
3112
|
+
if (!isTargetVisible(entry)) {
|
|
3113
|
+
safelyUnregister(entry);
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
if (registry.provider?.version === SDK_VERSION) {
|
|
3117
|
+
safelyAttach(entry, registry.provider);
|
|
3118
|
+
return;
|
|
3119
|
+
}
|
|
3120
|
+
requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
|
|
3121
|
+
}
|
|
3122
|
+
let visibilityObserver = null;
|
|
3123
|
+
function observeTargetVisibility(registry) {
|
|
3124
|
+
if (visibilityObserver ||
|
|
3125
|
+
typeof MutationObserver === 'undefined' ||
|
|
3126
|
+
typeof document === 'undefined' ||
|
|
3127
|
+
!document.documentElement) {
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
visibilityObserver = new MutationObserver(() => {
|
|
3131
|
+
for (const entry of registry.registrations)
|
|
3132
|
+
syncAttachment(entry, registry);
|
|
3133
|
+
});
|
|
3134
|
+
visibilityObserver.observe(document.documentElement, {
|
|
3135
|
+
attributes: true,
|
|
3136
|
+
attributeFilter: ['aria-hidden', 'class', 'hidden', 'style'],
|
|
3137
|
+
childList: true,
|
|
3138
|
+
subtree: true,
|
|
3139
|
+
});
|
|
3140
|
+
}
|
|
3141
|
+
function stopObservingTargetVisibilityIfIdle(registry) {
|
|
3142
|
+
if (registry.registrations.size > 0)
|
|
3143
|
+
return;
|
|
3144
|
+
visibilityObserver?.disconnect();
|
|
3145
|
+
visibilityObserver = null;
|
|
3146
|
+
}
|
|
3147
|
+
function hasAttachedDeveloperAssistant(registry) {
|
|
3148
|
+
if (registry.provider?.version !== SDK_VERSION)
|
|
3149
|
+
return false;
|
|
3150
|
+
return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
|
|
3151
|
+
}
|
|
3083
3152
|
function registerDeveloperAssistantTarget(target) {
|
|
3084
3153
|
const registry = getRegistry();
|
|
3085
3154
|
announceDeveloperAssistantCore();
|
|
3086
3155
|
const entry = { target, delegate: null, registered: true };
|
|
3087
3156
|
registry.registrations.add(entry);
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
try {
|
|
3091
|
-
entry.delegate = registry.provider.register(target);
|
|
3092
|
-
}
|
|
3093
|
-
catch {
|
|
3094
|
-
// Developer Assistance is optional. A registration failure must not
|
|
3095
|
-
// interrupt the Element lifecycle or payment flow.
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3157
|
+
observeTargetVisibility(registry);
|
|
3158
|
+
syncAttachment(entry, registry);
|
|
3098
3159
|
return {
|
|
3099
3160
|
unregister() {
|
|
3100
3161
|
if (!entry.registered)
|
|
@@ -3102,10 +3163,13 @@ function registerDeveloperAssistantTarget(target) {
|
|
|
3102
3163
|
entry.registered = false;
|
|
3103
3164
|
registry.registrations.delete(entry);
|
|
3104
3165
|
safelyUnregister(entry);
|
|
3166
|
+
stopObservingTargetVisibilityIfIdle(registry);
|
|
3105
3167
|
},
|
|
3106
3168
|
refresh() {
|
|
3107
|
-
if (entry.registered)
|
|
3108
|
-
|
|
3169
|
+
if (!entry.registered)
|
|
3170
|
+
return;
|
|
3171
|
+
syncAttachment(entry, registry);
|
|
3172
|
+
entry.delegate?.refresh();
|
|
3109
3173
|
},
|
|
3110
3174
|
collapse() {
|
|
3111
3175
|
if (entry.registered)
|
|
@@ -3114,6 +3178,26 @@ function registerDeveloperAssistantTarget(target) {
|
|
|
3114
3178
|
};
|
|
3115
3179
|
}
|
|
3116
3180
|
|
|
3181
|
+
function isElementVisible(element) {
|
|
3182
|
+
if (!element?.isConnected)
|
|
3183
|
+
return false;
|
|
3184
|
+
for (let current = element; current; current = current.parentElement) {
|
|
3185
|
+
if (current.hidden ||
|
|
3186
|
+
current.inert ||
|
|
3187
|
+
current.getAttribute('aria-hidden') === 'true') {
|
|
3188
|
+
return false;
|
|
3189
|
+
}
|
|
3190
|
+
const style = current.ownerDocument.defaultView?.getComputedStyle(current);
|
|
3191
|
+
if (style?.display === 'none' ||
|
|
3192
|
+
style?.visibility === 'hidden' ||
|
|
3193
|
+
style?.visibility === 'collapse' ||
|
|
3194
|
+
style?.contentVisibility === 'hidden') {
|
|
3195
|
+
return false;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
return true;
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3117
3201
|
const FRAME_URL_LENGTH_WARNING_THRESHOLD = 4096;
|
|
3118
3202
|
let hasWarnedAboutLongFrameUrl = false;
|
|
3119
3203
|
const ELEMENTS_FRAME_NAVIGATION_QUERY = '__paypercut_navigation';
|
|
@@ -3183,6 +3267,7 @@ function buildCardElementFrameUrl(input) {
|
|
|
3183
3267
|
function setSharedParams(params, input, includeKeyMode = true) {
|
|
3184
3268
|
params.set('controllerId', input.controllerId);
|
|
3185
3269
|
params.set('apiKey', input.clientOptions.publishableKey);
|
|
3270
|
+
set(params, 'account', input.clientOptions.account);
|
|
3186
3271
|
if (includeKeyMode)
|
|
3187
3272
|
params.set('keyMode', inferKeyMode(input.clientOptions.publishableKey));
|
|
3188
3273
|
params.set('locale', input.elementsOptions.locale || navigatorLocale());
|
|
@@ -4870,6 +4955,7 @@ class CardElementImpl {
|
|
|
4870
4955
|
configurationIdentity: this.group.configurationIdentity,
|
|
4871
4956
|
appearanceScopeId: this.group.controllerId,
|
|
4872
4957
|
presets,
|
|
4958
|
+
isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
|
|
4873
4959
|
isAvailable: () => this.canApplyDeveloperPreset(),
|
|
4874
4960
|
isAppearanceAvailable: () => this.isMounted(),
|
|
4875
4961
|
appearancePreviewClearsTestData: () => true,
|
|
@@ -5064,6 +5150,100 @@ function patchApplePayModalFocus(modal, attempts = 0) {
|
|
|
5064
5150
|
root.appendChild(style);
|
|
5065
5151
|
}
|
|
5066
5152
|
|
|
5153
|
+
const GOOGLE_PAY_POPUP_RECOVERY_POLICY = {
|
|
5154
|
+
closedPollIntervalMs: 250,
|
|
5155
|
+
providerSettlementGraceMs: 3500,
|
|
5156
|
+
};
|
|
5157
|
+
/**
|
|
5158
|
+
* Captures the popup synchronously opened by a provider launch and supplies a
|
|
5159
|
+
* bounded fallback when the provider leaves its result promise pending after
|
|
5160
|
+
* the popup has actually closed.
|
|
5161
|
+
*/
|
|
5162
|
+
const launchWithProviderPopupRecovery = (launch, onAbandoned, host = window) => {
|
|
5163
|
+
const originalOpen = host.open;
|
|
5164
|
+
let capturedPopup = null;
|
|
5165
|
+
let captureInstalled = false;
|
|
5166
|
+
let stopped = false;
|
|
5167
|
+
let pollTimer = null;
|
|
5168
|
+
let settlementTimer = null;
|
|
5169
|
+
const captureOpen = ((url, target, features) => {
|
|
5170
|
+
const popup = originalOpen.call(host, url, target, features);
|
|
5171
|
+
if (!capturedPopup && popup)
|
|
5172
|
+
capturedPopup = popup;
|
|
5173
|
+
return popup;
|
|
5174
|
+
});
|
|
5175
|
+
try {
|
|
5176
|
+
host.open = captureOpen;
|
|
5177
|
+
captureInstalled = host.open === captureOpen;
|
|
5178
|
+
}
|
|
5179
|
+
catch {
|
|
5180
|
+
captureInstalled = false;
|
|
5181
|
+
}
|
|
5182
|
+
let result;
|
|
5183
|
+
try {
|
|
5184
|
+
result = launch();
|
|
5185
|
+
}
|
|
5186
|
+
finally {
|
|
5187
|
+
if (captureInstalled && host.open === captureOpen)
|
|
5188
|
+
host.open = originalOpen;
|
|
5189
|
+
}
|
|
5190
|
+
const stop = () => {
|
|
5191
|
+
if (stopped)
|
|
5192
|
+
return;
|
|
5193
|
+
stopped = true;
|
|
5194
|
+
if (pollTimer !== null)
|
|
5195
|
+
host.clearTimeout(pollTimer);
|
|
5196
|
+
if (settlementTimer !== null)
|
|
5197
|
+
host.clearTimeout(settlementTimer);
|
|
5198
|
+
pollTimer = null;
|
|
5199
|
+
settlementTimer = null;
|
|
5200
|
+
capturedPopup = null;
|
|
5201
|
+
};
|
|
5202
|
+
const merchantDocumentHasFocus = () => {
|
|
5203
|
+
try {
|
|
5204
|
+
return host.document?.hasFocus() ?? true;
|
|
5205
|
+
}
|
|
5206
|
+
catch {
|
|
5207
|
+
return false;
|
|
5208
|
+
}
|
|
5209
|
+
};
|
|
5210
|
+
const poll = () => {
|
|
5211
|
+
if (stopped || !capturedPopup)
|
|
5212
|
+
return;
|
|
5213
|
+
let closed = false;
|
|
5214
|
+
try {
|
|
5215
|
+
closed = capturedPopup.closed;
|
|
5216
|
+
}
|
|
5217
|
+
catch {
|
|
5218
|
+
stop();
|
|
5219
|
+
return;
|
|
5220
|
+
}
|
|
5221
|
+
// Chrome can close Google's short-lived launcher window after handing the
|
|
5222
|
+
// flow to its native payment-handler window. The launcher closing is only
|
|
5223
|
+
// a customer dismissal once focus has returned to the merchant document.
|
|
5224
|
+
if (!closed || !merchantDocumentHasFocus()) {
|
|
5225
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5226
|
+
return;
|
|
5227
|
+
}
|
|
5228
|
+
pollTimer = null;
|
|
5229
|
+
settlementTimer = host.setTimeout(() => {
|
|
5230
|
+
if (stopped)
|
|
5231
|
+
return;
|
|
5232
|
+
settlementTimer = null;
|
|
5233
|
+
if (!merchantDocumentHasFocus()) {
|
|
5234
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5235
|
+
return;
|
|
5236
|
+
}
|
|
5237
|
+
stop();
|
|
5238
|
+
onAbandoned();
|
|
5239
|
+
}, GOOGLE_PAY_POPUP_RECOVERY_POLICY.providerSettlementGraceMs);
|
|
5240
|
+
};
|
|
5241
|
+
if (capturedPopup) {
|
|
5242
|
+
pollTimer = host.setTimeout(poll, GOOGLE_PAY_POPUP_RECOVERY_POLICY.closedPollIntervalMs);
|
|
5243
|
+
}
|
|
5244
|
+
return { result, stop };
|
|
5245
|
+
};
|
|
5246
|
+
|
|
5067
5247
|
const MAX_IFRAME_HEIGHT = 4096;
|
|
5068
5248
|
const EXPRESS_PREVIEW_INITIALIZATION_TIMEOUT_MS = 10000;
|
|
5069
5249
|
const WALLET_OVERLAY_FALLBACK_Z_INDEX = '2147483647';
|
|
@@ -5143,6 +5323,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5143
5323
|
this.googlePayEnvironment = null;
|
|
5144
5324
|
this.googlePayRequestId = null;
|
|
5145
5325
|
this.googlePayProcessingRequestId = null;
|
|
5326
|
+
this.googlePayPopupRecovery = null;
|
|
5146
5327
|
this.googlePayUpdates = new Map();
|
|
5147
5328
|
this.googlePayAuthorization = null;
|
|
5148
5329
|
this.googlePayButtonTarget = null;
|
|
@@ -5262,6 +5443,14 @@ class ExpressCheckoutElementImpl {
|
|
|
5262
5443
|
this.applePaySession !== null ||
|
|
5263
5444
|
this.googlePayRequestId !== null);
|
|
5264
5445
|
}
|
|
5446
|
+
hasActiveProviderSubmission() {
|
|
5447
|
+
const googlePayAwaitingMerchantApproval = this.googlePayRequestId !== null &&
|
|
5448
|
+
this.activeAttempt?.requestId === this.googlePayRequestId &&
|
|
5449
|
+
this.activeAttempt.approved === false;
|
|
5450
|
+
return (this.activeAttempt?.approved === true ||
|
|
5451
|
+
this.applePaySession !== null ||
|
|
5452
|
+
(this.googlePayRequestId !== null && !googlePayAwaitingMerchantApproval));
|
|
5453
|
+
}
|
|
5265
5454
|
handleControllerError(error) {
|
|
5266
5455
|
if (this.destroyed)
|
|
5267
5456
|
return;
|
|
@@ -5667,6 +5856,7 @@ class ExpressCheckoutElementImpl {
|
|
|
5667
5856
|
configurationIdentity: this.group.configurationIdentity,
|
|
5668
5857
|
appearanceScopeId: this.group.controllerId,
|
|
5669
5858
|
componentDisplayScopeId: this.componentId,
|
|
5859
|
+
isVisible: () => isElementVisible(this.iframe?.parentElement ?? null),
|
|
5670
5860
|
isAvailable: () => true,
|
|
5671
5861
|
isAppearanceAvailable: () => this.isMounted(),
|
|
5672
5862
|
canPreview: () => this.group.isAppearancePreviewAvailable(),
|
|
@@ -5808,7 +5998,9 @@ class ExpressCheckoutElementImpl {
|
|
|
5808
5998
|
const settle = (accepted, options) => {
|
|
5809
5999
|
if (settled || this.destroyed || this.activeAttempt?.requestId !== requestId)
|
|
5810
6000
|
return;
|
|
5811
|
-
const
|
|
6001
|
+
const validatedResolution = accepted ? validateClickResolveOptions(options) : undefined;
|
|
6002
|
+
const { amount, ...checkoutDetails } = validatedResolution ?? {};
|
|
6003
|
+
const validatedOptions = Object.keys(checkoutDetails).length > 0 ? checkoutDetails : undefined;
|
|
5812
6004
|
settled = true;
|
|
5813
6005
|
window.clearTimeout(timeout);
|
|
5814
6006
|
if (accepted && this.activeAttempt?.requestId === requestId) {
|
|
@@ -5818,11 +6010,23 @@ class ExpressCheckoutElementImpl {
|
|
|
5818
6010
|
...(validatedOptions ?? {}),
|
|
5819
6011
|
});
|
|
5820
6012
|
}
|
|
5821
|
-
|
|
6013
|
+
if (amount === undefined) {
|
|
6014
|
+
this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions);
|
|
6015
|
+
}
|
|
6016
|
+
else {
|
|
6017
|
+
this.group.resolveWalletClick(this.componentId, requestId, accepted, validatedOptions, amount);
|
|
6018
|
+
}
|
|
5822
6019
|
if (!accepted) {
|
|
5823
6020
|
this.group.endWalletAttempt(this.componentId, requestId);
|
|
5824
|
-
|
|
5825
|
-
|
|
6021
|
+
// A top-level Google Pay sheet is already open before the async
|
|
6022
|
+
// merchant click decision returns. Keep the request identity until the
|
|
6023
|
+
// controller's wallet_cancel arrives so integrations receive their
|
|
6024
|
+
// normal cancel lifecycle and can release their own attempt lock.
|
|
6025
|
+
if (wallet !== 'google_pay' ||
|
|
6026
|
+
this.googlePayRequestId !== requestId) {
|
|
6027
|
+
this.activeAttempt = null;
|
|
6028
|
+
this.activeOptions = null;
|
|
6029
|
+
}
|
|
5826
6030
|
}
|
|
5827
6031
|
};
|
|
5828
6032
|
// Woo and other commerce adapters may need to validate their checkout and
|
|
@@ -6185,10 +6389,22 @@ class ExpressCheckoutElementImpl {
|
|
|
6185
6389
|
this.googlePayClient = this.createGooglePayClient(environment, Object.keys(paymentDataCallbacks).length > 0 ? paymentDataCallbacks : undefined);
|
|
6186
6390
|
// Keep the browser launch synchronous with the relayed click. Awaiting
|
|
6187
6391
|
// script or merchant work here loses mobile popup/user-activation state.
|
|
6188
|
-
const
|
|
6392
|
+
const popupRecovery = launchWithProviderPopupRecovery(() => this.googlePayClient.loadPaymentData(request), () => {
|
|
6393
|
+
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6394
|
+
return;
|
|
6395
|
+
try {
|
|
6396
|
+
this.group.sendGooglePayCanceled(this.componentId, requestId);
|
|
6397
|
+
}
|
|
6398
|
+
finally {
|
|
6399
|
+
this.clearGooglePayAttempt(requestId);
|
|
6400
|
+
}
|
|
6401
|
+
});
|
|
6402
|
+
this.googlePayPopupRecovery = popupRecovery;
|
|
6403
|
+
const payment = popupRecovery.result;
|
|
6189
6404
|
void Promise.resolve(payment).then((data) => {
|
|
6190
6405
|
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6191
6406
|
return;
|
|
6407
|
+
this.clearGooglePayPopupRecovery();
|
|
6192
6408
|
// Google has returned control to the merchant document at this
|
|
6193
6409
|
// boundary. Keep blocking duplicate checkout interactions, but stop
|
|
6194
6410
|
// telling the customer that the provider window is still open while
|
|
@@ -6199,13 +6415,17 @@ class ExpressCheckoutElementImpl {
|
|
|
6199
6415
|
}, (error) => {
|
|
6200
6416
|
if (this.googlePayRequestId !== requestId || this.destroyed)
|
|
6201
6417
|
return;
|
|
6202
|
-
|
|
6203
|
-
|
|
6418
|
+
try {
|
|
6419
|
+
if (isGooglePayCancellation(error)) {
|
|
6420
|
+
this.group.sendGooglePayCanceled(this.componentId, requestId);
|
|
6421
|
+
}
|
|
6422
|
+
else {
|
|
6423
|
+
this.group.sendGooglePayError(this.componentId, requestId, googlePayErrorCode(error), googlePayErrorMessage(error));
|
|
6424
|
+
}
|
|
6204
6425
|
}
|
|
6205
|
-
|
|
6206
|
-
this.
|
|
6426
|
+
finally {
|
|
6427
|
+
this.clearGooglePayAttempt(requestId);
|
|
6207
6428
|
}
|
|
6208
|
-
this.clearGooglePayAttempt(requestId);
|
|
6209
6429
|
});
|
|
6210
6430
|
}
|
|
6211
6431
|
catch (error) {
|
|
@@ -6292,6 +6512,7 @@ class ExpressCheckoutElementImpl {
|
|
|
6292
6512
|
clearGooglePayAttempt(requestId) {
|
|
6293
6513
|
if (requestId && this.googlePayRequestId !== requestId)
|
|
6294
6514
|
return;
|
|
6515
|
+
this.clearGooglePayPopupRecovery();
|
|
6295
6516
|
this.googlePayRequestId = null;
|
|
6296
6517
|
this.googlePayProcessingRequestId = null;
|
|
6297
6518
|
for (const pending of this.googlePayUpdates.values()) {
|
|
@@ -6306,6 +6527,10 @@ class ExpressCheckoutElementImpl {
|
|
|
6306
6527
|
}
|
|
6307
6528
|
this.positionGooglePayButton();
|
|
6308
6529
|
}
|
|
6530
|
+
clearGooglePayPopupRecovery() {
|
|
6531
|
+
this.googlePayPopupRecovery?.stop();
|
|
6532
|
+
this.googlePayPopupRecovery = null;
|
|
6533
|
+
}
|
|
6309
6534
|
startApplePay(requestId, request) {
|
|
6310
6535
|
this.abortApplePay();
|
|
6311
6536
|
const ApplePayAPI = window.ApplePaySession;
|
|
@@ -6656,6 +6881,7 @@ function validateClickResolveOptions(options) {
|
|
|
6656
6881
|
if (options === undefined)
|
|
6657
6882
|
return undefined;
|
|
6658
6883
|
const allowed = new Set([
|
|
6884
|
+
'amount',
|
|
6659
6885
|
'lineItems',
|
|
6660
6886
|
'emailRequired',
|
|
6661
6887
|
'phoneNumberRequired',
|
|
@@ -6667,6 +6893,12 @@ function validateClickResolveOptions(options) {
|
|
|
6667
6893
|
if (!isRecord(options) || Object.keys(options).some((key) => !allowed.has(key))) {
|
|
6668
6894
|
throw invalidOptions();
|
|
6669
6895
|
}
|
|
6896
|
+
if (options.amount !== undefined &&
|
|
6897
|
+
(typeof options.amount !== 'number' ||
|
|
6898
|
+
!Number.isSafeInteger(options.amount) ||
|
|
6899
|
+
options.amount < 0)) {
|
|
6900
|
+
throw invalidOptions();
|
|
6901
|
+
}
|
|
6670
6902
|
validateRows(options.lineItems, 'name');
|
|
6671
6903
|
validateRows(options.shippingRates, 'displayName', true);
|
|
6672
6904
|
for (const flag of [
|
|
@@ -6694,7 +6926,7 @@ function validateClickResolveOptions(options) {
|
|
|
6694
6926
|
});
|
|
6695
6927
|
}
|
|
6696
6928
|
function validateElementUpdateOptions(options) {
|
|
6697
|
-
if (!isRecord(options) || Object.keys(options).length === 0) {
|
|
6929
|
+
if (!isRecord(options) || Object.keys(options).length === 0 || 'amount' in options) {
|
|
6698
6930
|
throw new Error('[Paypercut Elements] Express Checkout update options must contain checkout details.');
|
|
6699
6931
|
}
|
|
6700
6932
|
return validateClickResolveOptions(options);
|
|
@@ -8257,6 +8489,9 @@ class CardFieldElementImpl {
|
|
|
8257
8489
|
isMounted() {
|
|
8258
8490
|
return this.mounted && !this.destroyed;
|
|
8259
8491
|
}
|
|
8492
|
+
isVisible() {
|
|
8493
|
+
return isElementVisible(this.surface?.root ?? null);
|
|
8494
|
+
}
|
|
8260
8495
|
destroy() {
|
|
8261
8496
|
if (this.destroyed)
|
|
8262
8497
|
return;
|
|
@@ -11297,9 +11532,6 @@ class ElementsGroupImpl {
|
|
|
11297
11532
|
return element;
|
|
11298
11533
|
}
|
|
11299
11534
|
if (type === 'expressCheckout') {
|
|
11300
|
-
if (this.elementsOptions.mode !== 'payment') {
|
|
11301
|
-
throw createElementsError('elements_component_configuration_invalid', 'Express Checkout is currently supported only in payment mode.', false);
|
|
11302
|
-
}
|
|
11303
11535
|
const element = new ExpressCheckoutElementImpl(this, options);
|
|
11304
11536
|
this.elements.set(element.componentId, element);
|
|
11305
11537
|
return element;
|
|
@@ -11746,7 +11978,9 @@ class ElementsGroupImpl {
|
|
|
11746
11978
|
};
|
|
11747
11979
|
this.postControl(control);
|
|
11748
11980
|
}
|
|
11749
|
-
resolveWalletClick(componentId, requestId, accepted, options) {
|
|
11981
|
+
resolveWalletClick(componentId, requestId, accepted, options, amount) {
|
|
11982
|
+
if (accepted && amount !== undefined)
|
|
11983
|
+
this.commitAmountUpdate(amount);
|
|
11750
11984
|
const snapshot = this.getUpdateSnapshot().options;
|
|
11751
11985
|
const message = {
|
|
11752
11986
|
channel: ELEMENTS_COMPONENT_CHANNEL,
|
|
@@ -11965,13 +12199,17 @@ class ElementsGroupImpl {
|
|
|
11965
12199
|
if (this.destroyed) {
|
|
11966
12200
|
throw new Error('[Paypercut Elements] Cannot update a destroyed group.');
|
|
11967
12201
|
}
|
|
12202
|
+
const activeElementSubmission = Array.from(this.elements.values()).some((element) => element.hasActiveSubmission());
|
|
12203
|
+
const activeProviderSubmission = Array.from(this.elements.values()).some((element) => element.componentType === 'express_checkout'
|
|
12204
|
+
? element.hasActiveProviderSubmission()
|
|
12205
|
+
: element.hasActiveSubmission());
|
|
11968
12206
|
if (this.pendingValidation !== null ||
|
|
11969
12207
|
this.paymentMethodSubmission.hasActiveSubmission() ||
|
|
11970
|
-
|
|
12208
|
+
(options.appearance !== undefined ? activeElementSubmission : activeProviderSubmission)) {
|
|
11971
12209
|
if (options.appearance !== undefined) {
|
|
11972
12210
|
throw new AppearancePreviewError('elements_appearance_preview_refused', 'Appearance Preview is unavailable while payment validation, Card authentication, or a wallet attempt is active.');
|
|
11973
12211
|
}
|
|
11974
|
-
throw
|
|
12212
|
+
throw createElementsError('elements_submission_in_progress', '[Paypercut Elements] Cannot update Elements while payment details are being submitted.', true);
|
|
11975
12213
|
}
|
|
11976
12214
|
const update = normalizeUpdateOptions(options, this.appearance, this.amount);
|
|
11977
12215
|
const appearanceWasRequested = options.appearance !== undefined;
|
|
@@ -11996,6 +12234,10 @@ class ElementsGroupImpl {
|
|
|
11996
12234
|
if (update.amount === this.amount && !appearanceChanged) {
|
|
11997
12235
|
return Promise.resolve();
|
|
11998
12236
|
}
|
|
12237
|
+
if (!appearanceChanged) {
|
|
12238
|
+
this.commitAmountUpdate(update.amount);
|
|
12239
|
+
return Promise.resolve();
|
|
12240
|
+
}
|
|
11999
12241
|
if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
|
|
12000
12242
|
throw new Error('[Paypercut Elements] The update revision limit has been reached.');
|
|
12001
12243
|
}
|
|
@@ -12027,6 +12269,26 @@ class ElementsGroupImpl {
|
|
|
12027
12269
|
this.postControl(message);
|
|
12028
12270
|
return Promise.resolve();
|
|
12029
12271
|
}
|
|
12272
|
+
commitAmountUpdate(amount) {
|
|
12273
|
+
if (amount === this.amount)
|
|
12274
|
+
return;
|
|
12275
|
+
if (this.updateRevision === Number.MAX_SAFE_INTEGER) {
|
|
12276
|
+
throw new Error('[Paypercut Elements] The update revision limit has been reached.');
|
|
12277
|
+
}
|
|
12278
|
+
this.amount = amount;
|
|
12279
|
+
this.invalidateSubmissionValidation();
|
|
12280
|
+
this.updateRevision += 1;
|
|
12281
|
+
if (!this.controllerInitialized)
|
|
12282
|
+
return;
|
|
12283
|
+
const snapshot = this.getUpdateSnapshot();
|
|
12284
|
+
this.postControl({
|
|
12285
|
+
channel: ELEMENTS_COMPONENT_CHANNEL,
|
|
12286
|
+
type: ElementsControllerCommandType.UpdateOptions,
|
|
12287
|
+
controllerId: this.controllerId,
|
|
12288
|
+
updateRevision: snapshot.updateRevision,
|
|
12289
|
+
options: snapshot.options,
|
|
12290
|
+
});
|
|
12291
|
+
}
|
|
12030
12292
|
startAppearancePreview(appearance, deferCommit = false) {
|
|
12031
12293
|
const generation = ++this.appearancePreviewGeneration;
|
|
12032
12294
|
const previous = cloneElementsAppearance(this.appearance);
|
|
@@ -12188,6 +12450,9 @@ class ElementsGroupImpl {
|
|
|
12188
12450
|
hasMountedCardFields() {
|
|
12189
12451
|
return Array.from(this.cardFields.values()).some((field) => field.isMounted());
|
|
12190
12452
|
}
|
|
12453
|
+
hasVisibleCardFields() {
|
|
12454
|
+
return Array.from(this.cardFields.values()).some((field) => field.isVisible());
|
|
12455
|
+
}
|
|
12191
12456
|
warnAppearancePreview(error) {
|
|
12192
12457
|
if (error.code === 'elements_appearance_preview_superseded')
|
|
12193
12458
|
return;
|
|
@@ -12284,6 +12549,7 @@ class ElementsGroupImpl {
|
|
|
12284
12549
|
configurationIdentity: this.configurationIdentity,
|
|
12285
12550
|
appearanceScopeId: this.controllerId,
|
|
12286
12551
|
presetSource: 'split-card',
|
|
12552
|
+
isVisible: () => !this.destroyed && this.hasVisibleCardFields(),
|
|
12287
12553
|
isAvailable: () => !this.destroyed && this.cardCollectionRuntime.canApplyDeveloperPreset(),
|
|
12288
12554
|
isAppearanceAvailable: () => !this.destroyed && this.hasMountedCardFields(),
|
|
12289
12555
|
appearancePreviewClearsTestData: () => true,
|
|
@@ -12526,7 +12792,7 @@ const MAX_CONFIRM_ATTEMPTS = 3;
|
|
|
12526
12792
|
const CLIENT_SECRET_MARKER = '_secret_';
|
|
12527
12793
|
const CLIENT_SECRET_PREFIX_LENGTH = 3;
|
|
12528
12794
|
const MAX_CLIENT_SECRET_LENGTH = 4096;
|
|
12529
|
-
// Shared with
|
|
12795
|
+
// Shared with Paypercut's payment-resource client-secret issuer. Checkout IDs are
|
|
12530
12796
|
// embedded only so the SDK can address the authoritative resource; merchants
|
|
12531
12797
|
// must continue to treat the complete client secret as opaque.
|
|
12532
12798
|
const MAX_RESOURCE_ID_LENGTH = 200;
|
|
@@ -12744,6 +13010,7 @@ class PaymentConfirmationCoordinator {
|
|
|
12744
13010
|
this.billingDetailsFor = billingDetailsFor;
|
|
12745
13011
|
this.inFlight = new Map();
|
|
12746
13012
|
this.activeAction = null;
|
|
13013
|
+
this.account = options.account;
|
|
12747
13014
|
this.apiUrl = getApiOrigin(options.apiUrl);
|
|
12748
13015
|
this.hostedOrigin = new URL(getCheckoutOrigin(options.hostedCheckoutUrl)).origin;
|
|
12749
13016
|
this.actionShell = new ElementsActionShell(this.hostedOrigin, (actionId) => this.rejectActiveAction(actionId, 'elements_action_canceled', 'Payment authentication was canceled.', true), (actionId, code, message, recoverable) => this.rejectActiveAction(actionId, code, message, recoverable));
|
|
@@ -12821,6 +13088,7 @@ class PaymentConfirmationCoordinator {
|
|
|
12821
13088
|
method: 'GET',
|
|
12822
13089
|
headers: {
|
|
12823
13090
|
Accept: 'application/json',
|
|
13091
|
+
...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
|
|
12824
13092
|
},
|
|
12825
13093
|
}, 'elements_checkout_status_failed', { deadlineAt });
|
|
12826
13094
|
return parseCheckoutStatus(value, parsed.checkoutSessionId);
|
|
@@ -12834,6 +13102,7 @@ class PaymentConfirmationCoordinator {
|
|
|
12834
13102
|
Accept: 'application/json',
|
|
12835
13103
|
'Content-Type': 'application/json',
|
|
12836
13104
|
'Idempotency-Key': idempotencyKey,
|
|
13105
|
+
...(this.account !== undefined ? { 'Paypercut-Account': this.account } : {}),
|
|
12837
13106
|
},
|
|
12838
13107
|
body: JSON.stringify({
|
|
12839
13108
|
key: this.publishableKey,
|
|
@@ -12914,6 +13183,7 @@ class PaymentConfirmationCoordinator {
|
|
|
12914
13183
|
payload: {
|
|
12915
13184
|
protocolVersion: ELEMENTS_PAYMENT_CONFIRMATION_PROTOCOL_VERSION,
|
|
12916
13185
|
publishableKey: this.publishableKey,
|
|
13186
|
+
...(this.account !== undefined ? { account: this.account } : {}),
|
|
12917
13187
|
apiUrl: this.apiUrl,
|
|
12918
13188
|
sdkVersion: config.version,
|
|
12919
13189
|
deadlineAt,
|
|
@@ -12989,6 +13259,7 @@ class PaypercutImpl {
|
|
|
12989
13259
|
this.paymentConfirmation = null;
|
|
12990
13260
|
this.configurationIdentity = JSON.stringify([
|
|
12991
13261
|
options.publishableKey,
|
|
13262
|
+
options.account ?? null,
|
|
12992
13263
|
getApiOrigin(options.apiUrl),
|
|
12993
13264
|
getCheckoutOrigin(options.hostedCheckoutUrl),
|
|
12994
13265
|
]);
|
|
@@ -13062,6 +13333,7 @@ class PaypercutImpl {
|
|
|
13062
13333
|
return Promise.reject(createSubmitError('elements_client_secret_invalid', 'confirmPayment requires only a Checkout Session clientSecret.', false));
|
|
13063
13334
|
}
|
|
13064
13335
|
this.paymentConfirmation ?? (this.paymentConfirmation = new PaymentConfirmationCoordinator(this.options.publishableKey, {
|
|
13336
|
+
...(this.options.account !== undefined ? { account: this.options.account } : {}),
|
|
13065
13337
|
...(this.options.apiUrl ? { apiUrl: this.options.apiUrl } : {}),
|
|
13066
13338
|
...(this.options.hostedCheckoutUrl
|
|
13067
13339
|
? { hostedCheckoutUrl: this.options.hostedCheckoutUrl }
|
|
@@ -13073,12 +13345,22 @@ class PaypercutImpl {
|
|
|
13073
13345
|
function isSetupFutureUsage(value) {
|
|
13074
13346
|
return value === undefined || value === 'on_session' || value === 'off_session';
|
|
13075
13347
|
}
|
|
13076
|
-
const Paypercut = function (options) {
|
|
13077
|
-
|
|
13348
|
+
const Paypercut = function (optionsOrKey, options) {
|
|
13349
|
+
if (typeof optionsOrKey === 'string') {
|
|
13350
|
+
if (options !== undefined &&
|
|
13351
|
+
(!options || typeof options !== 'object' || Array.isArray(options))) {
|
|
13352
|
+
throw new Error('[Paypercut Elements] Client options must be an object.');
|
|
13353
|
+
}
|
|
13354
|
+
return new PaypercutImpl(validateClientOptions({ ...options, publishableKey: optionsOrKey }));
|
|
13355
|
+
}
|
|
13356
|
+
if (options !== undefined) {
|
|
13357
|
+
throw new Error('[Paypercut Elements] Pass client options in one initializer object.');
|
|
13358
|
+
}
|
|
13359
|
+
return new PaypercutImpl(validateClientOptions(optionsOrKey));
|
|
13078
13360
|
};
|
|
13079
13361
|
Paypercut.version = config.version;
|
|
13080
13362
|
function validateClientOptions(options) {
|
|
13081
|
-
if (!options || typeof options !== 'object') {
|
|
13363
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
13082
13364
|
throw new Error('[Paypercut Elements] Client options are required.');
|
|
13083
13365
|
}
|
|
13084
13366
|
const publishableKey = options.publishableKey;
|