@funnelfox/billing 0.9.0 → 0.9.3-feat-defer-session-on-interaction.34
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/chunk-index.cjs.js +388 -43
- package/dist/chunk-index.cjs2.js +0 -6
- package/dist/chunk-index.cjs3.js +2 -37
- package/dist/chunk-index.es.js +389 -43
- package/dist/chunk-index.es2.js +0 -6
- package/dist/chunk-index.es3.js +2 -37
- package/dist/chunk-stripe-card-form.cjs.js +37 -101
- package/dist/chunk-stripe-card-form.es.js +37 -101
- package/dist/funnelfox-billing.esm.js +1 -1
- package/dist/funnelfox-billing.js +426 -183
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +2 -2
- package/src/types.d.ts +52 -4
package/dist/chunk-index.es.js
CHANGED
|
@@ -321,20 +321,6 @@ async function loadPrimerSDK(version) {
|
|
|
321
321
|
/**
|
|
322
322
|
* @fileoverview Helper utilities for Funnefox SDK
|
|
323
323
|
*/
|
|
324
|
-
function formatCurrencyAmount(minorAmount, currency) {
|
|
325
|
-
const code = currency?.trim().toUpperCase() || 'USD';
|
|
326
|
-
try {
|
|
327
|
-
const formatter = new Intl.NumberFormat(undefined, {
|
|
328
|
-
style: 'currency',
|
|
329
|
-
currency: code,
|
|
330
|
-
});
|
|
331
|
-
const fractionDigits = formatter.resolvedOptions().maximumFractionDigits ?? 2;
|
|
332
|
-
return formatter.format(minorAmount / 10 ** fractionDigits);
|
|
333
|
-
}
|
|
334
|
-
catch {
|
|
335
|
-
return `${(minorAmount / 100).toFixed(2)} ${code}`;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
324
|
function merge(...objects) {
|
|
339
325
|
const result = {};
|
|
340
326
|
for (const obj of objects) {
|
|
@@ -503,7 +489,7 @@ var PaymentMethod;
|
|
|
503
489
|
/**
|
|
504
490
|
* @fileoverview Constants for Funnefox SDK
|
|
505
491
|
*/
|
|
506
|
-
const SDK_VERSION = '0.9.
|
|
492
|
+
const SDK_VERSION = '0.9.3-feat-defer-session-on-interaction.34';
|
|
507
493
|
const DEFAULTS = {
|
|
508
494
|
BASE_URL: 'https://billing.funnelfox.com',
|
|
509
495
|
REGION: 'default',
|
|
@@ -640,6 +626,141 @@ function requireString(value, fieldName) {
|
|
|
640
626
|
return true;
|
|
641
627
|
}
|
|
642
628
|
|
|
629
|
+
/**
|
|
630
|
+
* @fileoverview Support for Apple's official <apple-pay-button> custom element.
|
|
631
|
+
*
|
|
632
|
+
* Primer's checkout-web v2 renders the Apple Pay button through the CSS
|
|
633
|
+
* approach (-webkit-appearance: -apple-pay-button), and WebKit only accepts
|
|
634
|
+
* the 7 legacy values for -apple-pay-button-type. Newer types such as
|
|
635
|
+
* 'continue' are silently dropped and fall back to 'plain' (verified in
|
|
636
|
+
* Safari 26 on macOS and iOS — see PRD-1426).
|
|
637
|
+
*
|
|
638
|
+
* Apple's official custom element supports the full set of button types, so
|
|
639
|
+
* for "native-only" types we overlay it on top of the (visually hidden)
|
|
640
|
+
* Primer button and forward clicks, keeping Primer's payment flow untouched.
|
|
641
|
+
*/
|
|
642
|
+
const APPLE_PAY_SDK_URL = 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';
|
|
643
|
+
/** How long to wait for the <apple-pay-button> element definition before
|
|
644
|
+
* giving up and falling back to Primer's own button. */
|
|
645
|
+
const ELEMENT_DEFINITION_TIMEOUT_MS = 4000;
|
|
646
|
+
/**
|
|
647
|
+
* Button types WebKit can render through Primer's CSS approach.
|
|
648
|
+
* Everything outside this list requires the native <apple-pay-button> element.
|
|
649
|
+
*/
|
|
650
|
+
const CSS_RENDERABLE_APPLE_PAY_TYPES = [
|
|
651
|
+
'plain',
|
|
652
|
+
'buy',
|
|
653
|
+
'set-up',
|
|
654
|
+
'donate',
|
|
655
|
+
'check-out',
|
|
656
|
+
'book',
|
|
657
|
+
'subscribe',
|
|
658
|
+
];
|
|
659
|
+
/**
|
|
660
|
+
* Returns true when the requested Apple Pay buttonType can only be rendered
|
|
661
|
+
* with Apple's native <apple-pay-button> element.
|
|
662
|
+
*/
|
|
663
|
+
function isNativeOnlyApplePayButtonType(type) {
|
|
664
|
+
return !!type && !CSS_RENDERABLE_APPLE_PAY_TYPES.includes(type);
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Loads Apple's apple-pay-sdk.js (defines the <apple-pay-button> custom
|
|
668
|
+
* element). Resolves to true when the element is available.
|
|
669
|
+
*/
|
|
670
|
+
async function loadApplePayButtonElement() {
|
|
671
|
+
if (typeof window === 'undefined' || !window.customElements) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
if (window.customElements.get('apple-pay-button')) {
|
|
675
|
+
return true;
|
|
676
|
+
}
|
|
677
|
+
try {
|
|
678
|
+
await loadScript$1({
|
|
679
|
+
src: APPLE_PAY_SDK_URL,
|
|
680
|
+
crossOrigin: 'anonymous',
|
|
681
|
+
appendTo: 'head',
|
|
682
|
+
});
|
|
683
|
+
// Never hang on a script that loaded but did not define the element —
|
|
684
|
+
// fall back to Primer's own button instead.
|
|
685
|
+
const defined = window.customElements
|
|
686
|
+
.whenDefined('apple-pay-button')
|
|
687
|
+
.then(() => true);
|
|
688
|
+
const timeout = new Promise(resolve => {
|
|
689
|
+
setTimeout(() => resolve(false), ELEMENT_DEFINITION_TIMEOUT_MS);
|
|
690
|
+
});
|
|
691
|
+
return await Promise.race([defined, timeout]);
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function createNativeApplePayElement(options) {
|
|
698
|
+
const native = document.createElement('apple-pay-button');
|
|
699
|
+
native.setAttribute('type', options.buttonType);
|
|
700
|
+
native.setAttribute('buttonstyle', options.buttonStyle || 'black');
|
|
701
|
+
native.setAttribute('locale', (typeof navigator !== 'undefined' && navigator.language) || 'en-US');
|
|
702
|
+
native.style.cssText = [
|
|
703
|
+
'position:absolute',
|
|
704
|
+
'inset:0',
|
|
705
|
+
'width:100%',
|
|
706
|
+
'height:100%',
|
|
707
|
+
'--apple-pay-button-width:100%',
|
|
708
|
+
'--apple-pay-button-height:100%',
|
|
709
|
+
'--apple-pay-button-border-radius:28px',
|
|
710
|
+
'display:block',
|
|
711
|
+
'cursor:pointer',
|
|
712
|
+
'z-index:1',
|
|
713
|
+
].join(';');
|
|
714
|
+
return native;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Renders Apple's native <apple-pay-button> stretched over `wrapper` and
|
|
718
|
+
* forwards clicks to the Primer-rendered <button> inside it. The synchronous
|
|
719
|
+
* forwarded click preserves the user activation required by ApplePaySession.
|
|
720
|
+
*
|
|
721
|
+
* Returns the overlay element, or null when the Apple Pay SDK could not be
|
|
722
|
+
* loaded (callers should keep Primer's own button visible as a fallback).
|
|
723
|
+
*/
|
|
724
|
+
async function overlayNativeApplePayButton(wrapper, options) {
|
|
725
|
+
const available = await loadApplePayButtonElement();
|
|
726
|
+
if (!available) {
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
// The overlay is only safe when Primer's own clickable button is present —
|
|
730
|
+
// otherwise there is nothing to forward the click to.
|
|
731
|
+
if (!wrapper.querySelector('button')) {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
const native = createNativeApplePayElement(options);
|
|
735
|
+
wrapper.style.position = 'relative';
|
|
736
|
+
native.addEventListener('click', () => {
|
|
737
|
+
const primerButton = wrapper.querySelector('button');
|
|
738
|
+
primerButton?.click();
|
|
739
|
+
});
|
|
740
|
+
wrapper.appendChild(native);
|
|
741
|
+
return native;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Renders the native button with no Primer button behind it, for the deferred
|
|
745
|
+
* flow: the visitor sees the real Apple Pay button immediately while the
|
|
746
|
+
* client session is still un-created. `onActivate` fires on tap so the caller
|
|
747
|
+
* can start (or await) initialization.
|
|
748
|
+
*
|
|
749
|
+
* Returns null when Apple's SDK is unavailable — callers must fall back to
|
|
750
|
+
* creating the session eagerly so a button of some kind is always rendered.
|
|
751
|
+
*/
|
|
752
|
+
async function renderPlaceholderApplePayButton(wrapper, options) {
|
|
753
|
+
const available = await loadApplePayButtonElement();
|
|
754
|
+
if (!available) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const native = createNativeApplePayElement(options);
|
|
758
|
+
wrapper.style.position = 'relative';
|
|
759
|
+
native.addEventListener('click', options.onActivate);
|
|
760
|
+
wrapper.appendChild(native);
|
|
761
|
+
return native;
|
|
762
|
+
}
|
|
763
|
+
|
|
643
764
|
/**
|
|
644
765
|
* @fileoverview Primer SDK integration wrapper
|
|
645
766
|
*/
|
|
@@ -678,6 +799,7 @@ class PrimerWrapper {
|
|
|
678
799
|
}
|
|
679
800
|
async createHeadlessCheckout(clientToken, options, method) {
|
|
680
801
|
await this.ensurePrimerLoaded();
|
|
802
|
+
this.applePayOptions = options.applePay;
|
|
681
803
|
this.currentHeadless = PrimerWrapper.headlessManager.getOrCreate(clientToken, options, method);
|
|
682
804
|
return this.currentHeadless;
|
|
683
805
|
}
|
|
@@ -724,16 +846,53 @@ class PrimerWrapper {
|
|
|
724
846
|
}
|
|
725
847
|
htmlNode.appendChild(wrapper);
|
|
726
848
|
/* end hack */
|
|
849
|
+
/* PRD-1426: WebKit cannot render newer Apple Pay button types (e.g.
|
|
850
|
+
* 'continue') through the CSS approach Primer v2 uses. For those types
|
|
851
|
+
* we overlay Apple's official <apple-pay-button> element on top of the
|
|
852
|
+
* visually hidden Primer button and forward clicks, keeping Primer's
|
|
853
|
+
* payment flow untouched. The Primer button is hidden BEFORE it renders
|
|
854
|
+
* to avoid a flash of the plain button; if the Apple SDK fails to load,
|
|
855
|
+
* the rule is removed and Primer's own button stays visible (graceful
|
|
856
|
+
* fallback to 'plain'). */
|
|
857
|
+
const applePayConfig = this.applePayOptions;
|
|
858
|
+
const nativeButtonType = allowedPaymentMethod === PaymentMethod.APPLE_PAY &&
|
|
859
|
+
applePayConfig?.buttonType &&
|
|
860
|
+
isNativeOnlyApplePayButtonType(applePayConfig.buttonType)
|
|
861
|
+
? applePayConfig.buttonType
|
|
862
|
+
: null;
|
|
863
|
+
let hideRuleIndex = null;
|
|
864
|
+
if (nativeButtonType && sheet) {
|
|
865
|
+
hideRuleIndex = sheet.insertRule(`
|
|
866
|
+
.${wrapper.className} > button {
|
|
867
|
+
opacity: 0 !important;
|
|
868
|
+
}
|
|
869
|
+
`);
|
|
870
|
+
}
|
|
727
871
|
button = pmManager.createButton();
|
|
728
872
|
await button.render(wrapper, {});
|
|
873
|
+
let nativeOverlay = null;
|
|
874
|
+
if (nativeButtonType) {
|
|
875
|
+
nativeOverlay = await overlayNativeApplePayButton(wrapper, {
|
|
876
|
+
buttonType: nativeButtonType,
|
|
877
|
+
buttonStyle: applePayConfig?.buttonStyle,
|
|
878
|
+
});
|
|
879
|
+
if (!nativeOverlay && sheet && hideRuleIndex !== null) {
|
|
880
|
+
sheet.deleteRule(hideRuleIndex);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
729
883
|
this.destroyCallbacks.push(() => button.clean());
|
|
730
884
|
onMethodRender(allowedPaymentMethod);
|
|
731
885
|
return {
|
|
732
886
|
setDisabled: (disabled) => {
|
|
733
887
|
button.setDisabled(disabled);
|
|
888
|
+
if (nativeOverlay) {
|
|
889
|
+
nativeOverlay.style.pointerEvents = disabled ? 'none' : '';
|
|
890
|
+
nativeOverlay.style.opacity = disabled ? '0.5' : '';
|
|
891
|
+
}
|
|
734
892
|
},
|
|
735
893
|
destroy: () => {
|
|
736
894
|
styleEl.remove();
|
|
895
|
+
nativeOverlay?.remove();
|
|
737
896
|
button.clean();
|
|
738
897
|
},
|
|
739
898
|
};
|
|
@@ -1080,6 +1239,32 @@ class PrimerWrapper {
|
|
|
1080
1239
|
}
|
|
1081
1240
|
PrimerWrapper.headlessManager = new HeadlessManager();
|
|
1082
1241
|
|
|
1242
|
+
/**
|
|
1243
|
+
* @fileoverview Tags the deferred session request so the warm-up trigger can
|
|
1244
|
+
* be measured without adding a single extra network call.
|
|
1245
|
+
*
|
|
1246
|
+
* The backend already logs every request header, so `X-FF-Warmup` lands in
|
|
1247
|
+
* Elasticsearch for free. That gives us, per session actually created:
|
|
1248
|
+
* - which signal started it (dwell vs interaction vs a cold tap)
|
|
1249
|
+
* - how long after mount it fired
|
|
1250
|
+
*
|
|
1251
|
+
* Which is what tells us whether the dwell can be lengthened (more savings)
|
|
1252
|
+
* or must stay short (cold-tap risk), instead of guessing at an interaction
|
|
1253
|
+
* rate nobody has measured.
|
|
1254
|
+
*/
|
|
1255
|
+
const WARMUP_HEADER = 'X-FF-Warmup';
|
|
1256
|
+
let pendingTag = null;
|
|
1257
|
+
/** Records the trigger for the session request that is about to be sent. */
|
|
1258
|
+
function setWarmupTag(trigger, msSinceMount) {
|
|
1259
|
+
pendingTag = `${trigger};${Math.max(0, Math.round(msSinceMount))}`;
|
|
1260
|
+
}
|
|
1261
|
+
/** Consumes the tag — it describes one request only. */
|
|
1262
|
+
function takeWarmupTag() {
|
|
1263
|
+
const tag = pendingTag;
|
|
1264
|
+
pendingTag = null;
|
|
1265
|
+
return tag;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1083
1268
|
/**
|
|
1084
1269
|
* @fileoverview API client for Funnefox backend integration
|
|
1085
1270
|
*/
|
|
@@ -1097,6 +1282,7 @@ class APIClient {
|
|
|
1097
1282
|
headers: {
|
|
1098
1283
|
'Content-Type': 'application/json',
|
|
1099
1284
|
'X-SDK-Version': SDK_VERSION,
|
|
1285
|
+
...warmupHeader(),
|
|
1100
1286
|
...(options.headers || {}),
|
|
1101
1287
|
},
|
|
1102
1288
|
...options,
|
|
@@ -1311,6 +1497,10 @@ class APIClient {
|
|
|
1311
1497
|
}));
|
|
1312
1498
|
}
|
|
1313
1499
|
}
|
|
1500
|
+
function warmupHeader() {
|
|
1501
|
+
const tag = takeWarmupTag();
|
|
1502
|
+
return tag ? { [WARMUP_HEADER]: tag } : {};
|
|
1503
|
+
}
|
|
1314
1504
|
|
|
1315
1505
|
class SessionService {
|
|
1316
1506
|
constructor() {
|
|
@@ -1393,6 +1583,96 @@ const hideLoader = () => {
|
|
|
1393
1583
|
}
|
|
1394
1584
|
};
|
|
1395
1585
|
|
|
1586
|
+
/**
|
|
1587
|
+
* @fileoverview Decides when a deferred client session should be created.
|
|
1588
|
+
*
|
|
1589
|
+
* Fires on whichever comes first: the visitor's first interaction, or a short
|
|
1590
|
+
* dwell once the page is actually visible. The dwell is what makes the
|
|
1591
|
+
* deferral safe — ApplePaySession must be constructed inside the tap gesture,
|
|
1592
|
+
* so the session has to exist *before* the first tap. A human cannot read a
|
|
1593
|
+
* price and tap in under ~800ms, whereas prerenders, background tabs, crawlers
|
|
1594
|
+
* and instant bounces never reach the dwell at all and so never cost a
|
|
1595
|
+
* session (nor the order row behind it).
|
|
1596
|
+
*/
|
|
1597
|
+
const INTERACTION_EVENTS = [
|
|
1598
|
+
'pointerdown',
|
|
1599
|
+
'touchstart',
|
|
1600
|
+
'keydown',
|
|
1601
|
+
'wheel',
|
|
1602
|
+
'scroll',
|
|
1603
|
+
];
|
|
1604
|
+
/** Long enough to filter prerenders and instant bounces, far shorter than
|
|
1605
|
+
* any realistic time-to-tap on a paywall. */
|
|
1606
|
+
const DEFAULT_WARMUP_DWELL_MS = 800;
|
|
1607
|
+
/** True while the page is prerendering or not visible to the user. */
|
|
1608
|
+
function isPageHidden() {
|
|
1609
|
+
if (typeof document === 'undefined') {
|
|
1610
|
+
return true;
|
|
1611
|
+
}
|
|
1612
|
+
if (document.prerendering) {
|
|
1613
|
+
return true;
|
|
1614
|
+
}
|
|
1615
|
+
return document.visibilityState === 'hidden';
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Invokes `handler` once — on first interaction, or after `dwellMs` of visible
|
|
1619
|
+
* time, whichever happens first. Returns a cleanup for the un-fired case.
|
|
1620
|
+
*/
|
|
1621
|
+
function onSessionWarmup(handler, dwellMs = DEFAULT_WARMUP_DWELL_MS) {
|
|
1622
|
+
if (typeof document === 'undefined') {
|
|
1623
|
+
return () => { };
|
|
1624
|
+
}
|
|
1625
|
+
let fired = false;
|
|
1626
|
+
let timer;
|
|
1627
|
+
const cleanup = () => {
|
|
1628
|
+
if (timer !== undefined) {
|
|
1629
|
+
clearTimeout(timer);
|
|
1630
|
+
timer = undefined;
|
|
1631
|
+
}
|
|
1632
|
+
for (const event of INTERACTION_EVENTS) {
|
|
1633
|
+
document.removeEventListener(event, onInteraction, true);
|
|
1634
|
+
}
|
|
1635
|
+
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
1636
|
+
document.removeEventListener('prerenderingchange', onVisibilityChange);
|
|
1637
|
+
};
|
|
1638
|
+
const fire = (source) => {
|
|
1639
|
+
if (fired) {
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
fired = true;
|
|
1643
|
+
cleanup();
|
|
1644
|
+
handler(source);
|
|
1645
|
+
};
|
|
1646
|
+
function onInteraction() {
|
|
1647
|
+
if (!isPageHidden()) {
|
|
1648
|
+
fire('interaction');
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
function startDwell() {
|
|
1652
|
+
if (fired || timer !== undefined) {
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
timer = setTimeout(() => fire('dwell'), dwellMs);
|
|
1656
|
+
}
|
|
1657
|
+
function onVisibilityChange() {
|
|
1658
|
+
if (!isPageHidden()) {
|
|
1659
|
+
startDwell();
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
for (const event of INTERACTION_EVENTS) {
|
|
1663
|
+
document.addEventListener(event, onInteraction, {
|
|
1664
|
+
capture: true,
|
|
1665
|
+
passive: true,
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
1669
|
+
document.addEventListener('prerenderingchange', onVisibilityChange);
|
|
1670
|
+
if (!isPageHidden()) {
|
|
1671
|
+
startDwell();
|
|
1672
|
+
}
|
|
1673
|
+
return cleanup;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1396
1676
|
var V3_URL = 'https://js.stripe.com/v3';
|
|
1397
1677
|
var V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
|
|
1398
1678
|
var EXISTING_SCRIPT_MESSAGE = 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';
|
|
@@ -1893,14 +2173,6 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1893
2173
|
this.emitTaxInfo(info);
|
|
1894
2174
|
}
|
|
1895
2175
|
};
|
|
1896
|
-
// Re-render the current tax figures to a skin that subscribed after the estimate was first
|
|
1897
|
-
// emitted (the initMethod card path wires the skin only once the method mounts).
|
|
1898
|
-
this.renderTaxToSkin = () => {
|
|
1899
|
-
const info = this.lastTaxInfo ?? this.getSessionTaxInfo();
|
|
1900
|
-
if (info) {
|
|
1901
|
-
this.emit(EVENTS.TAX_CHANGE, info);
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
2176
|
this.runTaxRecalc = async () => {
|
|
1905
2177
|
const orderId = this.orderId;
|
|
1906
2178
|
const countryCode = this.getSelectedCountryCode();
|
|
@@ -1957,11 +2229,6 @@ class CheckoutInstance extends EventEmitter {
|
|
|
1957
2229
|
this.handleMethodRender = (method) => {
|
|
1958
2230
|
this.emit(EVENTS.METHOD_RENDER, method);
|
|
1959
2231
|
};
|
|
1960
|
-
this.handleTaxMethodRender = (method) => {
|
|
1961
|
-
if (method === PaymentMethod.PAYMENT_CARD && this.isTaxEnabled()) {
|
|
1962
|
-
this.renderTaxToSkin();
|
|
1963
|
-
}
|
|
1964
|
-
};
|
|
1965
2232
|
this.handleMethodRenderError = (method) => {
|
|
1966
2233
|
this.emit(EVENTS.METHOD_RENDER_ERROR, method);
|
|
1967
2234
|
};
|
|
@@ -2534,13 +2801,6 @@ class CheckoutInstance extends EventEmitter {
|
|
|
2534
2801
|
const skin = await skinFactory(this.checkoutConfig, this.cardSessionFieldConfig);
|
|
2535
2802
|
this.on(EVENTS.INPUT_ERROR, skin.onInputError);
|
|
2536
2803
|
this.on(EVENTS.STATUS_CHANGE, skin.onStatusChange);
|
|
2537
|
-
if (skin.onTaxChange) {
|
|
2538
|
-
this.on(EVENTS.TAX_CHANGE, skin.onTaxChange);
|
|
2539
|
-
}
|
|
2540
|
-
if (skin.onTaxPending) {
|
|
2541
|
-
this.on(EVENTS.TAX_PENDING, skin.onTaxPending);
|
|
2542
|
-
}
|
|
2543
|
-
this.on(EVENTS.METHOD_RENDER, this.handleTaxMethodRender);
|
|
2544
2804
|
this.on(EVENTS.ERROR, (error) => skin.onError(error));
|
|
2545
2805
|
this.on(EVENTS.LOADER_CHANGE, skin.onLoaderChange);
|
|
2546
2806
|
this.on(EVENTS.DESTROY, skin.onDestroy);
|
|
@@ -2558,13 +2818,6 @@ class CheckoutInstance extends EventEmitter {
|
|
|
2558
2818
|
skin.init();
|
|
2559
2819
|
this.on(EVENTS.INPUT_ERROR, skin.onInputError);
|
|
2560
2820
|
this.on(EVENTS.METHOD_RENDER, skin.onMethodRender);
|
|
2561
|
-
if (skin.onTaxChange) {
|
|
2562
|
-
this.on(EVENTS.TAX_CHANGE, skin.onTaxChange);
|
|
2563
|
-
}
|
|
2564
|
-
if (skin.onTaxPending) {
|
|
2565
|
-
this.on(EVENTS.TAX_PENDING, skin.onTaxPending);
|
|
2566
|
-
}
|
|
2567
|
-
this.on(EVENTS.METHOD_RENDER, this.handleTaxMethodRender);
|
|
2568
2821
|
this.on(EVENTS.SUCCESS, skin.onDestroy);
|
|
2569
2822
|
this.on(EVENTS.DESTROY, skin.onDestroy);
|
|
2570
2823
|
return skin.getCheckoutOptions();
|
|
@@ -2577,6 +2830,98 @@ class CheckoutInstance extends EventEmitter {
|
|
|
2577
2830
|
}
|
|
2578
2831
|
async initMethod(method, element, callbacks) {
|
|
2579
2832
|
this._ensureNotDestroyed();
|
|
2833
|
+
const deferred = await this.initMethodDeferred(method, element, callbacks);
|
|
2834
|
+
if (deferred) {
|
|
2835
|
+
return deferred;
|
|
2836
|
+
}
|
|
2837
|
+
return await this.initMethodNow(method, element, callbacks);
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Renders Apple's native button immediately and postpones session creation
|
|
2841
|
+
* until the visitor interacts. Returns null when deferral does not apply, so
|
|
2842
|
+
* the caller falls back to creating the session on mount.
|
|
2843
|
+
*/
|
|
2844
|
+
async initMethodDeferred(method, element, callbacks) {
|
|
2845
|
+
const applePay = this.checkoutConfig.applePay;
|
|
2846
|
+
const buttonType = applePay?.buttonType;
|
|
2847
|
+
if (this.checkoutConfig.sessionCreation !== 'onInteraction' ||
|
|
2848
|
+
method !== PaymentMethod.APPLE_PAY ||
|
|
2849
|
+
this.isReady() ||
|
|
2850
|
+
!buttonType ||
|
|
2851
|
+
!isNativeOnlyApplePayButtonType(buttonType)) {
|
|
2852
|
+
return null;
|
|
2853
|
+
}
|
|
2854
|
+
let started = null;
|
|
2855
|
+
let real = null;
|
|
2856
|
+
let disabled = false;
|
|
2857
|
+
let stopWaiting = () => { };
|
|
2858
|
+
let placeholder = null;
|
|
2859
|
+
const mountedAt = Date.now();
|
|
2860
|
+
const start = (trigger) => {
|
|
2861
|
+
const fromTap = trigger === 'tap';
|
|
2862
|
+
if (!started) {
|
|
2863
|
+
setWarmupTag(trigger, Date.now() - mountedAt);
|
|
2864
|
+
started = (async () => {
|
|
2865
|
+
stopWaiting();
|
|
2866
|
+
if (fromTap) {
|
|
2867
|
+
callbacks.onLoaderChange?.(true);
|
|
2868
|
+
}
|
|
2869
|
+
try {
|
|
2870
|
+
placeholder?.remove();
|
|
2871
|
+
placeholder = null;
|
|
2872
|
+
const methodInterface = await this.initMethodNow(method, element, callbacks);
|
|
2873
|
+
real = methodInterface;
|
|
2874
|
+
if (disabled) {
|
|
2875
|
+
methodInterface.setDisabled(true);
|
|
2876
|
+
}
|
|
2877
|
+
return methodInterface;
|
|
2878
|
+
}
|
|
2879
|
+
finally {
|
|
2880
|
+
if (fromTap) {
|
|
2881
|
+
callbacks.onLoaderChange?.(false);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
})();
|
|
2885
|
+
}
|
|
2886
|
+
return started;
|
|
2887
|
+
};
|
|
2888
|
+
placeholder = await renderPlaceholderApplePayButton(element, {
|
|
2889
|
+
buttonType,
|
|
2890
|
+
buttonStyle: applePay?.buttonStyle,
|
|
2891
|
+
// Cold tap: the visitor's first interaction is the button itself, so the
|
|
2892
|
+
// session cannot exist yet and ApplePaySession would lose the gesture.
|
|
2893
|
+
// Start now and let the loader cover the (rare) second tap.
|
|
2894
|
+
onActivate: () => void start('tap'),
|
|
2895
|
+
});
|
|
2896
|
+
if (!placeholder) {
|
|
2897
|
+
return null;
|
|
2898
|
+
}
|
|
2899
|
+
// Free head start: Primer's SDK is a static asset on their CDN, so
|
|
2900
|
+
// fetching it now costs no backend call and leaves only the session
|
|
2901
|
+
// request to complete before the first tap.
|
|
2902
|
+
void loadPrimerSDK().catch(() => { });
|
|
2903
|
+
stopWaiting = onSessionWarmup(trigger => void start(trigger));
|
|
2904
|
+
return {
|
|
2905
|
+
setDisabled: (value) => {
|
|
2906
|
+
disabled = value;
|
|
2907
|
+
real?.setDisabled(value);
|
|
2908
|
+
if (placeholder) {
|
|
2909
|
+
placeholder.style.pointerEvents = value ? 'none' : '';
|
|
2910
|
+
placeholder.style.opacity = value ? '0.5' : '';
|
|
2911
|
+
}
|
|
2912
|
+
},
|
|
2913
|
+
destroy: async () => {
|
|
2914
|
+
stopWaiting();
|
|
2915
|
+
placeholder?.remove();
|
|
2916
|
+
placeholder = null;
|
|
2917
|
+
if (started) {
|
|
2918
|
+
await (await started).destroy?.();
|
|
2919
|
+
}
|
|
2920
|
+
await this.destroy();
|
|
2921
|
+
},
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
async initMethodNow(method, element, callbacks) {
|
|
2580
2925
|
if (!this.isReady()) {
|
|
2581
2926
|
await this.createSession();
|
|
2582
2927
|
}
|
|
@@ -2794,6 +3139,7 @@ async function initMethod(method, element, options) {
|
|
|
2794
3139
|
...DEFAULT_BUTTONS_OPTIONS[PaymentMethod.GOOGLE_PAY],
|
|
2795
3140
|
...(options.googlePay || {}),
|
|
2796
3141
|
},
|
|
3142
|
+
sessionCreation: options.sessionCreation,
|
|
2797
3143
|
},
|
|
2798
3144
|
});
|
|
2799
3145
|
return await checkoutInstance.initMethod(method, element, {
|
|
@@ -2970,4 +3316,4 @@ if (typeof window !== 'undefined') {
|
|
|
2970
3316
|
}
|
|
2971
3317
|
console.debug('Billing SDK inited');
|
|
2972
3318
|
|
|
2973
|
-
export { APIError as A, Billing as B, CheckoutError as C, DEFAULT_BUTTONS_OPTIONS as D, EVENTS as E, FunnefoxSDKError as F, NetworkError as N, PaymentMethod as P, SDK_VERSION as S, ValidationError as V, PrimerError as a, ConfigurationError as b, DEFAULTS as c, CHECKOUT_STATES as d, ERROR_CODES as e,
|
|
3319
|
+
export { APIError as A, Billing as B, CheckoutError as C, DEFAULT_BUTTONS_OPTIONS as D, EVENTS as E, FunnefoxSDKError as F, NetworkError as N, PaymentMethod as P, SDK_VERSION as S, ValidationError as V, PrimerError as a, ConfigurationError as b, DEFAULTS as c, CHECKOUT_STATES as d, ERROR_CODES as e, configure as f, createCheckout as g, createClientSession as h, getAvailablePaymentMethods as i, loadStripe as l };
|
package/dist/chunk-index.es2.js
CHANGED
|
@@ -81,12 +81,6 @@ class DefaultSkin {
|
|
|
81
81
|
this.onInputError = (event) => {
|
|
82
82
|
this.cardInstance.onInputError(event);
|
|
83
83
|
};
|
|
84
|
-
this.onTaxChange = (info) => {
|
|
85
|
-
this.cardInstance.onTaxChange(info);
|
|
86
|
-
};
|
|
87
|
-
this.onTaxPending = () => {
|
|
88
|
-
this.cardInstance.onTaxPending();
|
|
89
|
-
};
|
|
90
84
|
this.onMethodRender = (paymentMethod) => {
|
|
91
85
|
const methodKey = paymentMethod.replace('_', '-').toLowerCase();
|
|
92
86
|
const methodContainer = this.containerEl.querySelector(`.ff-payment-method-${methodKey}`);
|