Skip to content

Commit

Permalink
experimental fix for return page showing failed payment (despite paym…
Browse files Browse the repository at this point in the history
…ent being successful)
  • Loading branch information
Ratchet7x5 committed Dec 13, 2024
1 parent 219802b commit 0b67181
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
14 changes: 14 additions & 0 deletions web/src/api/apiRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ export const postAttendanceUpdate = async (
return response.data;
};

// Get session status
export const getSessionStatus = async (
sessionId: string
): Promise<AxiosResponse> => {
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;
Expand Down
25 changes: 14 additions & 11 deletions web/src/screens/ReturnScreen.tsx
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down

0 comments on commit 0b67181

Please sign in to comment.