@paypercut/checkout-js 1.1.10 → 1.2.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 CHANGED
@@ -276,6 +276,7 @@ Subscribe to events using the `on()` method. You can use string event names or t
276
276
  | Event | Enum | Description | Payload |
277
277
  |-------|------|-------------|---------|
278
278
  | `loaded` | `SdkEvent.Loaded` | Checkout iframe has finished loading | `void` |
279
+ | `processing` | `SdkEvent.Processing` | Payment processing has started inside the hosted checkout | `{ checkoutId: string }` |
279
280
  | `success` | `SdkEvent.Success` | Payment completed successfully | `PaymentSuccessPayload` |
280
281
  | `error` | `SdkEvent.Error` | Terminal failure (tokenize, confirm, or 3DS) | `ApiErrorPayload` |
281
282
  | `expired` | `SdkEvent.Expired` | Checkout session expired | `void` |
@@ -295,6 +296,10 @@ checkout.on('loaded', () => {
295
296
  console.log('Checkout loaded');
296
297
  });
297
298
 
299
+ checkout.on('processing', ({ checkoutId }) => {
300
+ console.log('Payment processing started for checkout:', checkoutId);
301
+ });
302
+
298
303
  checkout.on('success', (payload) => {
299
304
  // PaymentSuccessPayload
300
305
  console.log('Payment successful');
@@ -323,6 +328,10 @@ checkout.on(SdkEvent.Loaded, () => {
323
328
  console.log('Checkout loaded');
324
329
  });
325
330
 
331
+ checkout.on(SdkEvent.Processing, ({ checkoutId }) => {
332
+ console.log('Payment processing started for checkout:', checkoutId);
333
+ });
334
+
326
335
  checkout.on(SdkEvent.Success, (payload) => {
327
336
  console.log('Payment successful', payload.payment_method);
328
337
  });
@@ -413,6 +422,7 @@ checkout.on('error', (err) => {
413
422
  ### Notes
414
423
 
415
424
  - `error`: the SDK forwards a normalized `ApiErrorPayload` when provided by Hosted Checkout.
425
+ - `processing`: non-terminal event. Use it to disable close buttons or show "do not close" messaging, then clear that UI on `success`, `error`, `cancel`, or `expired`.
416
426
  - `threeds_error`: forwards `payload.error` when available; otherwise the raw message data.
417
427
  - `three![img.png](img.png)ds_*` non-error events: payload is forwarded as-is from Hosted Checkout (shape may evolve).
418
428
 
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.1.10",
94
+ version: "1.2.1",
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
  *
@@ -293,6 +520,7 @@ function validateUIMode(mode) {
293
520
  exports.SdkEvent = void 0;
294
521
  (function (SdkEvent) {
295
522
  SdkEvent["Loaded"] = "loaded";
523
+ SdkEvent["Processing"] = "processing";
296
524
  SdkEvent["Success"] = "success";
297
525
  SdkEvent["Error"] = "error";
298
526
  SdkEvent["Expired"] = "expired";
@@ -486,9 +714,6 @@ class ExpressCheckoutImpl {
486
714
  * Regenerated on each wallet button click so retries get a fresh key.
487
715
  */
488
716
  this.idempotencyKey = generateId();
489
- // 3DS modal — same pattern as CheckoutImpl
490
- this.threeDSModal = null;
491
- this.threeDSIframe = null;
492
717
  // Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
493
718
  // Shown after loadPaymentData() resolves
494
719
  this.pending3DSAfterGpay = null;
@@ -517,6 +742,12 @@ class ExpressCheckoutImpl {
517
742
  this.pendingGpayShippingOption = undefined;
518
743
  this.currentShippingOptions = options.shippingOptions ?? [];
519
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
+ });
520
751
  window.addEventListener('message', this.messageHandler);
521
752
  }
522
753
  // ─── URL builders
@@ -688,6 +919,9 @@ class ExpressCheckoutImpl {
688
919
  }
689
920
  break;
690
921
  // 3DS flow
922
+ case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
923
+ this.threeDSModal.handleFrameResize(evt, data);
924
+ break;
691
925
  case 'THREEDS_START_FLOW':
692
926
  // Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
693
927
  // Resolve the pending GPay promise so GPay starts closing its sheet.
@@ -699,7 +933,7 @@ class ExpressCheckoutImpl {
699
933
  }
700
934
  else {
701
935
  // Apple Pay or any path without a pending GPay sheet — show immediately
702
- this.show3DSModal(data);
936
+ this.threeDSModal.show(data);
703
937
  }
704
938
  break;
705
939
  case 'THREEDS_READY':
@@ -709,7 +943,7 @@ class ExpressCheckoutImpl {
709
943
  case 'THREEDS_CANCELED':
710
944
  case 'THREEDS_ERROR':
711
945
  this.postToTokenizeIframe(data);
712
- this.close3DSModal();
946
+ this.threeDSModal.close();
713
947
  break;
714
948
  }
715
949
  }
@@ -1412,7 +1646,7 @@ class ExpressCheckoutImpl {
1412
1646
  if (this.pending3DSAfterGpay) {
1413
1647
  const threeDSData = this.pending3DSAfterGpay;
1414
1648
  this.pending3DSAfterGpay = null;
1415
- this.show3DSModal(threeDSData);
1649
+ this.threeDSModal.show(threeDSData);
1416
1650
  }
1417
1651
  }
1418
1652
  catch (e) {
@@ -1626,7 +1860,7 @@ class ExpressCheckoutImpl {
1626
1860
  this.layoutResizeObserver.disconnect();
1627
1861
  this.layoutResizeObserver = null;
1628
1862
  }
1629
- this.close3DSModal();
1863
+ this.threeDSModal.close();
1630
1864
  this.abortApplePaySession();
1631
1865
  this.sessionActive = false;
1632
1866
  this.mounted = false;
@@ -1734,23 +1968,8 @@ class ExpressCheckoutImpl {
1734
1968
  const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1735
1969
  this.tokenizeIframe.contentWindow.postMessage(message, origin);
1736
1970
  }
1737
- // ─── 3DS modal (mirrors CheckoutImpl) ──────────
1738
- show3DSModal(data) {
1739
- this.threeDSModal = document.createElement('div');
1740
- this.threeDSModal.id = 'paypercut-express-3ds-modal';
1741
- Object.assign(this.threeDSModal.style, {
1742
- position: 'fixed',
1743
- top: '0',
1744
- left: '0',
1745
- width: '100%',
1746
- height: '100%',
1747
- display: 'flex',
1748
- alignItems: 'center',
1749
- justifyContent: 'center',
1750
- zIndex: '999999',
1751
- background: 'rgba(0, 0, 0, 0.4)',
1752
- });
1753
- this.threeDSIframe = document.createElement('iframe');
1971
+ // ─── 3DS modal ──────────
1972
+ buildThreeDSUrl(data) {
1754
1973
  const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1755
1974
  const threeDSUrl = new URL('/express/threeds', checkoutOrigin);
1756
1975
  threeDSUrl.searchParams.set('instanceId', this.instanceId);
@@ -1763,37 +1982,25 @@ class ExpressCheckoutImpl {
1763
1982
  if (data.threeDSVersion)
1764
1983
  threeDSUrl.searchParams.set('threeDSVersion', data.threeDSVersion);
1765
1984
  threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
1766
- this.threeDSIframe.src = threeDSUrl.toString();
1767
- this.threeDSIframe.allow = 'payment *';
1768
- this.threeDSIframe.setAttribute('frameborder', '0');
1769
- Object.assign(this.threeDSIframe.style, {
1770
- minWidth: '400px',
1771
- minHeight: '400px',
1772
- border: 'none',
1773
- borderRadius: '8px',
1774
- display: 'block',
1775
- 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',
1776
1992
  });
1777
- this.threeDSModal.appendChild(this.threeDSIframe);
1778
- document.body.appendChild(this.threeDSModal);
1779
- this._pending3DSData = data;
1993
+ this.threeDSModal.close();
1994
+ this.emitter.emit(exports.ExpressSdkEvent.Cancel);
1780
1995
  }
1781
1996
  handle3DSReady() {
1782
- const data = this._pending3DSData;
1783
- if (!data || !this.threeDSIframe?.contentWindow) {
1997
+ if (!this.threeDSModal.handleReady()) {
1784
1998
  console.error('[PaypercutExpressCheckout] No pending 3DS data or iframe not ready');
1785
- return;
1786
1999
  }
1787
- const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1788
- this.threeDSIframe.contentWindow.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
1789
2000
  }
1790
- close3DSModal() {
1791
- if (this.threeDSModal) {
1792
- this.threeDSModal.remove();
1793
- this.threeDSModal = null;
1794
- }
1795
- this.threeDSIframe = null;
1796
- delete this._pending3DSData;
2001
+ postThreeDSInit(iframe) {
2002
+ const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
2003
+ iframe.contentWindow?.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
1797
2004
  }
1798
2005
  }
1799
2006
  //Factory
@@ -1811,11 +2018,14 @@ class CheckoutImpl {
1811
2018
  this.mounted = false;
1812
2019
  this.destroyed = false;
1813
2020
  this.iframe = null;
1814
- // 3DS Modal state
1815
- this.threeDSModal = null;
1816
- this.threeDSIframe = null;
1817
2021
  // Bind message handler
1818
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
+ });
1819
2029
  window.addEventListener('message', this.messageHandler);
1820
2030
  }
1821
2031
  /**
@@ -1910,6 +2120,11 @@ class CheckoutImpl {
1910
2120
  case 'CHECKOUT_LOADED':
1911
2121
  this.emitter.emit(exports.SdkEvent.Loaded);
1912
2122
  break;
2123
+ case 'CHECKOUT_PROCESSING':
2124
+ this.emitter.emit(exports.SdkEvent.Processing, {
2125
+ checkoutId: data.checkoutId,
2126
+ });
2127
+ break;
1913
2128
  case 'CHECKOUT_SUCCESS':
1914
2129
  const { payment_method = {}, payment = null } = data;
1915
2130
  this.emitter.emit(exports.SdkEvent.Success, { payment_method, payment });
@@ -1931,8 +2146,11 @@ class CheckoutImpl {
1931
2146
  this.emitter.emit(exports.SdkEvent.Resize, data.height);
1932
2147
  this.handleResize(data.height);
1933
2148
  break;
2149
+ case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
2150
+ this.threeDSModal.handleFrameResize(evt, data);
2151
+ break;
1934
2152
  case 'THREEDS_START_FLOW':
1935
- this.show3DSModal(data);
2153
+ this.threeDSModal.show(data);
1936
2154
  this.emitter.emit(exports.SdkEvent.ThreeDSStarted);
1937
2155
  break;
1938
2156
  case 'THREEDS_READY':
@@ -1940,17 +2158,17 @@ class CheckoutImpl {
1940
2158
  break;
1941
2159
  case 'THREEDS_COMPLETE':
1942
2160
  this.postToIframe(data);
1943
- this.close3DSModal();
2161
+ this.threeDSModal.close();
1944
2162
  this.emitter.emit(exports.SdkEvent.ThreeDSComplete);
1945
2163
  break;
1946
2164
  case 'THREEDS_CANCELED':
1947
2165
  this.postToIframe(data);
1948
- this.close3DSModal();
2166
+ this.threeDSModal.close();
1949
2167
  this.emitter.emit(exports.SdkEvent.ThreeDSCanceled);
1950
2168
  break;
1951
2169
  case 'THREEDS_ERROR':
1952
2170
  this.postToIframe(data);
1953
- this.close3DSModal();
2171
+ this.threeDSModal.close();
1954
2172
  this.emitter.emit(exports.SdkEvent.ThreeDSError, data.error);
1955
2173
  break;
1956
2174
  case 'FORM_VALIDATION':
@@ -2040,27 +2258,7 @@ class CheckoutImpl {
2040
2258
  // Set iframe height to match content
2041
2259
  this.iframe.style.height = `${height}px`;
2042
2260
  }
2043
- /**
2044
- * Show 3DS modal with challenge/decoupled flow
2045
- */
2046
- show3DSModal(data) {
2047
- // Create modal backdrop
2048
- this.threeDSModal = document.createElement('div');
2049
- this.threeDSModal.id = 'paypercut-3ds-modal';
2050
- Object.assign(this.threeDSModal.style, {
2051
- position: 'fixed',
2052
- top: '0',
2053
- left: '0',
2054
- width: '100%',
2055
- height: '100%',
2056
- display: 'flex',
2057
- alignItems: 'center',
2058
- justifyContent: 'center',
2059
- zIndex: '999999',
2060
- background: 'rgba(0, 0, 0, 0.4)',
2061
- });
2062
- // Create iframe for 3DS page
2063
- this.threeDSIframe = document.createElement('iframe');
2261
+ buildThreeDSUrl(data) {
2064
2262
  const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
2065
2263
  // Build URL: baseUrl/c/{checkoutId}/threeds with query params
2066
2264
  const threeDSUrl = new URL(`/c/${this.options.id}/threeds`, checkoutOrigin);
@@ -2077,50 +2275,32 @@ class CheckoutImpl {
2077
2275
  }
2078
2276
  // Always include liveMode; default to false when undefined
2079
2277
  threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
2080
- this.threeDSIframe.src = threeDSUrl.toString();
2081
- this.threeDSIframe.allow = 'payment *';
2082
- this.threeDSIframe.setAttribute('frameborder', '0');
2083
- // Fixed dimensions: follow 3DS component size (500x500)
2084
- Object.assign(this.threeDSIframe.style, {
2085
- minWidth: '400px',
2086
- minHeight: '400px',
2087
- border: 'none',
2088
- borderRadius: '8px',
2089
- display: 'block',
2090
- 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',
2091
2285
  });
2092
- // Append iframe directly to modal backdrop
2093
- this.threeDSModal.appendChild(this.threeDSIframe);
2094
- document.body.appendChild(this.threeDSModal);
2095
- // Store 3DS data for later use
2096
- this.pending3DSData = data;
2286
+ this.threeDSModal.close();
2287
+ this.emitter.emit(exports.SdkEvent.ThreeDSCanceled);
2097
2288
  }
2098
2289
  /**
2099
2290
  * Handle THREEDS_READY message - send THREEDS_INIT with challenge data
2100
2291
  */
2101
2292
  handle3DSReady() {
2102
- const data = this.pending3DSData;
2103
- if (!data || !this.threeDSIframe?.contentWindow) {
2293
+ if (!this.threeDSModal.handleReady()) {
2104
2294
  console.error('[PaypercutCheckout] No pending 3DS data or iframe not ready');
2105
- return;
2106
2295
  }
2296
+ }
2297
+ postThreeDSInit(iframe) {
2107
2298
  const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
2108
- this.threeDSIframe.contentWindow.postMessage({
2299
+ iframe.contentWindow?.postMessage({
2109
2300
  type: 'THREEDS_INIT',
2110
2301
  checkoutId: this.options.id,
2111
2302
  }, checkoutOrigin);
2112
2303
  }
2113
- /**
2114
- * Close 3DS modal and cleanup
2115
- */
2116
- close3DSModal() {
2117
- if (this.threeDSModal) {
2118
- this.threeDSModal.remove();
2119
- this.threeDSModal = null;
2120
- }
2121
- this.threeDSIframe = null;
2122
- delete this.pending3DSData;
2123
- }
2124
2304
  /**
2125
2305
  * Destroy the checkout instance and cleanup (idempotent)
2126
2306
  */
@@ -2140,7 +2320,7 @@ class CheckoutImpl {
2140
2320
  }
2141
2321
  }
2142
2322
  // Cleanup 3DS modal if open
2143
- this.close3DSModal();
2323
+ this.threeDSModal.close();
2144
2324
  // Only set mounted = false after successful DOM removal
2145
2325
  this.mounted = false;
2146
2326
  this.destroyed = true;