@paypercut/checkout-js 1.0.23 → 1.1.7

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/dist/index.mjs CHANGED
@@ -61,6 +61,13 @@ class Emitter {
61
61
  }
62
62
  });
63
63
  }
64
+ /**
65
+ * Returns true if at least one handler is registered for the given event
66
+ */
67
+ hasListeners(event) {
68
+ const set = this.handlers.get(event);
69
+ return !!set && set.size > 0;
70
+ }
64
71
  /**
65
72
  * Clear all event handlers
66
73
  */
@@ -80,8 +87,10 @@ class Emitter {
80
87
  * Production configuration (for merchants)
81
88
  */
82
89
  const productionConfig = {
83
- version: "1.0.23",
90
+ version: "1.1.7",
84
91
  defaultCheckoutOrigin: 'https://buy.paypercut.io',
92
+ defaultApiOrigin: 'https://api.paypercut.io',
93
+ defaultVaultApiUrl: 'https://api.basistheory.com',
85
94
  allowedOrigins: [
86
95
  'https://buy.paypercut.io',
87
96
  ]};
@@ -101,6 +110,18 @@ function isOriginAllowed(origin) {
101
110
  function getCheckoutOrigin(override) {
102
111
  return config.defaultCheckoutOrigin;
103
112
  }
113
+ /**
114
+ * Get the Paypercut API origin (with optional override for internal builds)
115
+ */
116
+ function getApiOrigin(override) {
117
+ return config.defaultApiOrigin;
118
+ }
119
+ /**
120
+ * Get the vault provider API URL (not overridable — internal use only)
121
+ */
122
+ function getVaultApiUrl() {
123
+ return config.defaultVaultApiUrl;
124
+ }
104
125
 
105
126
  /**
106
127
  * Supported locales for Paypercut Checkout
@@ -136,6 +157,7 @@ const LOCALES = [
136
157
  'cs', 'cs-CZ',
137
158
  'sl', 'sl-SI',
138
159
  'sk', 'sk-SK',
160
+ 'hu', 'hu-HU',
139
161
  ];
140
162
  /**
141
163
  * Fast runtime check using Set for O(1) lookup
@@ -278,6 +300,1493 @@ var SdkEvent;
278
300
  SdkEvent["FormValidation"] = "form_validation";
279
301
  })(SdkEvent || (SdkEvent = {}));
280
302
 
303
+ // ─── Locale ───────────────────────────────────────────────────────────────────
304
+ /**
305
+ * ISO 639-1 two-letter language codes supported by the Express Checkout wallet buttons.
306
+ *
307
+ * Pass one of these to `locale` in the options or to `setLocale()` after mount.
308
+ * Each wallet applies the locale independently:
309
+ * - Apple Pay supports all values in this list.
310
+ * - Google Pay supports most; unsupported languages (e.g. 'ro', 'hu') fall back to 'en'.
311
+ */
312
+ /**
313
+ * ISO 639-1 language codes supported by Google Pay's buttonLocale parameter.
314
+ * Source: https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions
315
+ */
316
+ const GPAY_SUPPORTED_LOCALES = new Set([
317
+ 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et',
318
+ 'fi', 'fr', 'hr', 'id', 'it', 'ja', 'ko', 'ms', 'nl', 'no',
319
+ 'pl', 'pt', 'ru', 'sk', 'sl', 'sr', 'sv', 'th', 'tr', 'uk', 'zh',
320
+ ]);
321
+ /** @internal */
322
+ function normalizeApplePayLocale(locale) {
323
+ return locale || 'en';
324
+ }
325
+ /** @internal */
326
+ function normalizeGPayLocale(locale) {
327
+ const lang = locale.split('-')[0].toLowerCase();
328
+ return GPAY_SUPPORTED_LOCALES.has(lang) ? lang : 'en';
329
+ }
330
+ var ExpressSdkEvent;
331
+ (function (ExpressSdkEvent) {
332
+ ExpressSdkEvent["Ready"] = "ready";
333
+ ExpressSdkEvent["Click"] = "click";
334
+ ExpressSdkEvent["SessionStart"] = "session_start";
335
+ ExpressSdkEvent["ShippingOptionsRequired"] = "shipping_options_required";
336
+ ExpressSdkEvent["ShippingAddressChange"] = "shipping_address_change";
337
+ ExpressSdkEvent["ShippingOptionChange"] = "shipping_option_change";
338
+ ExpressSdkEvent["PaymentMethodCreated"] = "payment_method_created";
339
+ ExpressSdkEvent["PaymentMethodFailed"] = "payment_method_failed";
340
+ ExpressSdkEvent["Cancel"] = "cancel";
341
+ ExpressSdkEvent["Error"] = "error";
342
+ })(ExpressSdkEvent || (ExpressSdkEvent = {}));
343
+
344
+ // ─── UUID helper ──────────────────────────────────────────────────────────────
345
+ function generateId() {
346
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
347
+ return crypto.randomUUID();
348
+ }
349
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
350
+ const r = (Math.random() * 16) | 0;
351
+ return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
352
+ });
353
+ }
354
+ // ─── Live key detection ───────────────────────────────────────────────────────
355
+ function isLiveKey(publishableKey) {
356
+ return publishableKey.startsWith('pk_live_');
357
+ }
358
+ // ─── Apple Pay JS SDK loader ──────────────────────────────────────────────────
359
+ let applePayScriptPromise = null;
360
+ function loadApplePayScript() {
361
+ if (applePayScriptPromise)
362
+ return applePayScriptPromise;
363
+ applePayScriptPromise = new Promise((resolve) => {
364
+ if (typeof window === 'undefined') {
365
+ resolve();
366
+ return;
367
+ }
368
+ // <apple-pay-button> custom element already registered — SDK already loaded
369
+ if (customElements?.get('apple-pay-button')) {
370
+ resolve();
371
+ return;
372
+ }
373
+ const script = document.createElement('script');
374
+ script.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
375
+ script.async = true;
376
+ script.onload = () => resolve();
377
+ // Non-Apple browsers won't expose ApplePaySession — treat as unavailable, not an error
378
+ script.onerror = () => resolve();
379
+ document.head.appendChild(script);
380
+ });
381
+ return applePayScriptPromise;
382
+ }
383
+ // ─── Google Pay JS API loader ─────────────────────────────────────────────────
384
+ let gpayScriptPromise = null;
385
+ function loadGooglePayScript() {
386
+ if (gpayScriptPromise)
387
+ return gpayScriptPromise;
388
+ gpayScriptPromise = new Promise((resolve, reject) => {
389
+ if (typeof window === 'undefined') {
390
+ reject(new Error('No window'));
391
+ return;
392
+ }
393
+ if (globalThis.google?.payments?.api?.PaymentsClient) {
394
+ resolve();
395
+ return;
396
+ }
397
+ const script = document.createElement('script');
398
+ script.src = 'https://pay.google.com/gp/p/js/pay.js';
399
+ script.async = true;
400
+ script.onload = () => resolve();
401
+ script.onerror = () => reject(new Error('Failed to load Google Pay script'));
402
+ document.head.appendChild(script);
403
+ });
404
+ return gpayScriptPromise;
405
+ }
406
+ // ─── Google Pay PaymentDataRequestUpdate builder ──────────────────────────────
407
+ /**
408
+ * Converts SDK update options into the Google Pay `PaymentDataRequestUpdate` shape.
409
+ * Pure function — no class state needed beyond currency and countryCode.
410
+ */
411
+ function buildGpayPaymentDataUpdate(update, currency, countryCode = 'DE') {
412
+ const result = {};
413
+ if (update.amount !== undefined) {
414
+ result.newTransactionInfo = {
415
+ totalPriceStatus: 'FINAL',
416
+ totalPriceLabel: 'Total',
417
+ totalPrice: (update.amount / 100).toFixed(2),
418
+ currencyCode: currency,
419
+ countryCode,
420
+ };
421
+ }
422
+ if (update.shippingOptions?.length) {
423
+ result.newShippingOptionParameters = {
424
+ defaultSelectedOptionId: update.shippingOptions[0].id,
425
+ shippingOptions: update.shippingOptions.map((so) => ({
426
+ id: so.id,
427
+ label: so.label,
428
+ description: so.detail ?? `${(so.amount / 100).toFixed(2)} ${currency}`,
429
+ })),
430
+ };
431
+ }
432
+ if (update.status === 'invalid_shipping_address') {
433
+ result.error = {
434
+ reason: 'SHIPPING_ADDRESS_UNSERVICEABLE',
435
+ message: 'Cannot ship to this address.',
436
+ intent: 'SHIPPING_ADDRESS',
437
+ };
438
+ }
439
+ else if (update.status === 'invalid_shipping_option') {
440
+ result.error = {
441
+ reason: 'SHIPPING_OPTION_INVALID',
442
+ message: 'This shipping option is not available.',
443
+ intent: 'SHIPPING_OPTION',
444
+ };
445
+ }
446
+ return result;
447
+ }
448
+
449
+ // Apple Pay uses 'check-out' (hyphenated); our public API uses 'checkout' to match Google Pay
450
+ function toApplePayButtonType(type) {
451
+ return type === 'checkout' ? 'check-out' : type;
452
+ }
453
+ // Implementation
454
+ class ExpressCheckoutImpl {
455
+ constructor(options) {
456
+ this.options = options;
457
+ this.emitter = new Emitter();
458
+ this.mounted = false;
459
+ this.destroyed = false;
460
+ /** True while a wallet payment sheet is open — prevents concurrent sessions */
461
+ this.sessionActive = false;
462
+ // DOM elements created by mount()
463
+ this.tokenizeIframe = null;
464
+ this.wrapper = null;
465
+ this.applePayContainer = null;
466
+ this.applePayButtonEl = null;
467
+ this.gpayContainer = null;
468
+ this.gpayClient = null;
469
+ this.gpayPaymentRequest = null;
470
+ this.gpayCurrentAmount = 0;
471
+ // Layout state
472
+ this.preferredLayout = 'row';
473
+ this.layoutResizeObserver = null;
474
+ /**
475
+ * Client-generated ID used to route postMessages to the correct instance.
476
+ * Passed to each iframe as a query param; echoed back in every message.
477
+ */
478
+ this.instanceId = generateId();
479
+ /**
480
+ * Idempotency key for the current payment attempt.
481
+ * Regenerated on each wallet button click so retries get a fresh key.
482
+ */
483
+ this.idempotencyKey = generateId();
484
+ // 3DS modal — same pattern as CheckoutImpl
485
+ this.threeDSModal = null;
486
+ this.threeDSIframe = null;
487
+ // Pending 3DS data captured during THREEDS_START_FLOW while GPay sheet is still closing.
488
+ // Shown after loadPaymentData() resolves
489
+ this.pending3DSAfterGpay = null;
490
+ // Apple Pay native session state — session created directly in the SDK window
491
+ // on the merchant's registered domain.
492
+ this.applePaySession = null;
493
+ this.applePayCurrentAmount = 0;
494
+ this.currentLineItems = [];
495
+ this.applePayCurrentShippingOptions = [];
496
+ this.applePayPendingShippingOption = null;
497
+ this.applePayPendingCallback = null;
498
+ // Stored from onpaymentauthorized — used to populate PaymentMethodCreated after TOKENIZE_RESPONSE
499
+ this.applePayPendingBillingDetails = null;
500
+ this.applePayPendingShippingDetails = null;
501
+ /**
502
+ * Config fetched via HTTP from /api/express/config on mount().
503
+ * Populated before any wallet buttons are mounted.
504
+ */
505
+ this.expressConfig = null;
506
+ // Pending Google Pay payment data waiting for tokenization response
507
+ this.pendingGpayResolve = null;
508
+ this.pendingGpayReject = null;
509
+ // Stored GPay metadata for use when TOKENIZE_RESPONSE arrives after 3DS (sheet already closed)
510
+ this.pendingGpayBillingDetails = null;
511
+ this.pendingGpayShippingDetails = null;
512
+ this.pendingGpayShippingOption = undefined;
513
+ this.currentShippingOptions = options.shippingOptions ?? [];
514
+ this.messageHandler = this.onMessage.bind(this);
515
+ window.addEventListener('message', this.messageHandler);
516
+ }
517
+ // ─── URL builders
518
+ buildTokenizeSrc() {
519
+ const baseUrl = getCheckoutOrigin(this.options.hostedCheckoutUrl);
520
+ const url = new URL('/express/tokenize', baseUrl);
521
+ url.searchParams.set('instanceId', this.instanceId);
522
+ url.searchParams.set('liveMode', String(isLiveKey(this.options.publishableKey)));
523
+ return url.toString();
524
+ }
525
+ // ─── Config fetch
526
+ async fetchExpressConfig() {
527
+ const apiOrigin = getApiOrigin(this.options.apiUrl);
528
+ const url = new URL('/v1/elements/sessions', apiOrigin);
529
+ url.searchParams.set('type', 'deferred_intent');
530
+ url.searchParams.set('key', this.options.publishableKey);
531
+ url.searchParams.set('deferred_intent[mode]', 'payment');
532
+ url.searchParams.set('referrer_host', window.location.hostname);
533
+ try {
534
+ const res = await fetch(url.toString(), { cache: 'no-store' });
535
+ if (!res.ok)
536
+ throw new Error(`Config fetch failed: HTTP ${res.status}`);
537
+ const data = await res.json();
538
+ const liveMode = isLiveKey(this.options.publishableKey);
539
+ const googlePayTestMerchantId = 'BCR2DN5T735375Y7';
540
+ const googlePayMerchantRef = data.payment_domain?.wallets?.google_pay?.merchant_ref ?? '';
541
+ const googlePayStatus = data.payment_domain?.wallets?.google_pay?.status ?? 'inactive';
542
+ this.expressConfig = {
543
+ tenantId: data.payment_domain?.wallet_provider?.tenant_id ?? '',
544
+ publicKey: data.payment_domain?.wallet_provider?.public_key ?? '',
545
+ vaultApiUrl: getVaultApiUrl(),
546
+ googlePayMerchantId: liveMode
547
+ ? googlePayStatus === 'active'
548
+ ? googlePayMerchantRef
549
+ : googlePayTestMerchantId
550
+ : googlePayMerchantRef || googlePayTestMerchantId,
551
+ googlePayStatus,
552
+ applePayStatus: data.payment_domain?.wallets?.apple_pay?.status ?? 'inactive',
553
+ displayName: data.merchant?.name ?? '',
554
+ merchantMid: data.merchant?.mid ?? '',
555
+ merchantMcc: data.merchant?.mcc ?? '',
556
+ merchantCountry: data.merchant?.country ?? '',
557
+ merchantUrl: data.merchant?.business_url ?? '',
558
+ };
559
+ }
560
+ catch (err) {
561
+ console.error('[PaypercutExpressCheckout] Failed to fetch express config:', err);
562
+ // expressConfig stays null — wallet buttons will not mount
563
+ }
564
+ }
565
+ // postMessage handler
566
+ onMessage(evt) {
567
+ if (!isOriginAllowed(evt.origin)) {
568
+ if (evt.origin.includes('localhost')) {
569
+ console.warn('[PaypercutExpressCheckout] Message blocked — origin not allowed:', evt.origin);
570
+ }
571
+ return;
572
+ }
573
+ const data = evt.data;
574
+ if (!data || typeof data !== 'object' || !('type' in data))
575
+ return;
576
+ if (data.instanceId && data.instanceId !== this.instanceId) {
577
+ return;
578
+ }
579
+ switch (data.type) {
580
+ // Tokenization response from the hidden tokenize iframe — handles both wallets.
581
+ // For Apple Pay: calls createPaymentMethod, then completes/aborts the Apple Pay sheet.
582
+ // For Google Pay: resolves the pending promise inside handleGooglePayAuthorized.
583
+ case 'TOKENIZE_RESPONSE':
584
+ if (data.wallet === 'apple_pay') {
585
+ if (data.success) {
586
+ this.createPaymentMethod({
587
+ btTokenId: data.btTokenId,
588
+ cardPayload: data.cardPayload,
589
+ billingDetails: data.billingDetails,
590
+ csessId: data.csessId,
591
+ walletType: 'apple_pay',
592
+ }).then((paymentMethodId) => {
593
+ this.completeApplePaySession(true);
594
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodCreated, {
595
+ paymentMethodId,
596
+ wallet: 'apple_pay',
597
+ billingDetails: this.applePayPendingBillingDetails ?? undefined,
598
+ shippingDetails: this.applePayPendingShippingDetails ?? undefined,
599
+ selectedShippingOption: this.applePayPendingShippingOption ?? undefined,
600
+ });
601
+ this.applePayPendingBillingDetails = null;
602
+ this.applePayPendingShippingDetails = null;
603
+ this.applePayPendingShippingOption = null;
604
+ }).catch((err) => {
605
+ this.completeApplePaySession(false);
606
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(err?.message ?? 'Payment method creation failed'));
607
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: err?.message ?? 'Payment method creation failed' });
608
+ this.applePayPendingBillingDetails = null;
609
+ this.applePayPendingShippingDetails = null;
610
+ this.applePayPendingShippingOption = null;
611
+ });
612
+ }
613
+ else {
614
+ this.completeApplePaySession(false);
615
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(data.error ?? 'Apple Pay payment failed'));
616
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: data.error ?? 'Apple Pay payment failed' });
617
+ this.applePayPendingBillingDetails = null;
618
+ this.applePayPendingShippingDetails = null;
619
+ this.applePayPendingShippingOption = null;
620
+ }
621
+ }
622
+ else {
623
+ // Google Pay
624
+ if (data.success) {
625
+ if (this.pendingGpayResolve) {
626
+ // Normal path (no 3DS): resolve and let handleGooglePayAuthorized create PM
627
+ this.pendingGpayResolve(data);
628
+ this.pendingGpayResolve = null;
629
+ this.pendingGpayReject = null;
630
+ }
631
+ else {
632
+ // Post-3DS path: sheet was already closed — create PM directly, same as Apple Pay
633
+ this.createPaymentMethod({
634
+ btTokenId: data.btTokenId,
635
+ cardPayload: data.cardPayload,
636
+ billingDetails: data.billingDetails,
637
+ csessId: data.csessId,
638
+ walletType: 'google_pay',
639
+ }).then((paymentMethodId) => {
640
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodCreated, {
641
+ paymentMethodId,
642
+ wallet: 'google_pay',
643
+ billingDetails: this.pendingGpayBillingDetails ?? undefined,
644
+ shippingDetails: this.pendingGpayShippingDetails ?? undefined,
645
+ selectedShippingOption: this.pendingGpayShippingOption,
646
+ });
647
+ }).catch((err) => {
648
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(err?.message ?? 'Payment method creation failed'));
649
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: err?.message ?? 'Payment method creation failed' });
650
+ }).finally(() => {
651
+ this.pendingGpayBillingDetails = null;
652
+ this.pendingGpayShippingDetails = null;
653
+ this.pendingGpayShippingOption = undefined;
654
+ });
655
+ }
656
+ }
657
+ else {
658
+ if (this.pendingGpayReject) {
659
+ // Normal path (no 3DS): reject the pending promise in handleGooglePayAuthorized
660
+ this.pendingGpayReject(new Error(data.error ?? 'Tokenization failed'));
661
+ this.pendingGpayResolve = null;
662
+ this.pendingGpayReject = null;
663
+ }
664
+ else {
665
+ // Post-3DS path: sheet already closed — emit events directly.
666
+ // Distinguish user cancellation from an actual error so integrators
667
+ // can handle them differently (e.g. "cancel" = re-show checkout,
668
+ // "error" = show an error message).
669
+ const errMsg = data.error ?? 'Google Pay payment failed';
670
+ const isCanceled = errMsg.toLowerCase().includes('cancel');
671
+ if (isCanceled) {
672
+ this.emitter.emit(ExpressSdkEvent.Cancel);
673
+ }
674
+ else {
675
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(errMsg));
676
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: errMsg });
677
+ }
678
+ this.pendingGpayBillingDetails = null;
679
+ this.pendingGpayShippingDetails = null;
680
+ this.pendingGpayShippingOption = undefined;
681
+ }
682
+ }
683
+ }
684
+ break;
685
+ // 3DS flow
686
+ case 'THREEDS_START_FLOW':
687
+ // Google Pay sheet is a native browser UI that cannot be overlaid by DOM elements.
688
+ // Resolve the pending GPay promise so GPay starts closing its sheet.
689
+ if (this.pendingGpayResolve) {
690
+ this.pending3DSAfterGpay = data;
691
+ this.pendingGpayResolve({ __closeSheet: true });
692
+ this.pendingGpayResolve = null;
693
+ this.pendingGpayReject = null;
694
+ }
695
+ else {
696
+ // Apple Pay or any path without a pending GPay sheet — show immediately
697
+ this.show3DSModal(data);
698
+ }
699
+ break;
700
+ case 'THREEDS_READY':
701
+ this.handle3DSReady();
702
+ break;
703
+ case 'THREEDS_COMPLETE':
704
+ case 'THREEDS_CANCELED':
705
+ case 'THREEDS_ERROR':
706
+ this.postToTokenizeIframe(data);
707
+ this.close3DSModal();
708
+ break;
709
+ }
710
+ }
711
+ // ─── Public API ──
712
+ mount(container) {
713
+ if (this.mounted) {
714
+ console.warn('[PaypercutExpressCheckout] mount() called but already mounted — ignoring');
715
+ return;
716
+ }
717
+ const el = typeof container === 'string'
718
+ ? document.querySelector(container)
719
+ : container;
720
+ if (!el) {
721
+ throw new Error(`[PaypercutExpressCheckout] Container not found: ${container}`);
722
+ }
723
+ const requestedWallets = this.options.walletOptions?.length
724
+ ? this.options.walletOptions
725
+ : [WalletOption.APPLE_PAY, WalletOption.GOOGLE_PAY];
726
+ const showApplePay = requestedWallets.includes(WalletOption.APPLE_PAY);
727
+ const showGooglePay = requestedWallets.includes(WalletOption.GOOGLE_PAY);
728
+ // Wrapper — row (default) or column layout; 'auto' uses ResizeObserver
729
+ const layoutOption = this.options.layout ?? 'row';
730
+ this.preferredLayout = layoutOption === 'auto' ? 'row' : layoutOption;
731
+ const wrapper = document.createElement('div');
732
+ this.wrapper = wrapper;
733
+ Object.assign(wrapper.style, {
734
+ display: 'flex',
735
+ flexDirection: this.preferredLayout === 'row' ? 'row' : 'column',
736
+ gap: '8px',
737
+ width: '100%',
738
+ });
739
+ // Placeholder containers — filled after config is fetched
740
+ // Google Pay is rendered first, Apple Pay second
741
+ if (showGooglePay) {
742
+ this.gpayContainer = document.createElement('div');
743
+ this.applyLayoutToContainers(this.preferredLayout, this.gpayContainer);
744
+ wrapper.appendChild(this.gpayContainer);
745
+ // Preload Google Pay script in parallel while config is being fetched
746
+ loadGooglePayScript().catch((err) => {
747
+ console.error('[PaypercutExpressCheckout] Failed to load Google Pay script:', err);
748
+ });
749
+ }
750
+ if (showApplePay) {
751
+ this.applePayContainer = document.createElement('div');
752
+ this.applyLayoutToContainers(this.preferredLayout, this.applePayContainer);
753
+ wrapper.appendChild(this.applePayContainer);
754
+ // Pre-load Apple Pay JS SDK in parallel while config is being fetched.
755
+ // Resolves even on non-Apple browsers — ApplePaySession check happens after.
756
+ loadApplePayScript();
757
+ }
758
+ el.appendChild(wrapper);
759
+ // Auto layout — observe container width and switch at 540px breakpoint
760
+ if (layoutOption === 'auto' && typeof ResizeObserver !== 'undefined') {
761
+ this.layoutResizeObserver = new ResizeObserver((entries) => {
762
+ const width = entries[0]?.contentRect.width ?? el.offsetWidth;
763
+ this.applyLayout(width <= 540 ? 'column' : 'row');
764
+ });
765
+ this.layoutResizeObserver.observe(el);
766
+ }
767
+ // Hidden tokenize iframe (appended to body, off-screen) — used by both wallets
768
+ const tokenizeSrc = this.buildTokenizeSrc();
769
+ this.tokenizeIframe = document.createElement('iframe');
770
+ this.tokenizeIframe.id = 'paypercut-express-tokenize-iframe';
771
+ this.tokenizeIframe.src = tokenizeSrc;
772
+ this.tokenizeIframe.setAttribute('frameborder', '0');
773
+ this.tokenizeIframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin');
774
+ Object.assign(this.tokenizeIframe.style, {
775
+ position: 'absolute',
776
+ top: '-9999px',
777
+ left: '-9999px',
778
+ width: '1px',
779
+ height: '1px',
780
+ border: 'none',
781
+ visibility: 'hidden',
782
+ });
783
+ document.body.appendChild(this.tokenizeIframe);
784
+ this.mounted = true;
785
+ // Fetch config then mount wallet buttons
786
+ this.fetchExpressConfig().then(async () => {
787
+ if (this.destroyed)
788
+ return;
789
+ const config = this.expressConfig;
790
+ if (showApplePay && this.applePayContainer && config?.applePayStatus === 'active') {
791
+ await this.mountApplePayButton(this.applePayContainer);
792
+ }
793
+ else if (this.applePayContainer) {
794
+ // Apple Pay can't mount — remove its container so the remaining button fills full width
795
+ this.applePayContainer.remove();
796
+ this.applePayContainer = null;
797
+ }
798
+ if (showGooglePay && config) {
799
+ this.mountGooglePayFromConfig();
800
+ }
801
+ this.emitter.emit(ExpressSdkEvent.Ready);
802
+ });
803
+ }
804
+ // ─── Layout ──────────────────────────────────────
805
+ applyLayoutToContainers(layout, ...containers) {
806
+ for (const container of containers) {
807
+ if (!container)
808
+ continue;
809
+ container.style.flex = layout === 'row' ? '1' : '';
810
+ container.style.minWidth = layout === 'row' ? '0' : '';
811
+ container.style.width = layout === 'row' ? '' : '100%';
812
+ }
813
+ }
814
+ applyLayout(layout) {
815
+ if (!this.wrapper)
816
+ return;
817
+ this.wrapper.style.flexDirection = layout === 'row' ? 'row' : 'column';
818
+ this.applyLayoutToContainers(layout, this.applePayContainer, this.gpayContainer);
819
+ }
820
+ /**
821
+ * Dynamically change the button layout after mount.
822
+ * 'row' places buttons side by side, 'column' stacks them vertically.
823
+ */
824
+ setLayout(layout) {
825
+ this.preferredLayout = layout;
826
+ this.applyLayout(layout);
827
+ }
828
+ /**
829
+ * Dynamically change the locale of the wallet buttons after mount.
830
+ *
831
+ * Pass an ISO 639-1 two-letter language code (e.g. `'en'`, `'bg'`, `'pl'`).
832
+ * Each wallet applies this independently:
833
+ * - Apple Pay updates its button label immediately.
834
+ * - Google Pay recreates its button with the new locale.
835
+ *
836
+ * Unsupported languages fall back to `'en'`. See `ExpressLocale` for the full list.
837
+ *
838
+ * @example
839
+ * express.setLocale('bg'); // switch both buttons to Bulgarian
840
+ */
841
+ setLocale(locale) {
842
+ this.options.locale = locale;
843
+ if (this.applePayButtonEl) {
844
+ this.applePayButtonEl.setAttribute('locale', normalizeApplePayLocale(locale));
845
+ }
846
+ if (this.gpayClient && this.gpayContainer && this.gpayPaymentRequest) {
847
+ this.setButtonOptions({});
848
+ }
849
+ }
850
+ setButtonOptions(opts) {
851
+ this.options.buttonOptions = { ...this.options.buttonOptions, ...opts };
852
+ const merged = this.options.buttonOptions;
853
+ // ── Apple Pay: update attributes on the live <apple-pay-button> element ──
854
+ if (this.applePayButtonEl) {
855
+ if (opts.applePayStyle !== undefined) {
856
+ this.applePayButtonEl.setAttribute('buttonstyle', opts.applePayStyle);
857
+ }
858
+ if (opts.type !== undefined) {
859
+ this.applePayButtonEl.setAttribute('type', toApplePayButtonType(opts.type));
860
+ }
861
+ if (opts.borderRadius !== undefined) {
862
+ this.applePayButtonEl.style.setProperty('--apple-pay-button-border-radius', opts.borderRadius);
863
+ }
864
+ }
865
+ // ── Google Pay: recreate the button (GPay SDK has no update API) ──
866
+ if (this.gpayClient && this.gpayContainer && this.gpayPaymentRequest) {
867
+ this.gpayContainer.innerHTML = '';
868
+ const button = this.gpayClient.createButton({
869
+ onClick: () => this.startGooglePay(this.gpayPaymentRequest),
870
+ buttonSizeMode: 'fill',
871
+ buttonType: merged?.type ?? 'plain',
872
+ buttonColor: merged?.googlePayColor ?? 'default',
873
+ ...(this.options.locale && { buttonLocale: normalizeGPayLocale(this.options.locale) }),
874
+ });
875
+ const borderRadius = merged?.borderRadius ?? '0.5rem';
876
+ button.style.width = '100%';
877
+ this.injectGpayInnerStyles(button, borderRadius);
878
+ this.gpayContainer.appendChild(button);
879
+ }
880
+ }
881
+ // ─── Apple Pay native button ────────────────────
882
+ async mountApplePayButton(container) {
883
+ await loadApplePayScript();
884
+ const ApplePayAPI = window.ApplePaySession;
885
+ if (!ApplePayAPI) {
886
+ console.log('[PaypercutExpressCheckout] ApplePaySession not available');
887
+ return;
888
+ }
889
+ if (!ApplePayAPI.canMakePayments?.()) {
890
+ console.log('[PaypercutExpressCheckout] ApplePaySession.canMakePayments() returned false — hiding Apple Pay button');
891
+ return;
892
+ }
893
+ const locale = this.options.locale ? normalizeApplePayLocale(this.options.locale) : 'en';
894
+ const buttonOpts = this.options.buttonOptions;
895
+ const button = document.createElement('apple-pay-button');
896
+ button.setAttribute('buttonstyle', buttonOpts?.applePayStyle ?? 'black');
897
+ button.setAttribute('type', toApplePayButtonType(buttonOpts?.type ?? 'plain'));
898
+ button.setAttribute('locale', locale);
899
+ button.style.setProperty('--apple-pay-button-width', '100%');
900
+ button.style.setProperty('--apple-pay-button-height', '48px');
901
+ button.style.setProperty('--apple-pay-button-border-radius', buttonOpts?.borderRadius ?? '0.5rem');
902
+ button.style.display = 'block';
903
+ button.style.cursor = 'pointer';
904
+ button.addEventListener('click', () => this.startApplePay());
905
+ // <apple-pay-button> is a custom element registered by the Apple Pay JS SDK.
906
+ // In Safari, ApplePaySession is native so it may already pass the check above
907
+ // before the SDK script has finished registering the custom element.
908
+ // Wait for it to be defined before appending so it renders correctly.
909
+ const appendButton = () => {
910
+ this.applePayButtonEl = button;
911
+ container.appendChild(button);
912
+ const shadow = button.shadowRoot;
913
+ if (shadow) {
914
+ const style = document.createElement('style');
915
+ style.textContent = 'span svg { height: 75% !important; width: auto !important; }';
916
+ shadow.appendChild(style);
917
+ }
918
+ };
919
+ if (customElements?.get('apple-pay-button')) {
920
+ appendButton();
921
+ }
922
+ else {
923
+ customElements?.whenDefined('apple-pay-button').then(appendButton).catch(() => appendButton());
924
+ }
925
+ }
926
+ /**
927
+ * Starts a native Apple Pay session in the SDK window (merchant's registered domain).
928
+ * Called synchronously from the Apple Pay button click handler.
929
+ * Uses async/await which Safari preserves as part of the user gesture.
930
+ */
931
+ async startApplePay() {
932
+ if (this.sessionActive)
933
+ return;
934
+ if (typeof window === 'undefined')
935
+ return;
936
+ const ApplePayAPI = window.ApplePaySession;
937
+ if (!ApplePayAPI) {
938
+ console.error('[PaypercutExpressCheckout] ApplePaySession not available');
939
+ return;
940
+ }
941
+ this.idempotencyKey = generateId();
942
+ this.setSessionActive(true);
943
+ this.emitter.emit(ExpressSdkEvent.Click);
944
+ // Emit SessionStart — merchant must call updateWith() within 3s
945
+ const sessionInitResult = await new Promise((resolve) => {
946
+ if (!this.emitter.hasListeners(ExpressSdkEvent.SessionStart)) {
947
+ resolve(null);
948
+ return;
949
+ }
950
+ const timer = setTimeout(() => resolve(null), 3000);
951
+ this.emitter.emit(ExpressSdkEvent.SessionStart, {
952
+ wallet: 'apple_pay',
953
+ updateWith: (opts) => {
954
+ clearTimeout(timer);
955
+ resolve(opts);
956
+ },
957
+ });
958
+ });
959
+ if (!sessionInitResult) {
960
+ console.error('[PaypercutExpressCheckout] Apple Pay: no session_start response — aborting');
961
+ this.setSessionActive(false);
962
+ this.emitter.emit(ExpressSdkEvent.ShippingOptionsRequired, { wallet: 'apple_pay' });
963
+ return;
964
+ }
965
+ // Apply merchant-provided initial state
966
+ if (typeof sessionInitResult.amount === 'number') {
967
+ this.applePayCurrentAmount = sessionInitResult.amount;
968
+ }
969
+ else {
970
+ this.applePayCurrentAmount = this.options.amount;
971
+ }
972
+ if (Array.isArray(sessionInitResult.lineItems)) {
973
+ this.currentLineItems = sessionInitResult.lineItems;
974
+ }
975
+ else {
976
+ this.currentLineItems = this.options.lineItems ?? [];
977
+ }
978
+ if (Array.isArray(sessionInitResult.shippingOptions)) {
979
+ this.applePayCurrentShippingOptions = sessionInitResult.shippingOptions;
980
+ }
981
+ else {
982
+ this.applePayCurrentShippingOptions = this.currentShippingOptions;
983
+ }
984
+ this.applePayPendingShippingOption = null;
985
+ const displayName = this.expressConfig?.displayName || 'Checkout';
986
+ const totalPrice = (this.applePayCurrentAmount / 100).toFixed(2);
987
+ const appleLineItems = this.currentLineItems.map((li) => ({
988
+ label: li.label,
989
+ amount: (li.amount / 100).toFixed(2),
990
+ type: li.type ?? 'final',
991
+ }));
992
+ const request = {
993
+ countryCode: this.options.countryCode ?? 'DE',
994
+ currencyCode: this.options.currency,
995
+ merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit'],
996
+ supportedNetworks: ['visa', 'masterCard'],
997
+ lineItems: appleLineItems,
998
+ total: {
999
+ label: displayName,
1000
+ amount: totalPrice,
1001
+ type: 'final',
1002
+ },
1003
+ requiredBillingContactFields: ['postalAddress', 'name', 'email'],
1004
+ };
1005
+ // Shipping is always required for Express Checkout
1006
+ request.requiredShippingContactFields = ['postalAddress', 'name', 'email'];
1007
+ if (this.applePayCurrentShippingOptions.length) {
1008
+ request.shippingMethods = this.applePayCurrentShippingOptions.map((so) => ({
1009
+ label: so.label,
1010
+ detail: so.detail ?? '',
1011
+ amount: (so.amount / 100).toFixed(2),
1012
+ identifier: so.id,
1013
+ }));
1014
+ }
1015
+ request.shippingType = 'shipping';
1016
+ this.abortApplePaySession();
1017
+ const version = ApplePayAPI.supportsVersion?.(14) ? 14 : 3;
1018
+ try {
1019
+ const session = new ApplePayAPI(version, request);
1020
+ this.applePaySession = session;
1021
+ session.onvalidatemerchant = async (event) => {
1022
+ const vaultApiUrl = this.expressConfig?.vaultApiUrl ?? getVaultApiUrl();
1023
+ const publicKey = this.expressConfig?.publicKey ?? '';
1024
+ try {
1025
+ const headers = {
1026
+ 'Content-Type': 'application/json',
1027
+ 'BT-API-KEY': publicKey,
1028
+ };
1029
+ if (this.idempotencyKey)
1030
+ headers['Idempotency-Key'] = this.idempotencyKey;
1031
+ const res = await fetch(`${vaultApiUrl}/apple-pay/session`, {
1032
+ method: 'POST',
1033
+ headers,
1034
+ body: JSON.stringify({
1035
+ display_name: displayName,
1036
+ domain: window.location.host,
1037
+ validation_url: event.validationURL,
1038
+ }),
1039
+ });
1040
+ if (!res.ok) {
1041
+ const err = await res.json().catch(() => ({}));
1042
+ throw new Error(err?.message ?? `Merchant validation failed: HTTP ${res.status}`);
1043
+ }
1044
+ const merchantSession = await res.json();
1045
+ session.completeMerchantValidation(merchantSession);
1046
+ }
1047
+ catch (err) {
1048
+ console.error('[PaypercutExpressCheckout] Apple Pay merchant validation failed');
1049
+ this.abortApplePaySession();
1050
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(err?.message ?? 'Apple Pay merchant validation failed'));
1051
+ this.emitter.emit(ExpressSdkEvent.Cancel);
1052
+ }
1053
+ };
1054
+ // Shipping address changed — emit to merchant, wait for updateWith(), complete session
1055
+ session.onshippingcontactselected = async (event) => {
1056
+ const contact = event.shippingContact;
1057
+ const update = await new Promise((resolve) => {
1058
+ this.applePayPendingCallback = { type: 'contact', resolve };
1059
+ this.emitter.emit(ExpressSdkEvent.ShippingAddressChange, {
1060
+ address: {
1061
+ country: contact.countryCode ?? '',
1062
+ state: contact.administrativeArea,
1063
+ city: contact.locality,
1064
+ postalCode: contact.postalCode,
1065
+ },
1066
+ updateWith: (opts) => this.update(opts),
1067
+ });
1068
+ // 30s safety timeout — return unchanged data so the sheet doesn't freeze
1069
+ setTimeout(() => resolve({}), 30000);
1070
+ });
1071
+ this.applePayPendingCallback = null;
1072
+ if (typeof update.amount === 'number')
1073
+ this.applePayCurrentAmount = update.amount;
1074
+ if (Array.isArray(update.lineItems))
1075
+ this.currentLineItems = update.lineItems;
1076
+ if (Array.isArray(update.shippingOptions))
1077
+ this.applePayCurrentShippingOptions = update.shippingOptions;
1078
+ const status = update.status === 'invalid_shipping_address'
1079
+ ? ApplePayAPI.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS
1080
+ : ApplePayAPI.STATUS_SUCCESS;
1081
+ try {
1082
+ session.completeShippingContactSelection(status, this.applePayCurrentShippingOptions.map((so) => ({
1083
+ label: so.label,
1084
+ detail: so.detail ?? '',
1085
+ amount: (so.amount / 100).toFixed(2),
1086
+ identifier: so.id,
1087
+ })), {
1088
+ label: displayName,
1089
+ amount: (this.applePayCurrentAmount / 100).toFixed(2),
1090
+ type: 'final',
1091
+ }, this.currentLineItems.map((li) => ({
1092
+ label: li.label,
1093
+ amount: (li.amount / 100).toFixed(2),
1094
+ type: li.type ?? 'final',
1095
+ })));
1096
+ }
1097
+ catch (e) {
1098
+ console.error('[PaypercutExpressCheckout] completeShippingContactSelection failed', e);
1099
+ }
1100
+ };
1101
+ // Shipping method changed — emit to merchant, wait for updateWith(), complete session
1102
+ session.onshippingmethodselected = async (event) => {
1103
+ const method = event.shippingMethod;
1104
+ const selectedOption = {
1105
+ id: method.identifier,
1106
+ label: method.label,
1107
+ detail: method.detail,
1108
+ amount: Math.round(parseFloat(method.amount) * 100),
1109
+ };
1110
+ this.applePayPendingShippingOption = selectedOption;
1111
+ const update = await new Promise((resolve) => {
1112
+ this.applePayPendingCallback = { type: 'method', resolve };
1113
+ this.emitter.emit(ExpressSdkEvent.ShippingOptionChange, {
1114
+ shippingOption: selectedOption,
1115
+ updateWith: (opts) => this.update(opts),
1116
+ });
1117
+ setTimeout(() => resolve({}), 30000);
1118
+ });
1119
+ this.applePayPendingCallback = null;
1120
+ if (typeof update.amount === 'number')
1121
+ this.applePayCurrentAmount = update.amount;
1122
+ if (Array.isArray(update.lineItems))
1123
+ this.currentLineItems = update.lineItems;
1124
+ try {
1125
+ session.completeShippingMethodSelection(ApplePayAPI.STATUS_SUCCESS, {
1126
+ label: displayName,
1127
+ amount: (this.applePayCurrentAmount / 100).toFixed(2),
1128
+ type: 'final',
1129
+ }, this.currentLineItems.map((li) => ({
1130
+ label: li.label,
1131
+ amount: (li.amount / 100).toFixed(2),
1132
+ type: li.type ?? 'final',
1133
+ })));
1134
+ }
1135
+ catch (e) {
1136
+ console.error('[PaypercutExpressCheckout] completeShippingMethodSelection failed', e);
1137
+ }
1138
+ };
1139
+ // Payment authorized — send raw token to tokenize iframe for BT tokenization
1140
+ // + createExpressPaymentMethod. completePayment is called from TOKENIZE_RESPONSE handler.
1141
+ session.onpaymentauthorized = (event) => {
1142
+ const billingContact = event.payment?.billingContact;
1143
+ const shippingContact = event.payment?.shippingContact;
1144
+ this.applePayPendingBillingDetails = billingContact
1145
+ ? {
1146
+ name: [billingContact.givenName, billingContact.familyName].filter(Boolean).join(' ') || undefined,
1147
+ email: billingContact.emailAddress,
1148
+ address: {
1149
+ line1: billingContact.addressLines?.[0],
1150
+ line2: billingContact.addressLines?.[1],
1151
+ city: billingContact.locality,
1152
+ state: billingContact.administrativeArea,
1153
+ postalCode: billingContact.postalCode,
1154
+ country: billingContact.countryCode,
1155
+ },
1156
+ }
1157
+ : null;
1158
+ this.applePayPendingShippingDetails = shippingContact
1159
+ ? {
1160
+ name: [shippingContact.givenName, shippingContact.familyName].filter(Boolean).join(' ') || undefined,
1161
+ address: {
1162
+ line1: shippingContact.addressLines?.[0],
1163
+ line2: shippingContact.addressLines?.[1],
1164
+ city: shippingContact.locality,
1165
+ state: shippingContact.administrativeArea,
1166
+ postalCode: shippingContact.postalCode,
1167
+ country: shippingContact.countryCode,
1168
+ },
1169
+ }
1170
+ : null;
1171
+ this.postToTokenizeIframe({
1172
+ type: 'TOKENIZE_REQUEST',
1173
+ instanceId: this.instanceId,
1174
+ wallet: 'apple_pay',
1175
+ applePaymentData: event.payment.token,
1176
+ idemKey: this.idempotencyKey,
1177
+ publishableKey: this.options.publishableKey,
1178
+ billingDetails: this.applePayPendingBillingDetails,
1179
+ amount: this.applePayCurrentAmount,
1180
+ currency: this.options.currency,
1181
+ merchantInfo: {
1182
+ name: this.expressConfig?.displayName ?? '',
1183
+ mid: this.expressConfig?.merchantMid ?? '',
1184
+ mcc: this.expressConfig?.merchantMcc ?? '',
1185
+ country: this.expressConfig?.merchantCountry ?? '',
1186
+ url: this.expressConfig?.merchantUrl ?? '',
1187
+ },
1188
+ });
1189
+ };
1190
+ session.oncancel = () => {
1191
+ this.applePaySession = null;
1192
+ this.applePayPendingCallback = null;
1193
+ this.applePayPendingShippingOption = null;
1194
+ this.emitter.emit(ExpressSdkEvent.Cancel);
1195
+ };
1196
+ session.begin();
1197
+ }
1198
+ catch (e) {
1199
+ this.applePaySession = null;
1200
+ console.error('[PaypercutExpressCheckout] Failed to create ApplePaySession', {
1201
+ name: e?.name,
1202
+ message: e?.message,
1203
+ hint: e?.name === 'SecurityError'
1204
+ ? 'Page is not HTTPS or merchant domain is not registered for Apple Pay'
1205
+ : 'Check isSecureContext and that ApplePaySession.canMakePayments() returns true',
1206
+ });
1207
+ }
1208
+ }
1209
+ // ─── Google Pay native button ───────────────────
1210
+ /**
1211
+ * Called after config is fetched. Waits for the GPay script to finish loading,
1212
+ * then mounts the button.
1213
+ */
1214
+ removeGpayContainer() {
1215
+ this.gpayContainer?.remove();
1216
+ this.gpayContainer = null;
1217
+ }
1218
+ mountGooglePayFromConfig() {
1219
+ const config = this.expressConfig;
1220
+ if (!config)
1221
+ return;
1222
+ const liveMode = isLiveKey(this.options.publishableKey);
1223
+ const tenantId = config.tenantId;
1224
+ const googlePayMerchantId = config.googlePayMerchantId;
1225
+ const merchantName = config.displayName || 'Checkout';
1226
+ if (!tenantId) {
1227
+ console.error('[PaypercutExpressCheckout] tenantId is empty — Google Pay cannot be mounted without a valid gatewayMerchantId.');
1228
+ this.removeGpayContainer();
1229
+ return;
1230
+ }
1231
+ if (!googlePayMerchantId) {
1232
+ console.warn('[PaypercutExpressCheckout] googlePayMerchantId is empty — Google Pay will not be mounted (merchant may not have Google Pay active).');
1233
+ this.removeGpayContainer();
1234
+ return;
1235
+ }
1236
+ console.log({ liveMode });
1237
+ if (liveMode && (!config.merchantMcc || !config.merchantUrl)) {
1238
+ console.warn('[PaypercutExpressCheckout] Google Pay disabled!');
1239
+ this.removeGpayContainer();
1240
+ return;
1241
+ }
1242
+ loadGooglePayScript().then(() => {
1243
+ this.mountGooglePayButton(tenantId, googlePayMerchantId, merchantName, liveMode);
1244
+ }).catch((err) => {
1245
+ console.error('[PaypercutExpressCheckout] Failed to load Google Pay script:', err);
1246
+ });
1247
+ }
1248
+ mountGooglePayButton(tenantId, merchantId, merchantName, liveMode) {
1249
+ if (!this.gpayContainer) {
1250
+ console.error('[PaypercutExpressCheckout] gpayContainer is null');
1251
+ return;
1252
+ }
1253
+ const google = globalThis.google;
1254
+ if (!google?.payments?.api?.PaymentsClient) {
1255
+ console.error('[PaypercutExpressCheckout] google.payments.api.PaymentsClient not available');
1256
+ return;
1257
+ }
1258
+ const environment = liveMode ? 'PRODUCTION' : 'TEST';
1259
+ const countryCode = this.options.countryCode;
1260
+ if (!countryCode) {
1261
+ console.warn('[PaypercutExpressCheckout] countryCode is not set. This is required for Google Pay in production. Pass it via options.countryCode (e.g. "DE").');
1262
+ }
1263
+ const paymentRequest = {
1264
+ apiVersion: 2,
1265
+ apiVersionMinor: 0,
1266
+ allowedPaymentMethods: [
1267
+ {
1268
+ type: 'CARD',
1269
+ parameters: {
1270
+ allowedAuthMethods: ['CRYPTOGRAM_3DS', 'PAN_ONLY'],
1271
+ allowedCardNetworks: ['MASTERCARD', 'VISA'],
1272
+ billingAddressRequired: true,
1273
+ billingAddressParameters: {
1274
+ format: 'FULL',
1275
+ phoneNumberRequired: false,
1276
+ },
1277
+ },
1278
+ tokenizationSpecification: {
1279
+ type: 'PAYMENT_GATEWAY',
1280
+ parameters: {
1281
+ gateway: 'basistheory',
1282
+ gatewayMerchantId: tenantId,
1283
+ },
1284
+ },
1285
+ },
1286
+ ],
1287
+ merchantInfo: {
1288
+ merchantId,
1289
+ merchantName,
1290
+ },
1291
+ transactionInfo: {
1292
+ totalPriceStatus: 'FINAL',
1293
+ totalPriceLabel: 'Total',
1294
+ totalPrice: (this.options.amount / 100).toFixed(2),
1295
+ currencyCode: this.options.currency,
1296
+ countryCode,
1297
+ },
1298
+ callbackIntents: ['PAYMENT_AUTHORIZATION', 'SHIPPING_ADDRESS', 'SHIPPING_OPTION']
1299
+ ,
1300
+ };
1301
+ {
1302
+ paymentRequest.shippingAddressRequired = true;
1303
+ paymentRequest.shippingOptionRequired = true;
1304
+ if (this.options.allowedCountries?.length) {
1305
+ paymentRequest.shippingAddressParameters = {
1306
+ allowedCountryCodes: this.options.allowedCountries,
1307
+ phoneNumberRequired: false,
1308
+ };
1309
+ }
1310
+ if (this.options.shippingOptions?.length) {
1311
+ paymentRequest.shippingOptionParameters = {
1312
+ defaultSelectedOptionId: this.options.shippingOptions[0].id,
1313
+ shippingOptions: this.options.shippingOptions.map((so) => ({
1314
+ id: so.id,
1315
+ label: so.label,
1316
+ description: so.detail ?? `${(so.amount / 100).toFixed(2)} ${this.options.currency}`,
1317
+ })),
1318
+ };
1319
+ }
1320
+ }
1321
+ this.gpayPaymentRequest = paymentRequest;
1322
+ this.gpayClient = new google.payments.api.PaymentsClient({
1323
+ environment,
1324
+ paymentDataCallbacks: {
1325
+ onPaymentAuthorized: (paymentData) => this.handleGooglePayAuthorized(paymentData),
1326
+ ...({
1327
+ onPaymentDataChanged: (intermediatePaymentData) => this.handleGooglePayDataChanged(intermediatePaymentData),
1328
+ }),
1329
+ },
1330
+ });
1331
+ const buttonOpts = this.options.buttonOptions;
1332
+ const button = this.gpayClient.createButton({
1333
+ onClick: () => this.startGooglePay(paymentRequest),
1334
+ buttonSizeMode: 'fill',
1335
+ buttonType: buttonOpts?.type ?? 'plain',
1336
+ buttonColor: buttonOpts?.googlePayColor ?? 'default',
1337
+ ...(this.options.locale && { buttonLocale: normalizeGPayLocale(this.options.locale) }),
1338
+ });
1339
+ const borderRadius = buttonOpts?.borderRadius ?? '0.5rem';
1340
+ button.style.width = '100%';
1341
+ this.injectGpayInnerStyles(button, borderRadius);
1342
+ this.gpayContainer.appendChild(button);
1343
+ }
1344
+ injectGpayInnerStyles(buttonEl, borderRadius) {
1345
+ const style = document.createElement('style');
1346
+ style.textContent = `.gpay-button { height: 48px !important; border-radius: ${borderRadius} !important; background-size: auto 60% !important; } .gpay-card-info-container { border-radius: ${borderRadius} !important; } .gpay-card-info-container-fill, .gpay-card-info-container-fill > .gpay-card-info-container { height: 48px !important; }`;
1347
+ buttonEl.prepend(style);
1348
+ }
1349
+ async startGooglePay(paymentRequest) {
1350
+ if (!this.gpayClient)
1351
+ return;
1352
+ if (this.sessionActive)
1353
+ return;
1354
+ this.idempotencyKey = generateId();
1355
+ this.setSessionActive(true);
1356
+ this.emitter.emit(ExpressSdkEvent.Click);
1357
+ // Ask merchant for initial shipping options before opening the sheet.
1358
+ // If no session_start handler is registered, skip straight through.
1359
+ if (this.emitter.hasListeners(ExpressSdkEvent.SessionStart)) {
1360
+ const resolved = await new Promise((resolve) => {
1361
+ const timer = setTimeout(() => resolve(null), 3000);
1362
+ this.emitter.emit(ExpressSdkEvent.SessionStart, {
1363
+ wallet: 'google_pay',
1364
+ updateWith: (opts) => {
1365
+ clearTimeout(timer);
1366
+ resolve(opts);
1367
+ },
1368
+ });
1369
+ });
1370
+ if (!resolved) {
1371
+ // Merchant didn't respond — do not open the sheet
1372
+ this.setSessionActive(false);
1373
+ this.emitter.emit(ExpressSdkEvent.ShippingOptionsRequired, { wallet: 'google_pay' });
1374
+ return;
1375
+ }
1376
+ // Apply merchant's options before loadPaymentData
1377
+ if (resolved.shippingOptions) {
1378
+ this.currentShippingOptions = resolved.shippingOptions;
1379
+ paymentRequest.shippingOptionParameters = {
1380
+ defaultSelectedOptionId: resolved.shippingOptions[0]?.id,
1381
+ shippingOptions: resolved.shippingOptions.map((so) => ({
1382
+ id: so.id,
1383
+ label: so.label,
1384
+ description: so.detail ?? `${(so.amount / 100).toFixed(2)} ${this.options.currency}`,
1385
+ })),
1386
+ };
1387
+ }
1388
+ if (resolved.amount != null) {
1389
+ this.gpayCurrentAmount = resolved.amount;
1390
+ paymentRequest.transactionInfo = {
1391
+ ...paymentRequest.transactionInfo,
1392
+ totalPrice: (resolved.amount / 100).toFixed(2),
1393
+ };
1394
+ }
1395
+ }
1396
+ // Ensure gpayCurrentAmount is always set before the sheet opens
1397
+ if (!this.gpayCurrentAmount) {
1398
+ this.gpayCurrentAmount = this.options.amount;
1399
+ }
1400
+ try {
1401
+ await this.gpayClient.loadPaymentData(paymentRequest);
1402
+ // If 3DS was triggered, the GPay sheet is now fully dismissed — show the challenge modal.
1403
+ if (this.pending3DSAfterGpay) {
1404
+ const threeDSData = this.pending3DSAfterGpay;
1405
+ this.pending3DSAfterGpay = null;
1406
+ this.show3DSModal(threeDSData);
1407
+ }
1408
+ }
1409
+ catch (e) {
1410
+ if (e?.statusCode === 'CANCELED' || e?.message?.toLowerCase?.().includes('cancel')) {
1411
+ this.emitter.emit(ExpressSdkEvent.Cancel);
1412
+ }
1413
+ else {
1414
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(e?.message ?? 'Google Pay failed'));
1415
+ }
1416
+ }
1417
+ finally {
1418
+ this.setSessionActive(false);
1419
+ }
1420
+ }
1421
+ async handleGooglePayAuthorized(paymentData) {
1422
+ try {
1423
+ const encryptedToken = paymentData.paymentMethodData.tokenizationData.token;
1424
+ const cardNetwork = paymentData.paymentMethodData?.info?.cardNetwork ?? '';
1425
+ const billingAddr = paymentData.paymentMethodData?.info?.billingAddress;
1426
+ const shippingAddr = paymentData.shippingAddress;
1427
+ const shippingOptionData = paymentData.shippingOptionData;
1428
+ const billingDetails = billingAddr ? {
1429
+ name: billingAddr.name,
1430
+ address: {
1431
+ line1: billingAddr.address1,
1432
+ city: billingAddr.locality,
1433
+ state: billingAddr.administrativeArea,
1434
+ postalCode: billingAddr.postalCode,
1435
+ country: billingAddr.countryCode,
1436
+ },
1437
+ } : null;
1438
+ const shippingDetails = shippingAddr ? {
1439
+ name: shippingAddr.name || undefined,
1440
+ address: {
1441
+ line1: shippingAddr.address1,
1442
+ city: shippingAddr.locality,
1443
+ state: shippingAddr.administrativeArea,
1444
+ postalCode: shippingAddr.postalCode,
1445
+ country: shippingAddr.countryCode,
1446
+ },
1447
+ } : undefined;
1448
+ const selectedShippingOption = shippingOptionData
1449
+ ? (this.currentShippingOptions.find((so) => so.id === shippingOptionData.id) ?? {
1450
+ id: shippingOptionData.id,
1451
+ label: shippingOptionData.label ?? shippingOptionData.id,
1452
+ amount: 0,
1453
+ })
1454
+ : undefined;
1455
+ // Store metadata upfront — needed if 3DS triggers and the sheet closes before TOKENIZE_RESPONSE
1456
+ this.pendingGpayBillingDetails = billingDetails;
1457
+ this.pendingGpayShippingDetails = shippingDetails;
1458
+ this.pendingGpayShippingOption = selectedShippingOption;
1459
+ // Send to hidden tokenize iframe — it will BT-tokenize + create the payment method
1460
+ const tokenResult = await new Promise((resolve, reject) => {
1461
+ const timeoutId = setTimeout(() => {
1462
+ this.pendingGpayResolve = null;
1463
+ this.pendingGpayReject = null;
1464
+ reject(new Error('Tokenization timed out'));
1465
+ }, 30000);
1466
+ this.pendingGpayResolve = (result) => { clearTimeout(timeoutId); resolve(result); };
1467
+ this.pendingGpayReject = (err) => { clearTimeout(timeoutId); reject(err); };
1468
+ this.postToTokenizeIframe({
1469
+ type: 'TOKENIZE_REQUEST',
1470
+ instanceId: this.instanceId,
1471
+ wallet: 'google_pay',
1472
+ encryptedToken,
1473
+ cardNetwork,
1474
+ idemKey: this.idempotencyKey,
1475
+ publishableKey: this.options.publishableKey,
1476
+ billingDetails,
1477
+ amount: this.options.amount,
1478
+ currency: this.options.currency,
1479
+ merchantInfo: {
1480
+ name: this.expressConfig?.displayName ?? '',
1481
+ mid: this.expressConfig?.merchantMid ?? '',
1482
+ mcc: this.expressConfig?.merchantMcc ?? '',
1483
+ country: this.expressConfig?.merchantCountry ?? '',
1484
+ url: this.expressConfig?.merchantUrl ?? '',
1485
+ },
1486
+ });
1487
+ });
1488
+ // 3DS was triggered — sheet already closed, payment method creation handled in message handler
1489
+ if (tokenResult.__closeSheet) {
1490
+ return { transactionState: 'SUCCESS' };
1491
+ }
1492
+ if (!tokenResult.success) {
1493
+ const errMsg = tokenResult.error ?? 'Tokenization failed';
1494
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(errMsg));
1495
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: errMsg });
1496
+ return { transactionState: 'ERROR' };
1497
+ }
1498
+ const paymentMethodId = await this.createPaymentMethod({
1499
+ btTokenId: tokenResult.btTokenId,
1500
+ cardPayload: tokenResult.cardPayload,
1501
+ billingDetails: tokenResult.billingDetails,
1502
+ csessId: tokenResult.csessId,
1503
+ walletType: 'google_pay',
1504
+ });
1505
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodCreated, {
1506
+ paymentMethodId,
1507
+ wallet: 'google_pay',
1508
+ billingDetails: billingDetails ?? undefined,
1509
+ shippingDetails,
1510
+ selectedShippingOption,
1511
+ });
1512
+ this.pendingGpayBillingDetails = null;
1513
+ this.pendingGpayShippingDetails = null;
1514
+ this.pendingGpayShippingOption = undefined;
1515
+ return { transactionState: 'SUCCESS' };
1516
+ }
1517
+ catch (err) {
1518
+ console.error('[PaypercutExpressCheckout] handleGooglePayAuthorized error:', err?.message ?? err);
1519
+ this.emitter.emit(ExpressSdkEvent.Error, new Error(err?.message ?? 'Google Pay authorization failed'));
1520
+ this.emitter.emit(ExpressSdkEvent.PaymentMethodFailed, { error: err?.message ?? 'Google Pay authorization failed' });
1521
+ return { transactionState: 'ERROR' };
1522
+ }
1523
+ }
1524
+ /**
1525
+ * Google Pay `onPaymentDataChanged` callback.
1526
+ * Called when the user changes their shipping address or shipping option.
1527
+ */
1528
+ async handleGooglePayDataChanged(intermediatePaymentData) {
1529
+ const { callbackTrigger, shippingAddress, shippingOptionData } = intermediatePaymentData;
1530
+ if (callbackTrigger === 'INITIALIZE') {
1531
+ return buildGpayPaymentDataUpdate({
1532
+ amount: this.gpayCurrentAmount || this.options.amount,
1533
+ shippingOptions: this.currentShippingOptions,
1534
+ }, this.options.currency, this.options.countryCode);
1535
+ }
1536
+ if (callbackTrigger === 'SHIPPING_ADDRESS') {
1537
+ const update = await new Promise((resolve) => {
1538
+ this.emitter.emit(ExpressSdkEvent.ShippingAddressChange, {
1539
+ address: {
1540
+ country: shippingAddress?.countryCode ?? '',
1541
+ state: shippingAddress?.administrativeArea,
1542
+ city: shippingAddress?.locality,
1543
+ postalCode: shippingAddress?.postalCode,
1544
+ },
1545
+ updateWith: (opts) => {
1546
+ if (opts.shippingOptions)
1547
+ this.currentShippingOptions = opts.shippingOptions;
1548
+ if (opts.amount != null)
1549
+ this.gpayCurrentAmount = opts.amount;
1550
+ resolve(opts);
1551
+ },
1552
+ });
1553
+ });
1554
+ return buildGpayPaymentDataUpdate(update, this.options.currency, this.options.countryCode);
1555
+ }
1556
+ if (callbackTrigger === 'SHIPPING_OPTION') {
1557
+ const selectedId = shippingOptionData?.id;
1558
+ const selected = this.currentShippingOptions.find((so) => so.id === selectedId);
1559
+ const update = await new Promise((resolve) => {
1560
+ this.emitter.emit(ExpressSdkEvent.ShippingOptionChange, {
1561
+ shippingOption: {
1562
+ id: selectedId ?? '',
1563
+ label: selected?.label ?? selectedId ?? '',
1564
+ detail: selected?.detail,
1565
+ amount: selected?.amount ?? 0,
1566
+ },
1567
+ updateWith: (opts) => {
1568
+ if (opts.amount != null)
1569
+ this.gpayCurrentAmount = opts.amount;
1570
+ resolve(opts);
1571
+ },
1572
+ });
1573
+ });
1574
+ return buildGpayPaymentDataUpdate(update, this.options.currency, this.options.countryCode);
1575
+ }
1576
+ return {};
1577
+ }
1578
+ update(options) {
1579
+ if (!this.mounted) {
1580
+ console.warn('[PaypercutExpressCheckout] Cannot update: not mounted');
1581
+ return;
1582
+ }
1583
+ // If an Apple Pay shipping callback is waiting, resolve it directly
1584
+ if (this.applePayPendingCallback) {
1585
+ this.applePayPendingCallback.resolve(options);
1586
+ return;
1587
+ }
1588
+ }
1589
+ on(event, handler) {
1590
+ return this.emitter.on(event, handler);
1591
+ }
1592
+ destroy() {
1593
+ if (this.destroyed)
1594
+ return;
1595
+ if (this.tokenizeIframe) {
1596
+ try {
1597
+ this.tokenizeIframe.remove();
1598
+ }
1599
+ catch { }
1600
+ this.tokenizeIframe = null;
1601
+ }
1602
+ if (this.gpayContainer) {
1603
+ try {
1604
+ this.gpayContainer.remove();
1605
+ }
1606
+ catch { }
1607
+ this.gpayContainer = null;
1608
+ }
1609
+ this.applePayButtonEl = null;
1610
+ this.gpayPaymentRequest = null;
1611
+ if (this.layoutResizeObserver) {
1612
+ this.layoutResizeObserver.disconnect();
1613
+ this.layoutResizeObserver = null;
1614
+ }
1615
+ this.close3DSModal();
1616
+ this.abortApplePaySession();
1617
+ this.sessionActive = false;
1618
+ this.mounted = false;
1619
+ this.destroyed = true;
1620
+ window.removeEventListener('message', this.messageHandler);
1621
+ this.emitter.clear();
1622
+ }
1623
+ // Private helpers
1624
+ setSessionActive(active) {
1625
+ this.sessionActive = active;
1626
+ const opacity = active ? '0.5' : '';
1627
+ const pointerEvents = active ? 'none' : '';
1628
+ if (this.applePayContainer) {
1629
+ this.applePayContainer.style.opacity = opacity;
1630
+ this.applePayContainer.style.pointerEvents = pointerEvents;
1631
+ }
1632
+ if (this.gpayContainer) {
1633
+ this.gpayContainer.style.opacity = opacity;
1634
+ this.gpayContainer.style.pointerEvents = pointerEvents;
1635
+ }
1636
+ }
1637
+ completeApplePaySession(success) {
1638
+ try {
1639
+ if (this.applePaySession) {
1640
+ const ApplePayAPI = window.ApplePaySession;
1641
+ const status = success ? ApplePayAPI.STATUS_SUCCESS : ApplePayAPI.STATUS_FAILURE;
1642
+ this.applePaySession.completePayment(status);
1643
+ }
1644
+ }
1645
+ catch { }
1646
+ this.applePaySession = null;
1647
+ this.applePayPendingCallback = null;
1648
+ this.applePayPendingShippingOption = null;
1649
+ this.applePayPendingBillingDetails = null;
1650
+ this.applePayPendingShippingDetails = null;
1651
+ this.setSessionActive(false);
1652
+ }
1653
+ abortApplePaySession() {
1654
+ try {
1655
+ this.applePaySession?.abort();
1656
+ }
1657
+ catch { }
1658
+ this.applePaySession = null;
1659
+ this.applePayPendingCallback = null;
1660
+ this.applePayPendingShippingOption = null;
1661
+ this.applePayPendingBillingDetails = null;
1662
+ this.applePayPendingShippingDetails = null;
1663
+ this.setSessionActive(false);
1664
+ }
1665
+ async createPaymentMethod(params) {
1666
+ const { btTokenId, cardPayload, billingDetails, csessId, walletType } = params;
1667
+ if (!cardPayload || !btTokenId) {
1668
+ throw new Error(`[createPaymentMethod] Missing required tokenization data.`);
1669
+ }
1670
+ const url = new URL('/v1/payment_methods', getApiOrigin(this.options.apiUrl));
1671
+ const body = {
1672
+ type: 'card',
1673
+ key: this.options.publishableKey,
1674
+ card: {
1675
+ token: csessId ?? '',
1676
+ brand: cardPayload.brand ?? '',
1677
+ exp_month: cardPayload.exp_month ?? 1,
1678
+ exp_year: cardPayload.exp_year ?? 1,
1679
+ funding: cardPayload.funding ?? '',
1680
+ last4: cardPayload.last4 ?? '',
1681
+ iin: cardPayload.bin ?? '',
1682
+ issuer: cardPayload.issuer ?? null,
1683
+ fingerprint: cardPayload.fingerprint ?? null,
1684
+ segment: cardPayload.segment ?? '',
1685
+ wallet: { type: walletType, dynamic_last4: null },
1686
+ three_d_secure_usage: { supported: true },
1687
+ },
1688
+ billing_details: {
1689
+ name: billingDetails?.name ?? null,
1690
+ email: billingDetails?.email ?? null,
1691
+ phone: billingDetails?.phone ?? null,
1692
+ address: {
1693
+ city: billingDetails?.address?.city ?? null,
1694
+ country: billingDetails?.address?.country ?? null,
1695
+ line1: billingDetails?.address?.line1 ?? null,
1696
+ line2: billingDetails?.address?.line2 ?? null,
1697
+ postal_code: billingDetails?.address?.postalCode ?? null,
1698
+ state: billingDetails?.address?.state ?? null,
1699
+ },
1700
+ },
1701
+ confirmation_token: { token_id: btTokenId },
1702
+ };
1703
+ const res = await fetch(url.toString(), {
1704
+ method: 'POST',
1705
+ headers: { 'Content-Type': 'application/json' },
1706
+ body: JSON.stringify(body),
1707
+ cache: 'no-store',
1708
+ });
1709
+ if (!res.ok) {
1710
+ const msg = await res.text().catch(() => `HTTP ${res.status}`);
1711
+ throw new Error(`Payment method creation failed (${res.status}): ${msg}`);
1712
+ }
1713
+ const pm = await res.json();
1714
+ return pm.id;
1715
+ }
1716
+ postToTokenizeIframe(message) {
1717
+ if (!this.tokenizeIframe?.contentWindow) {
1718
+ return;
1719
+ }
1720
+ const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1721
+ this.tokenizeIframe.contentWindow.postMessage(message, origin);
1722
+ }
1723
+ // ─── 3DS modal (mirrors CheckoutImpl) ──────────
1724
+ show3DSModal(data) {
1725
+ this.threeDSModal = document.createElement('div');
1726
+ this.threeDSModal.id = 'paypercut-express-3ds-modal';
1727
+ Object.assign(this.threeDSModal.style, {
1728
+ position: 'fixed',
1729
+ top: '0',
1730
+ left: '0',
1731
+ width: '100%',
1732
+ height: '100%',
1733
+ display: 'flex',
1734
+ alignItems: 'center',
1735
+ justifyContent: 'center',
1736
+ zIndex: '999999',
1737
+ background: 'rgba(0, 0, 0, 0.4)',
1738
+ });
1739
+ this.threeDSIframe = document.createElement('iframe');
1740
+ const checkoutOrigin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1741
+ const threeDSUrl = new URL('/express/threeds', checkoutOrigin);
1742
+ threeDSUrl.searchParams.set('instanceId', this.instanceId);
1743
+ threeDSUrl.searchParams.set('sessionId', data.sessionId);
1744
+ threeDSUrl.searchParams.set('step', data.step);
1745
+ if (data.challengeUrl)
1746
+ threeDSUrl.searchParams.set('challengeUrl', data.challengeUrl);
1747
+ if (data.acsTransactionId)
1748
+ threeDSUrl.searchParams.set('acsTransactionId', data.acsTransactionId);
1749
+ if (data.threeDSVersion)
1750
+ threeDSUrl.searchParams.set('threeDSVersion', data.threeDSVersion);
1751
+ threeDSUrl.searchParams.set('liveMode', String(data.liveMode ?? false));
1752
+ this.threeDSIframe.src = threeDSUrl.toString();
1753
+ this.threeDSIframe.allow = 'payment *';
1754
+ this.threeDSIframe.setAttribute('frameborder', '0');
1755
+ Object.assign(this.threeDSIframe.style, {
1756
+ minWidth: '400px',
1757
+ minHeight: '400px',
1758
+ border: 'none',
1759
+ borderRadius: '8px',
1760
+ display: 'block',
1761
+ background: 'transparent',
1762
+ });
1763
+ this.threeDSModal.appendChild(this.threeDSIframe);
1764
+ document.body.appendChild(this.threeDSModal);
1765
+ this._pending3DSData = data;
1766
+ }
1767
+ handle3DSReady() {
1768
+ const data = this._pending3DSData;
1769
+ if (!data || !this.threeDSIframe?.contentWindow) {
1770
+ console.error('[PaypercutExpressCheckout] No pending 3DS data or iframe not ready');
1771
+ return;
1772
+ }
1773
+ const origin = getCheckoutOrigin(this.options.hostedCheckoutUrl);
1774
+ this.threeDSIframe.contentWindow.postMessage({ type: 'THREEDS_INIT', instanceId: this.instanceId }, origin);
1775
+ }
1776
+ close3DSModal() {
1777
+ if (this.threeDSModal) {
1778
+ this.threeDSModal.remove();
1779
+ this.threeDSModal = null;
1780
+ }
1781
+ this.threeDSIframe = null;
1782
+ delete this._pending3DSData;
1783
+ }
1784
+ }
1785
+ //Factory
1786
+ const PaypercutExpressCheckout = function (options) {
1787
+ return new ExpressCheckoutImpl(options);
1788
+ };
1789
+
281
1790
  /**
282
1791
  * Internal implementation of CheckoutInstance
283
1792
  */
@@ -688,5 +2197,5 @@ const PaypercutCheckout = function (options) {
688
2197
  // Add static version property
689
2198
  PaypercutCheckout.version = config.version;
690
2199
 
691
- export { LOCALES, PaymentMethod, PaypercutCheckout, SdkEvent, UIMode, WalletOption, PaypercutCheckout as default };
2200
+ export { ExpressSdkEvent, LOCALES, PaymentMethod, PaypercutCheckout, PaypercutExpressCheckout, SdkEvent, UIMode, WalletOption, PaypercutCheckout as default };
692
2201
  //# sourceMappingURL=index.mjs.map