@funnelsgrove/payments 0.14.0 → 0.15.0
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.
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import { useCallback, useEffect, useMemo, useState, } from 'react';
|
|
14
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
15
15
|
import { CheckoutProvider, PaymentElement, useCheckout, } from '@stripe/react-stripe-js/checkout';
|
|
16
16
|
import { PaymentBrandMark, SecurityLockIcon } from './CheckoutBrandAssets.js';
|
|
17
17
|
import { StripeCheckoutExpressCheckoutButton } from './StripeCheckoutExpressCheckoutButton.js';
|
|
@@ -70,6 +70,7 @@ function SharedStripeCheckoutV2CheckoutSessionForm({ amountCents, buttonColor, c
|
|
|
70
70
|
? true
|
|
71
71
|
: walletAvailable;
|
|
72
72
|
const [submitting, setSubmitting] = useState(false);
|
|
73
|
+
const submitInFlightRef = useRef(false);
|
|
73
74
|
const [paymentElementReady, setPaymentElementReady] = useState(false);
|
|
74
75
|
const [error, setError] = useState(null);
|
|
75
76
|
const [billingCountry, setBillingCountry] = useState(null);
|
|
@@ -250,7 +251,7 @@ function SharedStripeCheckoutV2CheckoutSessionForm({ amountCents, buttonColor, c
|
|
|
250
251
|
};
|
|
251
252
|
const handleSubmit = async (event) => {
|
|
252
253
|
event.preventDefault();
|
|
253
|
-
if (
|
|
254
|
+
if (submitInFlightRef.current) {
|
|
254
255
|
return;
|
|
255
256
|
}
|
|
256
257
|
const billingCountryError = getBillingCountryError(billingCountry !== null && billingCountry !== void 0 ? billingCountry : fixedBillingCountry);
|
|
@@ -268,12 +269,17 @@ function SharedStripeCheckoutV2CheckoutSessionForm({ amountCents, buttonColor, c
|
|
|
268
269
|
setSharedError('Payment form is not ready yet.', true);
|
|
269
270
|
return;
|
|
270
271
|
}
|
|
272
|
+
submitInFlightRef.current = true;
|
|
271
273
|
setSubmitting(true);
|
|
272
274
|
setSharedError(null);
|
|
275
|
+
const finishSubmitting = () => {
|
|
276
|
+
submitInFlightRef.current = false;
|
|
277
|
+
setSubmitting(false);
|
|
278
|
+
};
|
|
273
279
|
try {
|
|
274
280
|
const syncedEmail = await ensureCustomerEmail();
|
|
275
281
|
if (!syncedEmail) {
|
|
276
|
-
|
|
282
|
+
finishSubmitting();
|
|
277
283
|
return;
|
|
278
284
|
}
|
|
279
285
|
await trackPaymentInfoSubmitted();
|
|
@@ -283,7 +289,7 @@ function SharedStripeCheckoutV2CheckoutSessionForm({ amountCents, buttonColor, c
|
|
|
283
289
|
if (result.type === 'error') {
|
|
284
290
|
const message = result.error.message || 'Payment failed.';
|
|
285
291
|
setSharedError(message, false, result.error);
|
|
286
|
-
|
|
292
|
+
finishSubmitting();
|
|
287
293
|
return;
|
|
288
294
|
}
|
|
289
295
|
if (typeof window !== 'undefined') {
|
|
@@ -291,11 +297,11 @@ function SharedStripeCheckoutV2CheckoutSessionForm({ amountCents, buttonColor, c
|
|
|
291
297
|
window.location.assign(returnUrl);
|
|
292
298
|
return;
|
|
293
299
|
}
|
|
294
|
-
|
|
300
|
+
finishSubmitting();
|
|
295
301
|
}
|
|
296
302
|
catch (submitError) {
|
|
297
303
|
setSharedError(getFriendlyCardErrorMessage(submitError));
|
|
298
|
-
|
|
304
|
+
finishSubmitting();
|
|
299
305
|
}
|
|
300
306
|
};
|
|
301
307
|
const visibleError = error;
|