@paypercut/checkout-js 1.2.0 → 1.2.3
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 +3 -3
- package/dist/index.cjs +284 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +284 -110
- 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/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,7 @@ class Emitter {
|
|
|
87
87
|
* Production configuration (for merchants)
|
|
88
88
|
*/
|
|
89
89
|
const productionConfig = {
|
|
90
|
-
version: "1.2.
|
|
90
|
+
version: "1.2.3",
|
|
91
91
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
92
92
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
93
93
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -123,6 +123,233 @@ function getVaultApiUrl() {
|
|
|
123
123
|
return config.defaultVaultApiUrl;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
const FRAME_EDGE_GAP = 16;
|
|
127
|
+
const FRAME_DEFAULT_WIDTH = 460;
|
|
128
|
+
const FRAME_DEFAULT_HEIGHT = 680;
|
|
129
|
+
const FRAME_MAX_WIDTH = 860;
|
|
130
|
+
const FRAME_MAX_HEIGHT = 860;
|
|
131
|
+
const FRAME_MIN_WIDTH = 320;
|
|
132
|
+
const FRAME_MIN_HEIGHT = 300;
|
|
133
|
+
const FRAME_CANCEL_OFFSET = 40;
|
|
134
|
+
function getViewportSize() {
|
|
135
|
+
const visualViewport = typeof window !== 'undefined' ? window.visualViewport : undefined;
|
|
136
|
+
const documentElement = typeof document !== 'undefined' ? document.documentElement : undefined;
|
|
137
|
+
return {
|
|
138
|
+
width: visualViewport?.width ||
|
|
139
|
+
window.innerWidth ||
|
|
140
|
+
documentElement?.clientWidth ||
|
|
141
|
+
window.screen?.width ||
|
|
142
|
+
FRAME_DEFAULT_WIDTH,
|
|
143
|
+
height: visualViewport?.height ||
|
|
144
|
+
window.innerHeight ||
|
|
145
|
+
documentElement?.clientHeight ||
|
|
146
|
+
window.screen?.height ||
|
|
147
|
+
FRAME_DEFAULT_HEIGHT,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function clampToAvailableSpace(value, min, max) {
|
|
151
|
+
const lower = Math.min(min, max);
|
|
152
|
+
return Math.min(Math.max(value, lower), max);
|
|
153
|
+
}
|
|
154
|
+
function createThreeDSModalBackdrop(id) {
|
|
155
|
+
const modal = document.createElement('div');
|
|
156
|
+
const viewport = getViewportSize();
|
|
157
|
+
modal.id = id;
|
|
158
|
+
Object.assign(modal.style, {
|
|
159
|
+
position: 'fixed',
|
|
160
|
+
top: '0',
|
|
161
|
+
left: '0',
|
|
162
|
+
width: `${viewport.width}px`,
|
|
163
|
+
height: `${viewport.height}px`,
|
|
164
|
+
minHeight: `${viewport.height}px`,
|
|
165
|
+
display: 'flex',
|
|
166
|
+
alignItems: 'center',
|
|
167
|
+
justifyContent: 'center',
|
|
168
|
+
zIndex: '999999',
|
|
169
|
+
background: 'rgba(0, 0, 0, 0.56)',
|
|
170
|
+
padding: `${FRAME_EDGE_GAP}px`,
|
|
171
|
+
boxSizing: 'border-box',
|
|
172
|
+
overflow: 'hidden',
|
|
173
|
+
});
|
|
174
|
+
return modal;
|
|
175
|
+
}
|
|
176
|
+
function applyThreeDSFrameSize(modal, iframe, requestedSize = {}, shell) {
|
|
177
|
+
if (!modal || !iframe) {
|
|
178
|
+
return requestedSize;
|
|
179
|
+
}
|
|
180
|
+
const viewport = getViewportSize();
|
|
181
|
+
const maxWidth = Math.min(FRAME_MAX_WIDTH, Math.max(0, viewport.width - FRAME_EDGE_GAP * 2));
|
|
182
|
+
const maxHeight = Math.min(FRAME_MAX_HEIGHT, Math.max(0, viewport.height - (FRAME_EDGE_GAP + FRAME_CANCEL_OFFSET) * 2));
|
|
183
|
+
const requestedWidth = requestedSize.width ?? FRAME_DEFAULT_WIDTH;
|
|
184
|
+
const requestedHeight = requestedSize.height ?? FRAME_DEFAULT_HEIGHT;
|
|
185
|
+
const width = clampToAvailableSpace(requestedWidth, FRAME_MIN_WIDTH, maxWidth);
|
|
186
|
+
const height = clampToAvailableSpace(requestedHeight, FRAME_MIN_HEIGHT, maxHeight);
|
|
187
|
+
modal.style.width = `${viewport.width}px`;
|
|
188
|
+
modal.style.height = `${viewport.height}px`;
|
|
189
|
+
modal.style.minHeight = `${viewport.height}px`;
|
|
190
|
+
iframe.style.width = `${Math.round(width)}px`;
|
|
191
|
+
iframe.style.height = `${Math.round(height)}px`;
|
|
192
|
+
if (shell) {
|
|
193
|
+
shell.style.width = `${Math.round(width)}px`;
|
|
194
|
+
shell.style.height = `${Math.round(height)}px`;
|
|
195
|
+
}
|
|
196
|
+
return { width, height };
|
|
197
|
+
}
|
|
198
|
+
function createThreeDSFrameShell(onCancel) {
|
|
199
|
+
const shell = document.createElement('div');
|
|
200
|
+
Object.assign(shell.style, {
|
|
201
|
+
position: 'relative',
|
|
202
|
+
borderRadius: '6px',
|
|
203
|
+
background: 'transparent',
|
|
204
|
+
boxShadow: '0 24px 64px rgba(0, 0, 0, 0.36), 0 2px 10px rgba(0, 0, 0, 0.18)',
|
|
205
|
+
overflow: 'visible',
|
|
206
|
+
});
|
|
207
|
+
const iframe = document.createElement('iframe');
|
|
208
|
+
iframe.allow = 'payment *';
|
|
209
|
+
iframe.setAttribute('frameborder', '0');
|
|
210
|
+
Object.assign(iframe.style, {
|
|
211
|
+
border: 'none',
|
|
212
|
+
borderRadius: '6px',
|
|
213
|
+
display: 'block',
|
|
214
|
+
background: 'transparent',
|
|
215
|
+
maxWidth: '100%',
|
|
216
|
+
maxHeight: '100%',
|
|
217
|
+
});
|
|
218
|
+
const cancelButton = document.createElement('button');
|
|
219
|
+
cancelButton.type = 'button';
|
|
220
|
+
cancelButton.textContent = 'Cancel';
|
|
221
|
+
cancelButton.setAttribute('aria-label', 'Cancel 3D Secure authentication');
|
|
222
|
+
Object.assign(cancelButton.style, {
|
|
223
|
+
position: 'absolute',
|
|
224
|
+
top: '-40px',
|
|
225
|
+
right: '0',
|
|
226
|
+
zIndex: '2',
|
|
227
|
+
height: '28px',
|
|
228
|
+
padding: '0 10px',
|
|
229
|
+
border: '0',
|
|
230
|
+
borderRadius: '999px',
|
|
231
|
+
background: 'rgba(17, 24, 39, 0.56)',
|
|
232
|
+
color: '#ffffff',
|
|
233
|
+
font: '600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
234
|
+
letterSpacing: '0.04em',
|
|
235
|
+
textTransform: 'uppercase',
|
|
236
|
+
cursor: 'pointer',
|
|
237
|
+
boxShadow: '0 4px 16px rgba(0, 0, 0, 0.24)',
|
|
238
|
+
transform: 'translateY(0) scale(1)',
|
|
239
|
+
transition: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
240
|
+
? 'none'
|
|
241
|
+
: 'transform 300ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 300ms cubic-bezier(0.22, 1, 0.36, 1), background 300ms cubic-bezier(0.22, 1, 0.36, 1)',
|
|
242
|
+
willChange: 'transform',
|
|
243
|
+
});
|
|
244
|
+
const resetCancelButton = () => {
|
|
245
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.56)';
|
|
246
|
+
cancelButton.style.boxShadow = '0 4px 16px rgba(0, 0, 0, 0.24)';
|
|
247
|
+
cancelButton.style.transform = 'translateY(0) scale(1)';
|
|
248
|
+
};
|
|
249
|
+
const liftCancelButton = () => {
|
|
250
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.68)';
|
|
251
|
+
cancelButton.style.boxShadow = '0 8px 22px rgba(0, 0, 0, 0.26)';
|
|
252
|
+
cancelButton.style.transform = 'translateY(-1px) scale(1.025)';
|
|
253
|
+
};
|
|
254
|
+
const pressCancelButton = () => {
|
|
255
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.72)';
|
|
256
|
+
cancelButton.style.boxShadow = '0 3px 12px rgba(0, 0, 0, 0.22)';
|
|
257
|
+
cancelButton.style.transform = 'translateY(0) scale(0.985)';
|
|
258
|
+
};
|
|
259
|
+
cancelButton.addEventListener('mouseenter', liftCancelButton);
|
|
260
|
+
cancelButton.addEventListener('focus', liftCancelButton);
|
|
261
|
+
cancelButton.addEventListener('mouseleave', resetCancelButton);
|
|
262
|
+
cancelButton.addEventListener('blur', resetCancelButton);
|
|
263
|
+
cancelButton.addEventListener('mouseup', liftCancelButton);
|
|
264
|
+
cancelButton.addEventListener('mousedown', pressCancelButton);
|
|
265
|
+
cancelButton.addEventListener('click', onCancel);
|
|
266
|
+
shell.appendChild(iframe);
|
|
267
|
+
shell.appendChild(cancelButton);
|
|
268
|
+
return { shell, iframe, cancelButton };
|
|
269
|
+
}
|
|
270
|
+
function normalizeThreeDSFrameSize(data) {
|
|
271
|
+
if (!data || typeof data !== 'object') {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const raw = data;
|
|
275
|
+
const next = {};
|
|
276
|
+
if (typeof raw.width === 'number' && Number.isFinite(raw.width) && raw.width > 0) {
|
|
277
|
+
next.width = raw.width;
|
|
278
|
+
}
|
|
279
|
+
if (typeof raw.height === 'number' && Number.isFinite(raw.height) && raw.height > 0) {
|
|
280
|
+
next.height = raw.height;
|
|
281
|
+
}
|
|
282
|
+
return next.width || next.height ? next : null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
class ThreeDSModalController {
|
|
286
|
+
constructor(options) {
|
|
287
|
+
this.options = options;
|
|
288
|
+
this.modal = null;
|
|
289
|
+
this.shell = null;
|
|
290
|
+
this.iframe = null;
|
|
291
|
+
this.frameSize = {};
|
|
292
|
+
this.resizeHandler = null;
|
|
293
|
+
this.pendingData = null;
|
|
294
|
+
}
|
|
295
|
+
show(data) {
|
|
296
|
+
this.close();
|
|
297
|
+
this.modal = createThreeDSModalBackdrop(this.options.modalId);
|
|
298
|
+
this.shell = createThreeDSFrameShell(() => this.options.onCancel());
|
|
299
|
+
this.iframe = this.shell.iframe;
|
|
300
|
+
this.iframe.src = this.options.buildUrl(data);
|
|
301
|
+
this.frameSize = {};
|
|
302
|
+
this.applySize();
|
|
303
|
+
this.modal.appendChild(this.shell.shell);
|
|
304
|
+
document.body.appendChild(this.modal);
|
|
305
|
+
this.resizeHandler = () => this.applySize();
|
|
306
|
+
window.addEventListener('resize', this.resizeHandler);
|
|
307
|
+
window.addEventListener('orientationchange', this.resizeHandler);
|
|
308
|
+
window.visualViewport?.addEventListener('resize', this.resizeHandler);
|
|
309
|
+
this.pendingData = data;
|
|
310
|
+
}
|
|
311
|
+
handleFrameResize(evt, data) {
|
|
312
|
+
if (!this.iframe?.contentWindow || evt.source !== this.iframe.contentWindow) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const nextSize = normalizeThreeDSFrameSize(data);
|
|
316
|
+
if (!nextSize) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
this.frameSize = {
|
|
320
|
+
...this.frameSize,
|
|
321
|
+
...nextSize,
|
|
322
|
+
};
|
|
323
|
+
this.applySize();
|
|
324
|
+
}
|
|
325
|
+
handleReady() {
|
|
326
|
+
if (!this.pendingData || !this.iframe?.contentWindow) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
this.options.onReady(this.iframe, this.pendingData);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
close() {
|
|
333
|
+
if (this.resizeHandler) {
|
|
334
|
+
window.removeEventListener('resize', this.resizeHandler);
|
|
335
|
+
window.removeEventListener('orientationchange', this.resizeHandler);
|
|
336
|
+
window.visualViewport?.removeEventListener('resize', this.resizeHandler);
|
|
337
|
+
this.resizeHandler = null;
|
|
338
|
+
}
|
|
339
|
+
if (this.modal) {
|
|
340
|
+
this.modal.remove();
|
|
341
|
+
this.modal = null;
|
|
342
|
+
}
|
|
343
|
+
this.shell = null;
|
|
344
|
+
this.iframe = null;
|
|
345
|
+
this.frameSize = {};
|
|
346
|
+
this.pendingData = null;
|
|
347
|
+
}
|
|
348
|
+
applySize() {
|
|
349
|
+
applyThreeDSFrameSize(this.modal, this.iframe, this.frameSize, this.shell?.shell);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
126
353
|
/**
|
|
127
354
|
* Supported locales for Paypercut Checkout
|
|
128
355
|
*
|
|
@@ -483,9 +710,6 @@ class ExpressCheckoutImpl {
|
|
|
483
710
|
* Regenerated on each wallet button click so retries get a fresh key.
|
|
484
711
|
*/
|
|
485
712
|
this.idempotencyKey = generateId();
|
|
486
|
-
// 3DS modal — same pattern as CheckoutImpl
|
|
487
|
-
this.threeDSModal = null;
|
|
488
|
-
this.threeDSIframe = null;
|
|
489
713
|
// Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
|
|
490
714
|
// Shown after loadPaymentData() resolves
|
|
491
715
|
this.pending3DSAfterGpay = null;
|
|
@@ -514,6 +738,12 @@ class ExpressCheckoutImpl {
|
|
|
514
738
|
this.pendingGpayShippingOption = undefined;
|
|
515
739
|
this.currentShippingOptions = options.shippingOptions ?? [];
|
|
516
740
|
this.messageHandler = this.onMessage.bind(this);
|
|
741
|
+
this.threeDSModal = new ThreeDSModalController({
|
|
742
|
+
modalId: 'paypercut-express-3ds-modal',
|
|
743
|
+
buildUrl: (data) => this.buildThreeDSUrl(data),
|
|
744
|
+
onCancel: () => this.handle3DSShellCancel(),
|
|
745
|
+
onReady: (iframe) => this.postThreeDSInit(iframe),
|
|
746
|
+
});
|
|
517
747
|
window.addEventListener('message', this.messageHandler);
|
|
518
748
|
}
|
|
519
749
|
// ─── URL builders
|
|
@@ -685,6 +915,9 @@ class ExpressCheckoutImpl {
|
|
|
685
915
|
}
|
|
686
916
|
break;
|
|
687
917
|
// 3DS flow
|
|
918
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
919
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
920
|
+
break;
|
|
688
921
|
case 'THREEDS_START_FLOW':
|
|
689
922
|
// Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
|
|
690
923
|
// Resolve the pending GPay promise so GPay starts closing its sheet.
|
|
@@ -696,7 +929,7 @@ class ExpressCheckoutImpl {
|
|
|
696
929
|
}
|
|
697
930
|
else {
|
|
698
931
|
// Apple Pay or any path without a pending GPay sheet — show immediately
|
|
699
|
-
this.
|
|
932
|
+
this.threeDSModal.show(data);
|
|
700
933
|
}
|
|
701
934
|
break;
|
|
702
935
|
case 'THREEDS_READY':
|
|
@@ -706,7 +939,7 @@ class ExpressCheckoutImpl {
|
|
|
706
939
|
case 'THREEDS_CANCELED':
|
|
707
940
|
case 'THREEDS_ERROR':
|
|
708
941
|
this.postToTokenizeIframe(data);
|
|
709
|
-
this.
|
|
942
|
+
this.threeDSModal.close();
|
|
710
943
|
break;
|
|
711
944
|
}
|
|
712
945
|
}
|
|
@@ -1409,7 +1642,7 @@ class ExpressCheckoutImpl {
|
|
|
1409
1642
|
if (this.pending3DSAfterGpay) {
|
|
1410
1643
|
const threeDSData = this.pending3DSAfterGpay;
|
|
1411
1644
|
this.pending3DSAfterGpay = null;
|
|
1412
|
-
this.
|
|
1645
|
+
this.threeDSModal.show(threeDSData);
|
|
1413
1646
|
}
|
|
1414
1647
|
}
|
|
1415
1648
|
catch (e) {
|
|
@@ -1623,7 +1856,7 @@ class ExpressCheckoutImpl {
|
|
|
1623
1856
|
this.layoutResizeObserver.disconnect();
|
|
1624
1857
|
this.layoutResizeObserver = null;
|
|
1625
1858
|
}
|
|
1626
|
-
this.
|
|
1859
|
+
this.threeDSModal.close();
|
|
1627
1860
|
this.abortApplePaySession();
|
|
1628
1861
|
this.sessionActive = false;
|
|
1629
1862
|
this.mounted = false;
|
|
@@ -1731,23 +1964,8 @@ class ExpressCheckoutImpl {
|
|
|
1731
1964
|
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1732
1965
|
this.tokenizeIframe.contentWindow.postMessage(message, origin);
|
|
1733
1966
|
}
|
|
1734
|
-
// ─── 3DS modal
|
|
1735
|
-
|
|
1736
|
-
this.threeDSModal = document.createElement('div');
|
|
1737
|
-
this.threeDSModal.id = 'paypercut-express-3ds-modal';
|
|
1738
|
-
Object.assign(this.threeDSModal.style, {
|
|
1739
|
-
position: 'fixed',
|
|
1740
|
-
top: '0',
|
|
1741
|
-
left: '0',
|
|
1742
|
-
width: '100%',
|
|
1743
|
-
height: '100%',
|
|
1744
|
-
display: 'flex',
|
|
1745
|
-
alignItems: 'center',
|
|
1746
|
-
justifyContent: 'center',
|
|
1747
|
-
zIndex: '999999',
|
|
1748
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
1749
|
-
});
|
|
1750
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
1967
|
+
// ─── 3DS modal ──────────
|
|
1968
|
+
buildThreeDSUrl(data) {
|
|
1751
1969
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1752
1970
|
const threeDSUrl = new URL('/express/threeds', checkoutOrigin);
|
|
1753
1971
|
threeDSUrl.searchParams.set('instanceId', this.instanceId);
|
|
@@ -1760,37 +1978,25 @@ class ExpressCheckoutImpl {
|
|
|
1760
1978
|
if (data.threeDSVersion)
|
|
1761
1979
|
threeDSUrl.searchParams.set('threeDSVersion', data.threeDSVersion);
|
|
1762
1980
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
borderRadius: '8px',
|
|
1771
|
-
display: 'block',
|
|
1772
|
-
background: 'transparent',
|
|
1981
|
+
return threeDSUrl.toString();
|
|
1982
|
+
}
|
|
1983
|
+
handle3DSShellCancel() {
|
|
1984
|
+
this.postToTokenizeIframe({
|
|
1985
|
+
type: 'THREEDS_CANCELED',
|
|
1986
|
+
instanceId: this.instanceId,
|
|
1987
|
+
error: 'User canceled 3DS authentication',
|
|
1773
1988
|
});
|
|
1774
|
-
this.threeDSModal.
|
|
1775
|
-
|
|
1776
|
-
this._pending3DSData = data;
|
|
1989
|
+
this.threeDSModal.close();
|
|
1990
|
+
this.emitter.emit(ExpressSdkEvent.Cancel);
|
|
1777
1991
|
}
|
|
1778
1992
|
handle3DSReady() {
|
|
1779
|
-
|
|
1780
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
1993
|
+
if (!this.threeDSModal.handleReady()) {
|
|
1781
1994
|
console.error('[PaypercutExpressCheckout] No pending 3DS data or iframe not ready');
|
|
1782
|
-
return;
|
|
1783
1995
|
}
|
|
1784
|
-
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1785
|
-
this.threeDSIframe.contentWindow.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1786
1996
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
this.threeDSModal = null;
|
|
1791
|
-
}
|
|
1792
|
-
this.threeDSIframe = null;
|
|
1793
|
-
delete this._pending3DSData;
|
|
1997
|
+
postThreeDSInit(iframe) {
|
|
1998
|
+
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1999
|
+
iframe.contentWindow?.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1794
2000
|
}
|
|
1795
2001
|
}
|
|
1796
2002
|
//Factory
|
|
@@ -1808,11 +2014,14 @@ class CheckoutImpl {
|
|
|
1808
2014
|
this.mounted = false;
|
|
1809
2015
|
this.destroyed = false;
|
|
1810
2016
|
this.iframe = null;
|
|
1811
|
-
// 3DS Modal state
|
|
1812
|
-
this.threeDSModal = null;
|
|
1813
|
-
this.threeDSIframe = null;
|
|
1814
2017
|
// Bind message handler
|
|
1815
2018
|
this.messageHandler = this.onMessage.bind(this);
|
|
2019
|
+
this.threeDSModal = new ThreeDSModalController({
|
|
2020
|
+
modalId: 'paypercut-3ds-modal',
|
|
2021
|
+
buildUrl: (data) => this.buildThreeDSUrl(data),
|
|
2022
|
+
onCancel: () => this.handle3DSShellCancel(),
|
|
2023
|
+
onReady: (iframe) => this.postThreeDSInit(iframe),
|
|
2024
|
+
});
|
|
1816
2025
|
window.addEventListener('message', this.messageHandler);
|
|
1817
2026
|
}
|
|
1818
2027
|
/**
|
|
@@ -1933,8 +2142,11 @@ class CheckoutImpl {
|
|
|
1933
2142
|
this.emitter.emit(SdkEvent.Resize, data.height);
|
|
1934
2143
|
this.handleResize(data.height);
|
|
1935
2144
|
break;
|
|
2145
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
2146
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
2147
|
+
break;
|
|
1936
2148
|
case 'THREEDS_START_FLOW':
|
|
1937
|
-
this.
|
|
2149
|
+
this.threeDSModal.show(data);
|
|
1938
2150
|
this.emitter.emit(SdkEvent.ThreeDSStarted);
|
|
1939
2151
|
break;
|
|
1940
2152
|
case 'THREEDS_READY':
|
|
@@ -1942,17 +2154,17 @@ class CheckoutImpl {
|
|
|
1942
2154
|
break;
|
|
1943
2155
|
case 'THREEDS_COMPLETE':
|
|
1944
2156
|
this.postToIframe(data);
|
|
1945
|
-
this.
|
|
2157
|
+
this.threeDSModal.close();
|
|
1946
2158
|
this.emitter.emit(SdkEvent.ThreeDSComplete);
|
|
1947
2159
|
break;
|
|
1948
2160
|
case 'THREEDS_CANCELED':
|
|
1949
2161
|
this.postToIframe(data);
|
|
1950
|
-
this.
|
|
2162
|
+
this.threeDSModal.close();
|
|
1951
2163
|
this.emitter.emit(SdkEvent.ThreeDSCanceled);
|
|
1952
2164
|
break;
|
|
1953
2165
|
case 'THREEDS_ERROR':
|
|
1954
2166
|
this.postToIframe(data);
|
|
1955
|
-
this.
|
|
2167
|
+
this.threeDSModal.close();
|
|
1956
2168
|
this.emitter.emit(SdkEvent.ThreeDSError, data.error);
|
|
1957
2169
|
break;
|
|
1958
2170
|
case 'FORM_VALIDATION':
|
|
@@ -2042,27 +2254,7 @@ class CheckoutImpl {
|
|
|
2042
2254
|
// Set iframe height to match content
|
|
2043
2255
|
this.iframe.style.height = `${height}px`;
|
|
2044
2256
|
}
|
|
2045
|
-
|
|
2046
|
-
* Show 3DS modal with challenge/decoupled flow
|
|
2047
|
-
*/
|
|
2048
|
-
show3DSModal(data) {
|
|
2049
|
-
// Create modal backdrop
|
|
2050
|
-
this.threeDSModal = document.createElement('div');
|
|
2051
|
-
this.threeDSModal.id = 'paypercut-3ds-modal';
|
|
2052
|
-
Object.assign(this.threeDSModal.style, {
|
|
2053
|
-
position: 'fixed',
|
|
2054
|
-
top: '0',
|
|
2055
|
-
left: '0',
|
|
2056
|
-
width: '100%',
|
|
2057
|
-
height: '100%',
|
|
2058
|
-
display: 'flex',
|
|
2059
|
-
alignItems: 'center',
|
|
2060
|
-
justifyContent: 'center',
|
|
2061
|
-
zIndex: '999999',
|
|
2062
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
2063
|
-
});
|
|
2064
|
-
// Create iframe for 3DS page
|
|
2065
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
2257
|
+
buildThreeDSUrl(data) {
|
|
2066
2258
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2067
2259
|
// Build URL: baseUrl/c/{checkoutId}/threeds with query params
|
|
2068
2260
|
const threeDSUrl = new URL(`/c/${this.options.id}/threeds`, checkoutOrigin);
|
|
@@ -2079,50 +2271,32 @@ class CheckoutImpl {
|
|
|
2079
2271
|
}
|
|
2080
2272
|
// Always include liveMode; default to false when undefined
|
|
2081
2273
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
border: 'none',
|
|
2090
|
-
borderRadius: '8px',
|
|
2091
|
-
display: 'block',
|
|
2092
|
-
background: 'transparent',
|
|
2274
|
+
return threeDSUrl.toString();
|
|
2275
|
+
}
|
|
2276
|
+
handle3DSShellCancel() {
|
|
2277
|
+
this.postToIframe({
|
|
2278
|
+
type: 'THREEDS_CANCELED',
|
|
2279
|
+
checkoutId: this.options.id,
|
|
2280
|
+
reason: 'sdk_shell_cancel',
|
|
2093
2281
|
});
|
|
2094
|
-
|
|
2095
|
-
this.
|
|
2096
|
-
document.body.appendChild(this.threeDSModal);
|
|
2097
|
-
// Store 3DS data for later use
|
|
2098
|
-
this.pending3DSData = data;
|
|
2282
|
+
this.threeDSModal.close();
|
|
2283
|
+
this.emitter.emit(SdkEvent.ThreeDSCanceled);
|
|
2099
2284
|
}
|
|
2100
2285
|
/**
|
|
2101
2286
|
* Handle THREEDS_READY message - send THREEDS_INIT with challenge data
|
|
2102
2287
|
*/
|
|
2103
2288
|
handle3DSReady() {
|
|
2104
|
-
|
|
2105
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
2289
|
+
if (!this.threeDSModal.handleReady()) {
|
|
2106
2290
|
console.error('[PaypercutCheckout] No pending 3DS data or iframe not ready');
|
|
2107
|
-
return;
|
|
2108
2291
|
}
|
|
2292
|
+
}
|
|
2293
|
+
postThreeDSInit(iframe) {
|
|
2109
2294
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2110
|
-
|
|
2295
|
+
iframe.contentWindow?.postMessage({
|
|
2111
2296
|
type: 'THREEDS_INIT',
|
|
2112
2297
|
checkoutId: this.options.id,
|
|
2113
2298
|
}, checkoutOrigin);
|
|
2114
2299
|
}
|
|
2115
|
-
/**
|
|
2116
|
-
* Close 3DS modal and cleanup
|
|
2117
|
-
*/
|
|
2118
|
-
close3DSModal() {
|
|
2119
|
-
if (this.threeDSModal) {
|
|
2120
|
-
this.threeDSModal.remove();
|
|
2121
|
-
this.threeDSModal = null;
|
|
2122
|
-
}
|
|
2123
|
-
this.threeDSIframe = null;
|
|
2124
|
-
delete this.pending3DSData;
|
|
2125
|
-
}
|
|
2126
2300
|
/**
|
|
2127
2301
|
* Destroy the checkout instance and cleanup (idempotent)
|
|
2128
2302
|
*/
|
|
@@ -2142,7 +2316,7 @@ class CheckoutImpl {
|
|
|
2142
2316
|
}
|
|
2143
2317
|
}
|
|
2144
2318
|
// Cleanup 3DS modal if open
|
|
2145
|
-
this.
|
|
2319
|
+
this.threeDSModal.close();
|
|
2146
2320
|
// Only set mounted = false after successful DOM removal
|
|
2147
2321
|
this.mounted = false;
|
|
2148
2322
|
this.destroyed = true;
|