@funnelsgrove/payments 0.11.12 → 0.11.14

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,14 @@ 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);
37
+ const [serverUpdateInFlight, setServerUpdateInFlight] = useState(false);
36
38
  const [walletAvailable, setWalletAvailable] = useState(initialAvailable !== null && initialAvailable !== void 0 ? initialAvailable : null);
37
39
  const normalizedServerUpdateKey = (serverUpdateKey === null || serverUpdateKey === void 0 ? void 0 : serverUpdateKey.trim()) || '';
40
+ const serverUpdatePending = serverUpdateInFlight ||
41
+ Boolean(serverUpdatePromiseRef.current) ||
42
+ Boolean(normalizedServerUpdateKey && appliedServerUpdateKey !== normalizedServerUpdateKey);
38
43
  const effectiveWalletAvailable = initialAvailable === true && walletAvailable !== false
39
44
  ? true
40
45
  : walletAvailable;
@@ -45,6 +50,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
45
50
  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
51
  }, [baseOptions, options]);
47
52
  const ensureServerUpdated = useCallback(async (paymentMethod) => {
53
+ var _a;
48
54
  if (!normalizedServerUpdateKey) {
49
55
  return true;
50
56
  }
@@ -55,8 +61,16 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
55
61
  return false;
56
62
  }
57
63
  if (serverUpdatePromiseRef.current) {
58
- return serverUpdatePromiseRef.current;
64
+ const pendingUpdate = serverUpdatePromiseRef.current;
65
+ const pendingResult = await pendingUpdate.promise;
66
+ if (pendingUpdate.key === normalizedServerUpdateKey) {
67
+ return pendingResult;
68
+ }
69
+ if (appliedServerUpdateKeyRef.current === normalizedServerUpdateKey) {
70
+ return true;
71
+ }
59
72
  }
73
+ setServerUpdateInFlight(true);
60
74
  const updatePromise = (async () => {
61
75
  let updateCallbackFailed = false;
62
76
  const updateResult = await checkoutState.checkout.runServerUpdate(async () => {
@@ -85,20 +99,28 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
85
99
  return false;
86
100
  }
87
101
  appliedServerUpdateKeyRef.current = normalizedServerUpdateKey;
102
+ setAppliedServerUpdateKey(normalizedServerUpdateKey);
88
103
  onError === null || onError === void 0 ? void 0 : onError(null);
89
104
  return true;
90
105
  })();
91
- serverUpdatePromiseRef.current = updatePromise;
106
+ serverUpdatePromiseRef.current = {
107
+ key: normalizedServerUpdateKey,
108
+ promise: updatePromise,
109
+ };
92
110
  try {
93
111
  return await updatePromise;
94
112
  }
95
113
  finally {
96
- serverUpdatePromiseRef.current = null;
114
+ if (((_a = serverUpdatePromiseRef.current) === null || _a === void 0 ? void 0 : _a.promise) === updatePromise) {
115
+ serverUpdatePromiseRef.current = null;
116
+ setServerUpdateInFlight(false);
117
+ }
97
118
  }
98
119
  }, [checkoutAnalytics, checkoutSessionId, checkoutState, normalizedServerUpdateKey, onError, onServerUpdate]);
99
120
  useEffect(() => {
100
121
  if (!normalizedServerUpdateKey) {
101
122
  appliedServerUpdateKeyRef.current = '';
123
+ setAppliedServerUpdateKey('');
102
124
  return;
103
125
  }
104
126
  if (checkoutState.type !== 'success' || !onServerUpdate) {
@@ -243,13 +265,14 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
243
265
  }
244
266
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
245
267
  };
246
- return (_jsxs(_Fragment, { children: [_jsx("div", { className: [
268
+ return (_jsxs(_Fragment, { children: [_jsx("div", { "aria-busy": serverUpdatePending || undefined, "aria-disabled": serverUpdatePending || undefined, className: [
247
269
  'stripe-express-checkout-button',
248
270
  className !== null && className !== void 0 ? className : '',
249
271
  effectiveWalletAvailable === false ? 'is-hidden' : '',
272
+ serverUpdatePending ? 'is-server-update-pending' : '',
250
273
  ]
251
274
  .filter(Boolean)
252
- .join(' '), children: _jsx(ExpressCheckoutElementWithCancel, { options: resolvedOptions, onCancel: handleCancel, onClick: handleClick, onConfirm: (event) => void handleConfirm(event), onLoadError: ({ error }) => {
275
+ .join(' '), inert: serverUpdatePending, children: _jsx(ExpressCheckoutElementWithCancel, { options: resolvedOptions, onCancel: handleCancel, onClick: handleClick, onConfirm: (event) => void handleConfirm(event), onLoadError: ({ error }) => {
253
276
  setWalletAvailable(false);
254
277
  onAvailabilityChange === null || onAvailabilityChange === void 0 ? void 0 : onAvailabilityChange(false);
255
278
  reportFailure(error.message || 'Unable to load wallet checkout.', 'wallet_load');
@@ -272,4 +295,8 @@ const stripeExpressCheckoutButtonStyles = `
272
295
  .stripe-express-checkout-button.is-hidden {
273
296
  display: none;
274
297
  }
298
+
299
+ .stripe-express-checkout-button.is-server-update-pending {
300
+ pointer-events: none;
301
+ }
275
302
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.11.12",
3
+ "version": "0.11.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",