From 0b67181797c8b5635cca710607106c0c57cd5a4d Mon Sep 17 00:00:00 2001 From: Ratchet7x5 <36789694+Ratchet7x5@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:01:17 +1300 Subject: [PATCH] experimental fix for return page showing failed payment (despite payment being successful) --- web/src/api/apiRequests.ts | 14 ++++++++++++++ web/src/screens/ReturnScreen.tsx | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/web/src/api/apiRequests.ts b/web/src/api/apiRequests.ts index 6f666a1..f952b10 100644 --- a/web/src/api/apiRequests.ts +++ b/web/src/api/apiRequests.ts @@ -82,6 +82,20 @@ export const postAttendanceUpdate = async ( return response.data; }; +// Get session status +export const getSessionStatus = async ( + sessionId: string +): Promise => { + const response = await apiClient.get( + `/api/stripe/session-status?session_id=${sessionId}`, + { + headers: { "Content-Type": "application/json" }, + } + ); + + return response; +}; + //Use this one to automatically create an Event or Membership checkout. Event checkout will decrement a ticket. export const fetchEventOrMembershipCheckoutSecret = async (payload: { priceId: string; diff --git a/web/src/screens/ReturnScreen.tsx b/web/src/screens/ReturnScreen.tsx index 6ed745c..3af0069 100644 --- a/web/src/screens/ReturnScreen.tsx +++ b/web/src/screens/ReturnScreen.tsx @@ -1,23 +1,26 @@ import { useState, useEffect } from "react"; import { Navigate, useNavigate } from "react-router"; import { EmailLink } from "../data/data"; +import { getSessionStatus } from "../api/apiRequests"; -export default function ReturnScreen() { +export default async function ReturnScreen() { const navigate = useNavigate(); const [status, setStatus] = useState(null); const [customerEmail, setCustomerEmail] = useState(""); useEffect(() => { - const queryString = window.location.search; - const urlParams = new URLSearchParams(queryString); - const sessionId = urlParams.get("session_id"); - fetch(`/api/stripe/session-status?session_id=${sessionId}`) - .then((res) => res.json()) - .then((data) => { - setStatus(data.status); - setCustomerEmail(data.customer_email); - }) - .catch(); + async function getSessionData() { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const sessionId = urlParams.get("session_id"); + const response = await getSessionStatus(sessionId!); + return response; + } + + getSessionData().then((response) => { + setStatus(response.data.status); + setCustomerEmail(response.data.customer_email); + }); }, []); if (status === "open") {