@funnelsgrove/payments 0.11.12 → 0.11.13
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.
|
@@ -32,9 +32,11 @@ const buildDefaultOptions = () => ({
|
|
|
32
32
|
export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail = true, customerEmail, className, options, availabilityPaymentMethods = ['applePay'], initialAvailable, keepInitialAvailableOnReady = false, serverUpdateKey, supportedCountries, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onSuccess, unsupportedCountryMessage, }) {
|
|
33
33
|
const checkoutState = useCheckout();
|
|
34
34
|
const appliedServerUpdateKeyRef = useRef('');
|
|
35
|
+
const [appliedServerUpdateKey, setAppliedServerUpdateKey] = useState('');
|
|
35
36
|
const serverUpdatePromiseRef = useRef(null);
|
|
36
37
|
const [walletAvailable, setWalletAvailable] = useState(initialAvailable !== null && initialAvailable !== void 0 ? initialAvailable : null);
|
|
37
38
|
const normalizedServerUpdateKey = (serverUpdateKey === null || serverUpdateKey === void 0 ? void 0 : serverUpdateKey.trim()) || '';
|
|
39
|
+
const serverUpdatePending = Boolean(normalizedServerUpdateKey && appliedServerUpdateKey !== normalizedServerUpdateKey);
|
|
38
40
|
const effectiveWalletAvailable = initialAvailable === true && walletAvailable !== false
|
|
39
41
|
? true
|
|
40
42
|
: walletAvailable;
|
|
@@ -45,6 +47,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
45
47
|
return Object.assign(Object.assign(Object.assign({}, baseOptions), (options !== null && options !== void 0 ? options : {})), { buttonTheme: Object.assign(Object.assign({}, ((_a = baseOptions.buttonTheme) !== null && _a !== void 0 ? _a : {})), ((_b = options === null || options === void 0 ? void 0 : options.buttonTheme) !== null && _b !== void 0 ? _b : {})), buttonType: Object.assign(Object.assign({}, ((_c = baseOptions.buttonType) !== null && _c !== void 0 ? _c : {})), ((_d = options === null || options === void 0 ? void 0 : options.buttonType) !== null && _d !== void 0 ? _d : {})), layout: Object.assign(Object.assign({}, ((_e = baseOptions.layout) !== null && _e !== void 0 ? _e : {})), ((_f = options === null || options === void 0 ? void 0 : options.layout) !== null && _f !== void 0 ? _f : {})), paymentMethods: Object.assign(Object.assign({}, ((_g = baseOptions.paymentMethods) !== null && _g !== void 0 ? _g : {})), ((_h = options === null || options === void 0 ? void 0 : options.paymentMethods) !== null && _h !== void 0 ? _h : {})), paymentMethodOrder: (_j = options === null || options === void 0 ? void 0 : options.paymentMethodOrder) !== null && _j !== void 0 ? _j : baseOptions.paymentMethodOrder });
|
|
46
48
|
}, [baseOptions, options]);
|
|
47
49
|
const ensureServerUpdated = useCallback(async (paymentMethod) => {
|
|
50
|
+
var _a;
|
|
48
51
|
if (!normalizedServerUpdateKey) {
|
|
49
52
|
return true;
|
|
50
53
|
}
|
|
@@ -55,7 +58,14 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
55
58
|
return false;
|
|
56
59
|
}
|
|
57
60
|
if (serverUpdatePromiseRef.current) {
|
|
58
|
-
|
|
61
|
+
const pendingUpdate = serverUpdatePromiseRef.current;
|
|
62
|
+
const pendingResult = await pendingUpdate.promise;
|
|
63
|
+
if (pendingUpdate.key === normalizedServerUpdateKey) {
|
|
64
|
+
return pendingResult;
|
|
65
|
+
}
|
|
66
|
+
if (appliedServerUpdateKeyRef.current === normalizedServerUpdateKey) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
const updatePromise = (async () => {
|
|
61
71
|
let updateCallbackFailed = false;
|
|
@@ -85,20 +95,27 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
85
95
|
return false;
|
|
86
96
|
}
|
|
87
97
|
appliedServerUpdateKeyRef.current = normalizedServerUpdateKey;
|
|
98
|
+
setAppliedServerUpdateKey(normalizedServerUpdateKey);
|
|
88
99
|
onError === null || onError === void 0 ? void 0 : onError(null);
|
|
89
100
|
return true;
|
|
90
101
|
})();
|
|
91
|
-
serverUpdatePromiseRef.current =
|
|
102
|
+
serverUpdatePromiseRef.current = {
|
|
103
|
+
key: normalizedServerUpdateKey,
|
|
104
|
+
promise: updatePromise,
|
|
105
|
+
};
|
|
92
106
|
try {
|
|
93
107
|
return await updatePromise;
|
|
94
108
|
}
|
|
95
109
|
finally {
|
|
96
|
-
serverUpdatePromiseRef.current
|
|
110
|
+
if (((_a = serverUpdatePromiseRef.current) === null || _a === void 0 ? void 0 : _a.promise) === updatePromise) {
|
|
111
|
+
serverUpdatePromiseRef.current = null;
|
|
112
|
+
}
|
|
97
113
|
}
|
|
98
114
|
}, [checkoutAnalytics, checkoutSessionId, checkoutState, normalizedServerUpdateKey, onError, onServerUpdate]);
|
|
99
115
|
useEffect(() => {
|
|
100
116
|
if (!normalizedServerUpdateKey) {
|
|
101
117
|
appliedServerUpdateKeyRef.current = '';
|
|
118
|
+
setAppliedServerUpdateKey('');
|
|
102
119
|
return;
|
|
103
120
|
}
|
|
104
121
|
if (checkoutState.type !== 'success' || !onServerUpdate) {
|
|
@@ -243,13 +260,14 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
243
260
|
}
|
|
244
261
|
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
245
262
|
};
|
|
246
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: [
|
|
263
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { "aria-busy": serverUpdatePending || undefined, "aria-disabled": serverUpdatePending || undefined, className: [
|
|
247
264
|
'stripe-express-checkout-button',
|
|
248
265
|
className !== null && className !== void 0 ? className : '',
|
|
249
266
|
effectiveWalletAvailable === false ? 'is-hidden' : '',
|
|
267
|
+
serverUpdatePending ? 'is-server-update-pending' : '',
|
|
250
268
|
]
|
|
251
269
|
.filter(Boolean)
|
|
252
|
-
.join(' '), children: _jsx(ExpressCheckoutElementWithCancel, { options: resolvedOptions, onCancel: handleCancel, onClick: handleClick, onConfirm: (event) => void handleConfirm(event), onLoadError: ({ error }) => {
|
|
270
|
+
.join(' '), inert: serverUpdatePending, children: _jsx(ExpressCheckoutElementWithCancel, { options: resolvedOptions, onCancel: handleCancel, onClick: handleClick, onConfirm: (event) => void handleConfirm(event), onLoadError: ({ error }) => {
|
|
253
271
|
setWalletAvailable(false);
|
|
254
272
|
onAvailabilityChange === null || onAvailabilityChange === void 0 ? void 0 : onAvailabilityChange(false);
|
|
255
273
|
reportFailure(error.message || 'Unable to load wallet checkout.', 'wallet_load');
|
|
@@ -272,4 +290,8 @@ const stripeExpressCheckoutButtonStyles = `
|
|
|
272
290
|
.stripe-express-checkout-button.is-hidden {
|
|
273
291
|
display: none;
|
|
274
292
|
}
|
|
293
|
+
|
|
294
|
+
.stripe-express-checkout-button.is-server-update-pending {
|
|
295
|
+
pointer-events: none;
|
|
296
|
+
}
|
|
275
297
|
`;
|