Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Fix "cannot access before initialization" error

Dave Earley8e76413e4858
diff --git a/frontend/src/components/forms/StripeCheckoutForm/index.tsx b/frontend/src/components/forms/StripeCheckoutForm/index.tsx
index 7184d91f2..30dc53471 100644
--- a/frontend/src/components/forms/StripeCheckoutForm/index.tsx
+++ b/frontend/src/components/forms/StripeCheckoutForm/index.tsx
@@ -22,6 +22,25 @@ export default function StripeCheckoutForm({setSubmitHandler}: {
const {data: order, isFetched: isOrderFetched} = useGetOrderPublic(eventId, orderShortId, ['event']);
const event = order?.event;
+ const handleSubmit = async () => {
+ if (!stripe || !elements) {
+ return;
+ }
+
+ const {error} = await stripe.confirmPayment({
+ elements,
+ confirmParams: {
+ return_url: window?.location.origin + `/checkout/${eventId}/${orderShortId}/payment_return`
+ },
+ });
+
+ if (error?.type === "card_error" || error?.type === "validation_error") {
+ setMessage(error.message);
+ } else {
+ setMessage(t`An unexpected error occurred.`);
+ }
+ };
+
useEffect(() => {
if (!stripe) {
return;
@@ -88,25 +107,6 @@ export default function StripeCheckoutForm({setSubmitHandler}: {
);
}
- const handleSubmit = async () => {
- if (!stripe || !elements) {
- return;
- }
-
- const {error} = await stripe.confirmPayment({
- elements,
- confirmParams: {
- return_url: window?.location.origin + `/checkout/${eventId}/${orderShortId}/payment_return`
- },
- });
-
- if (error?.type === "card_error" || error?.type === "validation_error") {
- setMessage(error.message);
- } else {
- setMessage(t`An unexpected error occurred.`);
- }
- };
-
const paymentElementOptions: stripeJs.StripePaymentElementOptions = {
layout: {
type: "accordion",