@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/README.md
CHANGED
|
@@ -63,12 +63,12 @@ pnpm add @paypercut/checkout-js
|
|
|
63
63
|
|
|
64
64
|
```html
|
|
65
65
|
<!-- jsDelivr (recommended with SRI) -->
|
|
66
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.
|
|
66
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.2.3/dist/paypercut-checkout.iife.min.js"
|
|
67
67
|
integrity="sha384-..."
|
|
68
68
|
crossorigin="anonymous"></script>
|
|
69
69
|
|
|
70
70
|
<!-- or UNPKG -->
|
|
71
|
-
<script src="https://unpkg.com/@paypercut/checkout-js@1.
|
|
71
|
+
<script src="https://unpkg.com/@paypercut/checkout-js@1.2.3/dist/paypercut-checkout.iife.min.js"></script>
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
---
|
|
@@ -760,7 +760,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
|
|
|
760
760
|
<body>
|
|
761
761
|
<div id="checkout"></div>
|
|
762
762
|
|
|
763
|
-
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.
|
|
763
|
+
<script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.2.3/dist/paypercut-checkout.iife.min.js"></script>
|
|
764
764
|
<script>
|
|
765
765
|
const checkout = PaypercutCheckout({
|
|
766
766
|
id: '01KB23M9EC960C50G3AH14FTTT',
|
package/dist/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ class Emitter {
|
|
|
91
91
|
* Production configuration (for merchants)
|
|
92
92
|
*/
|
|
93
93
|
const productionConfig = {
|
|
94
|
-
version: "1.2.
|
|
94
|
+
version: "1.2.3",
|
|
95
95
|
defaultCheckoutOrigin: 'https://buy.paypercut.io',
|
|
96
96
|
defaultApiOrigin: 'https://api.paypercut.io',
|
|
97
97
|
defaultVaultApiUrl: 'https://api.basistheory.com',
|
|
@@ -127,6 +127,233 @@ function getVaultApiUrl() {
|
|
|
127
127
|
return config.defaultVaultApiUrl;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
const FRAME_EDGE_GAP = 16;
|
|
131
|
+
const FRAME_DEFAULT_WIDTH = 460;
|
|
132
|
+
const FRAME_DEFAULT_HEIGHT = 680;
|
|
133
|
+
const FRAME_MAX_WIDTH = 860;
|
|
134
|
+
const FRAME_MAX_HEIGHT = 860;
|
|
135
|
+
const FRAME_MIN_WIDTH = 320;
|
|
136
|
+
const FRAME_MIN_HEIGHT = 300;
|
|
137
|
+
const FRAME_CANCEL_OFFSET = 40;
|
|
138
|
+
function getViewportSize() {
|
|
139
|
+
const visualViewport = typeof window !== 'undefined' ? window.visualViewport : undefined;
|
|
140
|
+
const documentElement = typeof document !== 'undefined' ? document.documentElement : undefined;
|
|
141
|
+
return {
|
|
142
|
+
width: visualViewport?.width ||
|
|
143
|
+
window.innerWidth ||
|
|
144
|
+
documentElement?.clientWidth ||
|
|
145
|
+
window.screen?.width ||
|
|
146
|
+
FRAME_DEFAULT_WIDTH,
|
|
147
|
+
height: visualViewport?.height ||
|
|
148
|
+
window.innerHeight ||
|
|
149
|
+
documentElement?.clientHeight ||
|
|
150
|
+
window.screen?.height ||
|
|
151
|
+
FRAME_DEFAULT_HEIGHT,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function clampToAvailableSpace(value, min, max) {
|
|
155
|
+
const lower = Math.min(min, max);
|
|
156
|
+
return Math.min(Math.max(value, lower), max);
|
|
157
|
+
}
|
|
158
|
+
function createThreeDSModalBackdrop(id) {
|
|
159
|
+
const modal = document.createElement('div');
|
|
160
|
+
const viewport = getViewportSize();
|
|
161
|
+
modal.id = id;
|
|
162
|
+
Object.assign(modal.style, {
|
|
163
|
+
position: 'fixed',
|
|
164
|
+
top: '0',
|
|
165
|
+
left: '0',
|
|
166
|
+
width: `${viewport.width}px`,
|
|
167
|
+
height: `${viewport.height}px`,
|
|
168
|
+
minHeight: `${viewport.height}px`,
|
|
169
|
+
display: 'flex',
|
|
170
|
+
alignItems: 'center',
|
|
171
|
+
justifyContent: 'center',
|
|
172
|
+
zIndex: '999999',
|
|
173
|
+
background: 'rgba(0, 0, 0, 0.56)',
|
|
174
|
+
padding: `${FRAME_EDGE_GAP}px`,
|
|
175
|
+
boxSizing: 'border-box',
|
|
176
|
+
overflow: 'hidden',
|
|
177
|
+
});
|
|
178
|
+
return modal;
|
|
179
|
+
}
|
|
180
|
+
function applyThreeDSFrameSize(modal, iframe, requestedSize = {}, shell) {
|
|
181
|
+
if (!modal || !iframe) {
|
|
182
|
+
return requestedSize;
|
|
183
|
+
}
|
|
184
|
+
const viewport = getViewportSize();
|
|
185
|
+
const maxWidth = Math.min(FRAME_MAX_WIDTH, Math.max(0, viewport.width - FRAME_EDGE_GAP * 2));
|
|
186
|
+
const maxHeight = Math.min(FRAME_MAX_HEIGHT, Math.max(0, viewport.height - (FRAME_EDGE_GAP + FRAME_CANCEL_OFFSET) * 2));
|
|
187
|
+
const requestedWidth = requestedSize.width ?? FRAME_DEFAULT_WIDTH;
|
|
188
|
+
const requestedHeight = requestedSize.height ?? FRAME_DEFAULT_HEIGHT;
|
|
189
|
+
const width = clampToAvailableSpace(requestedWidth, FRAME_MIN_WIDTH, maxWidth);
|
|
190
|
+
const height = clampToAvailableSpace(requestedHeight, FRAME_MIN_HEIGHT, maxHeight);
|
|
191
|
+
modal.style.width = `${viewport.width}px`;
|
|
192
|
+
modal.style.height = `${viewport.height}px`;
|
|
193
|
+
modal.style.minHeight = `${viewport.height}px`;
|
|
194
|
+
iframe.style.width = `${Math.round(width)}px`;
|
|
195
|
+
iframe.style.height = `${Math.round(height)}px`;
|
|
196
|
+
if (shell) {
|
|
197
|
+
shell.style.width = `${Math.round(width)}px`;
|
|
198
|
+
shell.style.height = `${Math.round(height)}px`;
|
|
199
|
+
}
|
|
200
|
+
return { width, height };
|
|
201
|
+
}
|
|
202
|
+
function createThreeDSFrameShell(onCancel) {
|
|
203
|
+
const shell = document.createElement('div');
|
|
204
|
+
Object.assign(shell.style, {
|
|
205
|
+
position: 'relative',
|
|
206
|
+
borderRadius: '6px',
|
|
207
|
+
background: 'transparent',
|
|
208
|
+
boxShadow: '0 24px 64px rgba(0, 0, 0, 0.36), 0 2px 10px rgba(0, 0, 0, 0.18)',
|
|
209
|
+
overflow: 'visible',
|
|
210
|
+
});
|
|
211
|
+
const iframe = document.createElement('iframe');
|
|
212
|
+
iframe.allow = 'payment *';
|
|
213
|
+
iframe.setAttribute('frameborder', '0');
|
|
214
|
+
Object.assign(iframe.style, {
|
|
215
|
+
border: 'none',
|
|
216
|
+
borderRadius: '6px',
|
|
217
|
+
display: 'block',
|
|
218
|
+
background: 'transparent',
|
|
219
|
+
maxWidth: '100%',
|
|
220
|
+
maxHeight: '100%',
|
|
221
|
+
});
|
|
222
|
+
const cancelButton = document.createElement('button');
|
|
223
|
+
cancelButton.type = 'button';
|
|
224
|
+
cancelButton.textContent = 'Cancel';
|
|
225
|
+
cancelButton.setAttribute('aria-label', 'Cancel 3D Secure authentication');
|
|
226
|
+
Object.assign(cancelButton.style, {
|
|
227
|
+
position: 'absolute',
|
|
228
|
+
top: '-40px',
|
|
229
|
+
right: '0',
|
|
230
|
+
zIndex: '2',
|
|
231
|
+
height: '28px',
|
|
232
|
+
padding: '0 10px',
|
|
233
|
+
border: '0',
|
|
234
|
+
borderRadius: '999px',
|
|
235
|
+
background: 'rgba(17, 24, 39, 0.56)',
|
|
236
|
+
color: '#ffffff',
|
|
237
|
+
font: '600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
238
|
+
letterSpacing: '0.04em',
|
|
239
|
+
textTransform: 'uppercase',
|
|
240
|
+
cursor: 'pointer',
|
|
241
|
+
boxShadow: '0 4px 16px rgba(0, 0, 0, 0.24)',
|
|
242
|
+
transform: 'translateY(0) scale(1)',
|
|
243
|
+
transition: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
244
|
+
? 'none'
|
|
245
|
+
: '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)',
|
|
246
|
+
willChange: 'transform',
|
|
247
|
+
});
|
|
248
|
+
const resetCancelButton = () => {
|
|
249
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.56)';
|
|
250
|
+
cancelButton.style.boxShadow = '0 4px 16px rgba(0, 0, 0, 0.24)';
|
|
251
|
+
cancelButton.style.transform = 'translateY(0) scale(1)';
|
|
252
|
+
};
|
|
253
|
+
const liftCancelButton = () => {
|
|
254
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.68)';
|
|
255
|
+
cancelButton.style.boxShadow = '0 8px 22px rgba(0, 0, 0, 0.26)';
|
|
256
|
+
cancelButton.style.transform = 'translateY(-1px) scale(1.025)';
|
|
257
|
+
};
|
|
258
|
+
const pressCancelButton = () => {
|
|
259
|
+
cancelButton.style.background = 'rgba(17, 24, 39, 0.72)';
|
|
260
|
+
cancelButton.style.boxShadow = '0 3px 12px rgba(0, 0, 0, 0.22)';
|
|
261
|
+
cancelButton.style.transform = 'translateY(0) scale(0.985)';
|
|
262
|
+
};
|
|
263
|
+
cancelButton.addEventListener('mouseenter', liftCancelButton);
|
|
264
|
+
cancelButton.addEventListener('focus', liftCancelButton);
|
|
265
|
+
cancelButton.addEventListener('mouseleave', resetCancelButton);
|
|
266
|
+
cancelButton.addEventListener('blur', resetCancelButton);
|
|
267
|
+
cancelButton.addEventListener('mouseup', liftCancelButton);
|
|
268
|
+
cancelButton.addEventListener('mousedown', pressCancelButton);
|
|
269
|
+
cancelButton.addEventListener('click', onCancel);
|
|
270
|
+
shell.appendChild(iframe);
|
|
271
|
+
shell.appendChild(cancelButton);
|
|
272
|
+
return { shell, iframe, cancelButton };
|
|
273
|
+
}
|
|
274
|
+
function normalizeThreeDSFrameSize(data) {
|
|
275
|
+
if (!data || typeof data !== 'object') {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
const raw = data;
|
|
279
|
+
const next = {};
|
|
280
|
+
if (typeof raw.width === 'number' && Number.isFinite(raw.width) && raw.width > 0) {
|
|
281
|
+
next.width = raw.width;
|
|
282
|
+
}
|
|
283
|
+
if (typeof raw.height === 'number' && Number.isFinite(raw.height) && raw.height > 0) {
|
|
284
|
+
next.height = raw.height;
|
|
285
|
+
}
|
|
286
|
+
return next.width || next.height ? next : null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
class ThreeDSModalController {
|
|
290
|
+
constructor(options) {
|
|
291
|
+
this.options = options;
|
|
292
|
+
this.modal = null;
|
|
293
|
+
this.shell = null;
|
|
294
|
+
this.iframe = null;
|
|
295
|
+
this.frameSize = {};
|
|
296
|
+
this.resizeHandler = null;
|
|
297
|
+
this.pendingData = null;
|
|
298
|
+
}
|
|
299
|
+
show(data) {
|
|
300
|
+
this.close();
|
|
301
|
+
this.modal = createThreeDSModalBackdrop(this.options.modalId);
|
|
302
|
+
this.shell = createThreeDSFrameShell(() => this.options.onCancel());
|
|
303
|
+
this.iframe = this.shell.iframe;
|
|
304
|
+
this.iframe.src = this.options.buildUrl(data);
|
|
305
|
+
this.frameSize = {};
|
|
306
|
+
this.applySize();
|
|
307
|
+
this.modal.appendChild(this.shell.shell);
|
|
308
|
+
document.body.appendChild(this.modal);
|
|
309
|
+
this.resizeHandler = () => this.applySize();
|
|
310
|
+
window.addEventListener('resize', this.resizeHandler);
|
|
311
|
+
window.addEventListener('orientationchange', this.resizeHandler);
|
|
312
|
+
window.visualViewport?.addEventListener('resize', this.resizeHandler);
|
|
313
|
+
this.pendingData = data;
|
|
314
|
+
}
|
|
315
|
+
handleFrameResize(evt, data) {
|
|
316
|
+
if (!this.iframe?.contentWindow || evt.source !== this.iframe.contentWindow) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const nextSize = normalizeThreeDSFrameSize(data);
|
|
320
|
+
if (!nextSize) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
this.frameSize = {
|
|
324
|
+
...this.frameSize,
|
|
325
|
+
...nextSize,
|
|
326
|
+
};
|
|
327
|
+
this.applySize();
|
|
328
|
+
}
|
|
329
|
+
handleReady() {
|
|
330
|
+
if (!this.pendingData || !this.iframe?.contentWindow) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
this.options.onReady(this.iframe, this.pendingData);
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
close() {
|
|
337
|
+
if (this.resizeHandler) {
|
|
338
|
+
window.removeEventListener('resize', this.resizeHandler);
|
|
339
|
+
window.removeEventListener('orientationchange', this.resizeHandler);
|
|
340
|
+
window.visualViewport?.removeEventListener('resize', this.resizeHandler);
|
|
341
|
+
this.resizeHandler = null;
|
|
342
|
+
}
|
|
343
|
+
if (this.modal) {
|
|
344
|
+
this.modal.remove();
|
|
345
|
+
this.modal = null;
|
|
346
|
+
}
|
|
347
|
+
this.shell = null;
|
|
348
|
+
this.iframe = null;
|
|
349
|
+
this.frameSize = {};
|
|
350
|
+
this.pendingData = null;
|
|
351
|
+
}
|
|
352
|
+
applySize() {
|
|
353
|
+
applyThreeDSFrameSize(this.modal, this.iframe, this.frameSize, this.shell?.shell);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
130
357
|
/**
|
|
131
358
|
* Supported locales for Paypercut Checkout
|
|
132
359
|
*
|
|
@@ -487,9 +714,6 @@ class ExpressCheckoutImpl {
|
|
|
487
714
|
* Regenerated on each wallet button click so retries get a fresh key.
|
|
488
715
|
*/
|
|
489
716
|
this.idempotencyKey = generateId();
|
|
490
|
-
// 3DS modal — same pattern as CheckoutImpl
|
|
491
|
-
this.threeDSModal = null;
|
|
492
|
-
this.threeDSIframe = null;
|
|
493
717
|
// Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
|
|
494
718
|
// Shown after loadPaymentData() resolves
|
|
495
719
|
this.pending3DSAfterGpay = null;
|
|
@@ -518,6 +742,12 @@ class ExpressCheckoutImpl {
|
|
|
518
742
|
this.pendingGpayShippingOption = undefined;
|
|
519
743
|
this.currentShippingOptions = options.shippingOptions ?? [];
|
|
520
744
|
this.messageHandler = this.onMessage.bind(this);
|
|
745
|
+
this.threeDSModal = new ThreeDSModalController({
|
|
746
|
+
modalId: 'paypercut-express-3ds-modal',
|
|
747
|
+
buildUrl: (data) => this.buildThreeDSUrl(data),
|
|
748
|
+
onCancel: () => this.handle3DSShellCancel(),
|
|
749
|
+
onReady: (iframe) => this.postThreeDSInit(iframe),
|
|
750
|
+
});
|
|
521
751
|
window.addEventListener('message', this.messageHandler);
|
|
522
752
|
}
|
|
523
753
|
// ─── URL builders
|
|
@@ -689,6 +919,9 @@ class ExpressCheckoutImpl {
|
|
|
689
919
|
}
|
|
690
920
|
break;
|
|
691
921
|
// 3DS flow
|
|
922
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
923
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
924
|
+
break;
|
|
692
925
|
case 'THREEDS_START_FLOW':
|
|
693
926
|
// Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
|
|
694
927
|
// Resolve the pending GPay promise so GPay starts closing its sheet.
|
|
@@ -700,7 +933,7 @@ class ExpressCheckoutImpl {
|
|
|
700
933
|
}
|
|
701
934
|
else {
|
|
702
935
|
// Apple Pay or any path without a pending GPay sheet — show immediately
|
|
703
|
-
this.
|
|
936
|
+
this.threeDSModal.show(data);
|
|
704
937
|
}
|
|
705
938
|
break;
|
|
706
939
|
case 'THREEDS_READY':
|
|
@@ -710,7 +943,7 @@ class ExpressCheckoutImpl {
|
|
|
710
943
|
case 'THREEDS_CANCELED':
|
|
711
944
|
case 'THREEDS_ERROR':
|
|
712
945
|
this.postToTokenizeIframe(data);
|
|
713
|
-
this.
|
|
946
|
+
this.threeDSModal.close();
|
|
714
947
|
break;
|
|
715
948
|
}
|
|
716
949
|
}
|
|
@@ -1413,7 +1646,7 @@ class ExpressCheckoutImpl {
|
|
|
1413
1646
|
if (this.pending3DSAfterGpay) {
|
|
1414
1647
|
const threeDSData = this.pending3DSAfterGpay;
|
|
1415
1648
|
this.pending3DSAfterGpay = null;
|
|
1416
|
-
this.
|
|
1649
|
+
this.threeDSModal.show(threeDSData);
|
|
1417
1650
|
}
|
|
1418
1651
|
}
|
|
1419
1652
|
catch (e) {
|
|
@@ -1627,7 +1860,7 @@ class ExpressCheckoutImpl {
|
|
|
1627
1860
|
this.layoutResizeObserver.disconnect();
|
|
1628
1861
|
this.layoutResizeObserver = null;
|
|
1629
1862
|
}
|
|
1630
|
-
this.
|
|
1863
|
+
this.threeDSModal.close();
|
|
1631
1864
|
this.abortApplePaySession();
|
|
1632
1865
|
this.sessionActive = false;
|
|
1633
1866
|
this.mounted = false;
|
|
@@ -1735,23 +1968,8 @@ class ExpressCheckoutImpl {
|
|
|
1735
1968
|
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1736
1969
|
this.tokenizeIframe.contentWindow.postMessage(message, origin);
|
|
1737
1970
|
}
|
|
1738
|
-
// ─── 3DS modal
|
|
1739
|
-
|
|
1740
|
-
this.threeDSModal = document.createElement('div');
|
|
1741
|
-
this.threeDSModal.id = 'paypercut-express-3ds-modal';
|
|
1742
|
-
Object.assign(this.threeDSModal.style, {
|
|
1743
|
-
position: 'fixed',
|
|
1744
|
-
top: '0',
|
|
1745
|
-
left: '0',
|
|
1746
|
-
width: '100%',
|
|
1747
|
-
height: '100%',
|
|
1748
|
-
display: 'flex',
|
|
1749
|
-
alignItems: 'center',
|
|
1750
|
-
justifyContent: 'center',
|
|
1751
|
-
zIndex: '999999',
|
|
1752
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
1753
|
-
});
|
|
1754
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
1971
|
+
// ─── 3DS modal ──────────
|
|
1972
|
+
buildThreeDSUrl(data) {
|
|
1755
1973
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1756
1974
|
const threeDSUrl = new URL('/express/threeds', checkoutOrigin);
|
|
1757
1975
|
threeDSUrl.searchParams.set('instanceId', this.instanceId);
|
|
@@ -1764,37 +1982,25 @@ class ExpressCheckoutImpl {
|
|
|
1764
1982
|
if (data.threeDSVersion)
|
|
1765
1983
|
threeDSUrl.searchParams.set('threeDSVersion', data.threeDSVersion);
|
|
1766
1984
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
borderRadius: '8px',
|
|
1775
|
-
display: 'block',
|
|
1776
|
-
background: 'transparent',
|
|
1985
|
+
return threeDSUrl.toString();
|
|
1986
|
+
}
|
|
1987
|
+
handle3DSShellCancel() {
|
|
1988
|
+
this.postToTokenizeIframe({
|
|
1989
|
+
type: 'THREEDS_CANCELED',
|
|
1990
|
+
instanceId: this.instanceId,
|
|
1991
|
+
error: 'User canceled 3DS authentication',
|
|
1777
1992
|
});
|
|
1778
|
-
this.threeDSModal.
|
|
1779
|
-
|
|
1780
|
-
this._pending3DSData = data;
|
|
1993
|
+
this.threeDSModal.close();
|
|
1994
|
+
this.emitter.emit(exports.ExpressSdkEvent.Cancel);
|
|
1781
1995
|
}
|
|
1782
1996
|
handle3DSReady() {
|
|
1783
|
-
|
|
1784
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
1997
|
+
if (!this.threeDSModal.handleReady()) {
|
|
1785
1998
|
console.error('[PaypercutExpressCheckout] No pending 3DS data or iframe not ready');
|
|
1786
|
-
return;
|
|
1787
1999
|
}
|
|
1788
|
-
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1789
|
-
this.threeDSIframe.contentWindow.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1790
2000
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
this.threeDSModal = null;
|
|
1795
|
-
}
|
|
1796
|
-
this.threeDSIframe = null;
|
|
1797
|
-
delete this._pending3DSData;
|
|
2001
|
+
postThreeDSInit(iframe) {
|
|
2002
|
+
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2003
|
+
iframe.contentWindow?.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1798
2004
|
}
|
|
1799
2005
|
}
|
|
1800
2006
|
//Factory
|
|
@@ -1812,11 +2018,14 @@ class CheckoutImpl {
|
|
|
1812
2018
|
this.mounted = false;
|
|
1813
2019
|
this.destroyed = false;
|
|
1814
2020
|
this.iframe = null;
|
|
1815
|
-
// 3DS Modal state
|
|
1816
|
-
this.threeDSModal = null;
|
|
1817
|
-
this.threeDSIframe = null;
|
|
1818
2021
|
// Bind message handler
|
|
1819
2022
|
this.messageHandler = this.onMessage.bind(this);
|
|
2023
|
+
this.threeDSModal = new ThreeDSModalController({
|
|
2024
|
+
modalId: 'paypercut-3ds-modal',
|
|
2025
|
+
buildUrl: (data) => this.buildThreeDSUrl(data),
|
|
2026
|
+
onCancel: () => this.handle3DSShellCancel(),
|
|
2027
|
+
onReady: (iframe) => this.postThreeDSInit(iframe),
|
|
2028
|
+
});
|
|
1820
2029
|
window.addEventListener('message', this.messageHandler);
|
|
1821
2030
|
}
|
|
1822
2031
|
/**
|
|
@@ -1937,8 +2146,11 @@ class CheckoutImpl {
|
|
|
1937
2146
|
this.emitter.emit(exports.SdkEvent.Resize, data.height);
|
|
1938
2147
|
this.handleResize(data.height);
|
|
1939
2148
|
break;
|
|
2149
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
2150
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
2151
|
+
break;
|
|
1940
2152
|
case 'THREEDS_START_FLOW':
|
|
1941
|
-
this.
|
|
2153
|
+
this.threeDSModal.show(data);
|
|
1942
2154
|
this.emitter.emit(exports.SdkEvent.ThreeDSStarted);
|
|
1943
2155
|
break;
|
|
1944
2156
|
case 'THREEDS_READY':
|
|
@@ -1946,17 +2158,17 @@ class CheckoutImpl {
|
|
|
1946
2158
|
break;
|
|
1947
2159
|
case 'THREEDS_COMPLETE':
|
|
1948
2160
|
this.postToIframe(data);
|
|
1949
|
-
this.
|
|
2161
|
+
this.threeDSModal.close();
|
|
1950
2162
|
this.emitter.emit(exports.SdkEvent.ThreeDSComplete);
|
|
1951
2163
|
break;
|
|
1952
2164
|
case 'THREEDS_CANCELED':
|
|
1953
2165
|
this.postToIframe(data);
|
|
1954
|
-
this.
|
|
2166
|
+
this.threeDSModal.close();
|
|
1955
2167
|
this.emitter.emit(exports.SdkEvent.ThreeDSCanceled);
|
|
1956
2168
|
break;
|
|
1957
2169
|
case 'THREEDS_ERROR':
|
|
1958
2170
|
this.postToIframe(data);
|
|
1959
|
-
this.
|
|
2171
|
+
this.threeDSModal.close();
|
|
1960
2172
|
this.emitter.emit(exports.SdkEvent.ThreeDSError, data.error);
|
|
1961
2173
|
break;
|
|
1962
2174
|
case 'FORM_VALIDATION':
|
|
@@ -2046,27 +2258,7 @@ class CheckoutImpl {
|
|
|
2046
2258
|
// Set iframe height to match content
|
|
2047
2259
|
this.iframe.style.height = `${height}px`;
|
|
2048
2260
|
}
|
|
2049
|
-
|
|
2050
|
-
* Show 3DS modal with challenge/decoupled flow
|
|
2051
|
-
*/
|
|
2052
|
-
show3DSModal(data) {
|
|
2053
|
-
// Create modal backdrop
|
|
2054
|
-
this.threeDSModal = document.createElement('div');
|
|
2055
|
-
this.threeDSModal.id = 'paypercut-3ds-modal';
|
|
2056
|
-
Object.assign(this.threeDSModal.style, {
|
|
2057
|
-
position: 'fixed',
|
|
2058
|
-
top: '0',
|
|
2059
|
-
left: '0',
|
|
2060
|
-
width: '100%',
|
|
2061
|
-
height: '100%',
|
|
2062
|
-
display: 'flex',
|
|
2063
|
-
alignItems: 'center',
|
|
2064
|
-
justifyContent: 'center',
|
|
2065
|
-
zIndex: '999999',
|
|
2066
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
2067
|
-
});
|
|
2068
|
-
// Create iframe for 3DS page
|
|
2069
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
2261
|
+
buildThreeDSUrl(data) {
|
|
2070
2262
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2071
2263
|
// Build URL: baseUrl/c/{checkoutId}/threeds with query params
|
|
2072
2264
|
const threeDSUrl = new URL(`/c/${this.options.id}/threeds`, checkoutOrigin);
|
|
@@ -2083,50 +2275,32 @@ class CheckoutImpl {
|
|
|
2083
2275
|
}
|
|
2084
2276
|
// Always include liveMode; default to false when undefined
|
|
2085
2277
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
border: 'none',
|
|
2094
|
-
borderRadius: '8px',
|
|
2095
|
-
display: 'block',
|
|
2096
|
-
background: 'transparent',
|
|
2278
|
+
return threeDSUrl.toString();
|
|
2279
|
+
}
|
|
2280
|
+
handle3DSShellCancel() {
|
|
2281
|
+
this.postToIframe({
|
|
2282
|
+
type: 'THREEDS_CANCELED',
|
|
2283
|
+
checkoutId: this.options.id,
|
|
2284
|
+
reason: 'sdk_shell_cancel',
|
|
2097
2285
|
});
|
|
2098
|
-
|
|
2099
|
-
this.
|
|
2100
|
-
document.body.appendChild(this.threeDSModal);
|
|
2101
|
-
// Store 3DS data for later use
|
|
2102
|
-
this.pending3DSData = data;
|
|
2286
|
+
this.threeDSModal.close();
|
|
2287
|
+
this.emitter.emit(exports.SdkEvent.ThreeDSCanceled);
|
|
2103
2288
|
}
|
|
2104
2289
|
/**
|
|
2105
2290
|
* Handle THREEDS_READY message - send THREEDS_INIT with challenge data
|
|
2106
2291
|
*/
|
|
2107
2292
|
handle3DSReady() {
|
|
2108
|
-
|
|
2109
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
2293
|
+
if (!this.threeDSModal.handleReady()) {
|
|
2110
2294
|
console.error('[PaypercutCheckout] No pending 3DS data or iframe not ready');
|
|
2111
|
-
return;
|
|
2112
2295
|
}
|
|
2296
|
+
}
|
|
2297
|
+
postThreeDSInit(iframe) {
|
|
2113
2298
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2114
|
-
|
|
2299
|
+
iframe.contentWindow?.postMessage({
|
|
2115
2300
|
type: 'THREEDS_INIT',
|
|
2116
2301
|
checkoutId: this.options.id,
|
|
2117
2302
|
}, checkoutOrigin);
|
|
2118
2303
|
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Close 3DS modal and cleanup
|
|
2121
|
-
*/
|
|
2122
|
-
close3DSModal() {
|
|
2123
|
-
if (this.threeDSModal) {
|
|
2124
|
-
this.threeDSModal.remove();
|
|
2125
|
-
this.threeDSModal = null;
|
|
2126
|
-
}
|
|
2127
|
-
this.threeDSIframe = null;
|
|
2128
|
-
delete this.pending3DSData;
|
|
2129
|
-
}
|
|
2130
2304
|
/**
|
|
2131
2305
|
* Destroy the checkout instance and cleanup (idempotent)
|
|
2132
2306
|
*/
|
|
@@ -2146,7 +2320,7 @@ class CheckoutImpl {
|
|
|
2146
2320
|
}
|
|
2147
2321
|
}
|
|
2148
2322
|
// Cleanup 3DS modal if open
|
|
2149
|
-
this.
|
|
2323
|
+
this.threeDSModal.close();
|
|
2150
2324
|
// Only set mounted = false after successful DOM removal
|
|
2151
2325
|
this.mounted = false;
|
|
2152
2326
|
this.destroyed = true;
|