@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 +10 -0
- package/dist/index.cjs +290 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +290 -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.d.ts
CHANGED
|
@@ -130,12 +130,13 @@ interface CancelPayload {
|
|
|
130
130
|
/**
|
|
131
131
|
* Event names that can be emitted by the checkout
|
|
132
132
|
*/
|
|
133
|
-
type EventName = 'loaded' | 'success' | 'error' | 'expired' | 'resize' | 'threeds_complete' | 'threeds_error' | 'threeds_canceled' | 'threeds_started' | 'cancel' | 'form_validation';
|
|
133
|
+
type EventName = 'loaded' | 'processing' | 'success' | 'error' | 'expired' | 'resize' | 'threeds_complete' | 'threeds_error' | 'threeds_canceled' | 'threeds_started' | 'cancel' | 'form_validation';
|
|
134
134
|
/**
|
|
135
135
|
* Preferred enum for SDK event names (use instead of hardcoded strings)
|
|
136
136
|
*/
|
|
137
137
|
declare enum SdkEvent {
|
|
138
138
|
Loaded = "loaded",
|
|
139
|
+
Processing = "processing",
|
|
139
140
|
Success = "success",
|
|
140
141
|
Error = "error",
|
|
141
142
|
Expired = "expired",
|
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.1
|
|
90
|
+
version: "1.2.1",
|
|
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
|
*
|
|
@@ -289,6 +516,7 @@ function validateUIMode(mode) {
|
|
|
289
516
|
var SdkEvent;
|
|
290
517
|
(function (SdkEvent) {
|
|
291
518
|
SdkEvent["Loaded"] = "loaded";
|
|
519
|
+
SdkEvent["Processing"] = "processing";
|
|
292
520
|
SdkEvent["Success"] = "success";
|
|
293
521
|
SdkEvent["Error"] = "error";
|
|
294
522
|
SdkEvent["Expired"] = "expired";
|
|
@@ -482,9 +710,6 @@ class ExpressCheckoutImpl {
|
|
|
482
710
|
* Regenerated on each wallet button click so retries get a fresh key.
|
|
483
711
|
*/
|
|
484
712
|
this.idempotencyKey = generateId();
|
|
485
|
-
// 3DS modal — same pattern as CheckoutImpl
|
|
486
|
-
this.threeDSModal = null;
|
|
487
|
-
this.threeDSIframe = null;
|
|
488
713
|
// Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
|
|
489
714
|
// Shown after loadPaymentData() resolves
|
|
490
715
|
this.pending3DSAfterGpay = null;
|
|
@@ -513,6 +738,12 @@ class ExpressCheckoutImpl {
|
|
|
513
738
|
this.pendingGpayShippingOption = undefined;
|
|
514
739
|
this.currentShippingOptions = options.shippingOptions ?? [];
|
|
515
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
|
+
});
|
|
516
747
|
window.addEventListener('message', this.messageHandler);
|
|
517
748
|
}
|
|
518
749
|
// ─── URL builders
|
|
@@ -684,6 +915,9 @@ class ExpressCheckoutImpl {
|
|
|
684
915
|
}
|
|
685
916
|
break;
|
|
686
917
|
// 3DS flow
|
|
918
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
919
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
920
|
+
break;
|
|
687
921
|
case 'THREEDS_START_FLOW':
|
|
688
922
|
// Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
|
|
689
923
|
// Resolve the pending GPay promise so GPay starts closing its sheet.
|
|
@@ -695,7 +929,7 @@ class ExpressCheckoutImpl {
|
|
|
695
929
|
}
|
|
696
930
|
else {
|
|
697
931
|
// Apple Pay or any path without a pending GPay sheet — show immediately
|
|
698
|
-
this.
|
|
932
|
+
this.threeDSModal.show(data);
|
|
699
933
|
}
|
|
700
934
|
break;
|
|
701
935
|
case 'THREEDS_READY':
|
|
@@ -705,7 +939,7 @@ class ExpressCheckoutImpl {
|
|
|
705
939
|
case 'THREEDS_CANCELED':
|
|
706
940
|
case 'THREEDS_ERROR':
|
|
707
941
|
this.postToTokenizeIframe(data);
|
|
708
|
-
this.
|
|
942
|
+
this.threeDSModal.close();
|
|
709
943
|
break;
|
|
710
944
|
}
|
|
711
945
|
}
|
|
@@ -1408,7 +1642,7 @@ class ExpressCheckoutImpl {
|
|
|
1408
1642
|
if (this.pending3DSAfterGpay) {
|
|
1409
1643
|
const threeDSData = this.pending3DSAfterGpay;
|
|
1410
1644
|
this.pending3DSAfterGpay = null;
|
|
1411
|
-
this.
|
|
1645
|
+
this.threeDSModal.show(threeDSData);
|
|
1412
1646
|
}
|
|
1413
1647
|
}
|
|
1414
1648
|
catch (e) {
|
|
@@ -1622,7 +1856,7 @@ class ExpressCheckoutImpl {
|
|
|
1622
1856
|
this.layoutResizeObserver.disconnect();
|
|
1623
1857
|
this.layoutResizeObserver = null;
|
|
1624
1858
|
}
|
|
1625
|
-
this.
|
|
1859
|
+
this.threeDSModal.close();
|
|
1626
1860
|
this.abortApplePaySession();
|
|
1627
1861
|
this.sessionActive = false;
|
|
1628
1862
|
this.mounted = false;
|
|
@@ -1730,23 +1964,8 @@ class ExpressCheckoutImpl {
|
|
|
1730
1964
|
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1731
1965
|
this.tokenizeIframe.contentWindow.postMessage(message, origin);
|
|
1732
1966
|
}
|
|
1733
|
-
// ─── 3DS modal
|
|
1734
|
-
|
|
1735
|
-
this.threeDSModal = document.createElement('div');
|
|
1736
|
-
this.threeDSModal.id = 'paypercut-express-3ds-modal';
|
|
1737
|
-
Object.assign(this.threeDSModal.style, {
|
|
1738
|
-
position: 'fixed',
|
|
1739
|
-
top: '0',
|
|
1740
|
-
left: '0',
|
|
1741
|
-
width: '100%',
|
|
1742
|
-
height: '100%',
|
|
1743
|
-
display: 'flex',
|
|
1744
|
-
alignItems: 'center',
|
|
1745
|
-
justifyContent: 'center',
|
|
1746
|
-
zIndex: '999999',
|
|
1747
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
1748
|
-
});
|
|
1749
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
1967
|
+
// ─── 3DS modal ──────────
|
|
1968
|
+
buildThreeDSUrl(data) {
|
|
1750
1969
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1751
1970
|
const threeDSUrl = new URL('/express/threeds', checkoutOrigin);
|
|
1752
1971
|
threeDSUrl.searchParams.set('instanceId', this.instanceId);
|
|
@@ -1759,37 +1978,25 @@ class ExpressCheckoutImpl {
|
|
|
1759
1978
|
if (data.threeDSVersion)
|
|
1760
1979
|
threeDSUrl.searchParams.set('threeDSVersion', data.threeDSVersion);
|
|
1761
1980
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
borderRadius: '8px',
|
|
1770
|
-
display: 'block',
|
|
1771
|
-
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',
|
|
1772
1988
|
});
|
|
1773
|
-
this.threeDSModal.
|
|
1774
|
-
|
|
1775
|
-
this._pending3DSData = data;
|
|
1989
|
+
this.threeDSModal.close();
|
|
1990
|
+
this.emitter.emit(ExpressSdkEvent.Cancel);
|
|
1776
1991
|
}
|
|
1777
1992
|
handle3DSReady() {
|
|
1778
|
-
|
|
1779
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
1993
|
+
if (!this.threeDSModal.handleReady()) {
|
|
1780
1994
|
console.error('[PaypercutExpressCheckout] No pending 3DS data or iframe not ready');
|
|
1781
|
-
return;
|
|
1782
1995
|
}
|
|
1783
|
-
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1784
|
-
this.threeDSIframe.contentWindow.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1785
1996
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
this.threeDSModal = null;
|
|
1790
|
-
}
|
|
1791
|
-
this.threeDSIframe = null;
|
|
1792
|
-
delete this._pending3DSData;
|
|
1997
|
+
postThreeDSInit(iframe) {
|
|
1998
|
+
const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
1999
|
+
iframe.contentWindow?.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
|
|
1793
2000
|
}
|
|
1794
2001
|
}
|
|
1795
2002
|
//Factory
|
|
@@ -1807,11 +2014,14 @@ class CheckoutImpl {
|
|
|
1807
2014
|
this.mounted = false;
|
|
1808
2015
|
this.destroyed = false;
|
|
1809
2016
|
this.iframe = null;
|
|
1810
|
-
// 3DS Modal state
|
|
1811
|
-
this.threeDSModal = null;
|
|
1812
|
-
this.threeDSIframe = null;
|
|
1813
2017
|
// Bind message handler
|
|
1814
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
|
+
});
|
|
1815
2025
|
window.addEventListener('message', this.messageHandler);
|
|
1816
2026
|
}
|
|
1817
2027
|
/**
|
|
@@ -1906,6 +2116,11 @@ class CheckoutImpl {
|
|
|
1906
2116
|
case 'CHECKOUT_LOADED':
|
|
1907
2117
|
this.emitter.emit(SdkEvent.Loaded);
|
|
1908
2118
|
break;
|
|
2119
|
+
case 'CHECKOUT_PROCESSING':
|
|
2120
|
+
this.emitter.emit(SdkEvent.Processing, {
|
|
2121
|
+
checkoutId: data.checkoutId,
|
|
2122
|
+
});
|
|
2123
|
+
break;
|
|
1909
2124
|
case 'CHECKOUT_SUCCESS':
|
|
1910
2125
|
const { payment_method = {}, payment = null } = data;
|
|
1911
2126
|
this.emitter.emit(SdkEvent.Success, { payment_method, payment });
|
|
@@ -1927,8 +2142,11 @@ class CheckoutImpl {
|
|
|
1927
2142
|
this.emitter.emit(SdkEvent.Resize, data.height);
|
|
1928
2143
|
this.handleResize(data.height);
|
|
1929
2144
|
break;
|
|
2145
|
+
case 'PAYPERCUT_THREEDS_FRAME_RESIZE':
|
|
2146
|
+
this.threeDSModal.handleFrameResize(evt, data);
|
|
2147
|
+
break;
|
|
1930
2148
|
case 'THREEDS_START_FLOW':
|
|
1931
|
-
this.
|
|
2149
|
+
this.threeDSModal.show(data);
|
|
1932
2150
|
this.emitter.emit(SdkEvent.ThreeDSStarted);
|
|
1933
2151
|
break;
|
|
1934
2152
|
case 'THREEDS_READY':
|
|
@@ -1936,17 +2154,17 @@ class CheckoutImpl {
|
|
|
1936
2154
|
break;
|
|
1937
2155
|
case 'THREEDS_COMPLETE':
|
|
1938
2156
|
this.postToIframe(data);
|
|
1939
|
-
this.
|
|
2157
|
+
this.threeDSModal.close();
|
|
1940
2158
|
this.emitter.emit(SdkEvent.ThreeDSComplete);
|
|
1941
2159
|
break;
|
|
1942
2160
|
case 'THREEDS_CANCELED':
|
|
1943
2161
|
this.postToIframe(data);
|
|
1944
|
-
this.
|
|
2162
|
+
this.threeDSModal.close();
|
|
1945
2163
|
this.emitter.emit(SdkEvent.ThreeDSCanceled);
|
|
1946
2164
|
break;
|
|
1947
2165
|
case 'THREEDS_ERROR':
|
|
1948
2166
|
this.postToIframe(data);
|
|
1949
|
-
this.
|
|
2167
|
+
this.threeDSModal.close();
|
|
1950
2168
|
this.emitter.emit(SdkEvent.ThreeDSError, data.error);
|
|
1951
2169
|
break;
|
|
1952
2170
|
case 'FORM_VALIDATION':
|
|
@@ -2036,27 +2254,7 @@ class CheckoutImpl {
|
|
|
2036
2254
|
// Set iframe height to match content
|
|
2037
2255
|
this.iframe.style.height = `${height}px`;
|
|
2038
2256
|
}
|
|
2039
|
-
|
|
2040
|
-
* Show 3DS modal with challenge/decoupled flow
|
|
2041
|
-
*/
|
|
2042
|
-
show3DSModal(data) {
|
|
2043
|
-
// Create modal backdrop
|
|
2044
|
-
this.threeDSModal = document.createElement('div');
|
|
2045
|
-
this.threeDSModal.id = 'paypercut-3ds-modal';
|
|
2046
|
-
Object.assign(this.threeDSModal.style, {
|
|
2047
|
-
position: 'fixed',
|
|
2048
|
-
top: '0',
|
|
2049
|
-
left: '0',
|
|
2050
|
-
width: '100%',
|
|
2051
|
-
height: '100%',
|
|
2052
|
-
display: 'flex',
|
|
2053
|
-
alignItems: 'center',
|
|
2054
|
-
justifyContent: 'center',
|
|
2055
|
-
zIndex: '999999',
|
|
2056
|
-
background: 'rgba(0, 0, 0, 0.4)',
|
|
2057
|
-
});
|
|
2058
|
-
// Create iframe for 3DS page
|
|
2059
|
-
this.threeDSIframe = document.createElement('iframe');
|
|
2257
|
+
buildThreeDSUrl(data) {
|
|
2060
2258
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2061
2259
|
// Build URL: baseUrl/c/{checkoutId}/threeds with query params
|
|
2062
2260
|
const threeDSUrl = new URL(`/c/${this.options.id}/threeds`, checkoutOrigin);
|
|
@@ -2073,50 +2271,32 @@ class CheckoutImpl {
|
|
|
2073
2271
|
}
|
|
2074
2272
|
// Always include liveMode; default to false when undefined
|
|
2075
2273
|
threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
border: 'none',
|
|
2084
|
-
borderRadius: '8px',
|
|
2085
|
-
display: 'block',
|
|
2086
|
-
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',
|
|
2087
2281
|
});
|
|
2088
|
-
|
|
2089
|
-
this.
|
|
2090
|
-
document.body.appendChild(this.threeDSModal);
|
|
2091
|
-
// Store 3DS data for later use
|
|
2092
|
-
this.pending3DSData = data;
|
|
2282
|
+
this.threeDSModal.close();
|
|
2283
|
+
this.emitter.emit(SdkEvent.ThreeDSCanceled);
|
|
2093
2284
|
}
|
|
2094
2285
|
/**
|
|
2095
2286
|
* Handle THREEDS_READY message - send THREEDS_INIT with challenge data
|
|
2096
2287
|
*/
|
|
2097
2288
|
handle3DSReady() {
|
|
2098
|
-
|
|
2099
|
-
if (!data || !this.threeDSIframe?.contentWindow) {
|
|
2289
|
+
if (!this.threeDSModal.handleReady()) {
|
|
2100
2290
|
console.error('[PaypercutCheckout] No pending 3DS data or iframe not ready');
|
|
2101
|
-
return;
|
|
2102
2291
|
}
|
|
2292
|
+
}
|
|
2293
|
+
postThreeDSInit(iframe) {
|
|
2103
2294
|
const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
|
|
2104
|
-
|
|
2295
|
+
iframe.contentWindow?.postMessage({
|
|
2105
2296
|
type: 'THREEDS_INIT',
|
|
2106
2297
|
checkoutId: this.options.id,
|
|
2107
2298
|
}, checkoutOrigin);
|
|
2108
2299
|
}
|
|
2109
|
-
/**
|
|
2110
|
-
* Close 3DS modal and cleanup
|
|
2111
|
-
*/
|
|
2112
|
-
close3DSModal() {
|
|
2113
|
-
if (this.threeDSModal) {
|
|
2114
|
-
this.threeDSModal.remove();
|
|
2115
|
-
this.threeDSModal = null;
|
|
2116
|
-
}
|
|
2117
|
-
this.threeDSIframe = null;
|
|
2118
|
-
delete this.pending3DSData;
|
|
2119
|
-
}
|
|
2120
2300
|
/**
|
|
2121
2301
|
* Destroy the checkout instance and cleanup (idempotent)
|
|
2122
2302
|
*/
|
|
@@ -2136,7 +2316,7 @@ class CheckoutImpl {
|
|
|
2136
2316
|
}
|
|
2137
2317
|
}
|
|
2138
2318
|
// Cleanup 3DS modal if open
|
|
2139
|
-
this.
|
|
2319
|
+
this.threeDSModal.close();
|
|
2140
2320
|
// Only set mounted = false after successful DOM removal
|
|
2141
2321
|
this.mounted = false;
|
|
2142
2322
|
this.destroyed = true;
|