Merge pull request 'Again rechange in payment success' (#16) from main into testing
All checks were successful
CityCards-Website / Build-CityCards-Website (push) Successful in 23s

Reviewed-on: #16
This commit is contained in:
2026-04-23 13:35:28 +00:00
2 changed files with 19 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ export const cardsApi = createApi({
}),
payForCard: builder.mutation({
query: (id) => ({
query: (id) => ({
url: `/website/passes/${id}/pay`,
method: "POST",
body: {},
@@ -51,10 +51,10 @@ export const cardsApi = createApi({
}),
confirmCardPayment: builder.mutation({
query: ({ bookingId, paymentIntentId }: { bookingId: string; paymentIntentId: string }) => ({
url: `/website/passes/${bookingId}/confirm-payment`,
query: (id) => ({
url: `/website/passes/${id}/confirm-payment`,
method: "POST",
body: { paymentIntentId }, // ✅ send paymentIntentId to backend
// body: id,
}),
}),

View File

@@ -15,6 +15,7 @@ interface PaymentSuccessPageProps {
user?: { email: string; name: string } | null;
}
// Helper to get cookie value
const getCookie = (name: string): string | null => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
@@ -38,36 +39,34 @@ export function PaymentSuccessPage({
useEffect(() => {
const confirm = async () => {
// 1⃣ Get bookingId from storage / cookie
// Try all possible sources
let bookingId = getCookie('pendingBookingId');
if (!bookingId) bookingId = localStorage.getItem('pendingBookingId');
if (!bookingId) bookingId = sessionStorage.getItem('pendingBookingId');
if (!bookingId) bookingId = searchParams.get('bookingId');
// 2⃣ Get payment_intent from URL (Stripe redirect)
const paymentIntentId = searchParams.get('payment_intent');
console.log('🔍 Retrieved data:', { bookingId, paymentIntentId });
console.log('Retrieved bookingId from sources:', {
cookie: getCookie('pendingBookingId'),
localStorage: localStorage.getItem('pendingBookingId'),
sessionStorage: sessionStorage.getItem('pendingBookingId'),
queryParam: searchParams.get('bookingId'),
final: bookingId,
});
if (!bookingId) {
setStatus('error');
setErrorMsg('Booking ID not found. Please contact support.');
return;
}
if (!paymentIntentId) {
setStatus('error');
setErrorMsg('Payment intent missing. Please contact support.');
setErrorMsg(
'Booking ID not found. Please contact support with your order details. ' +
'If you just completed payment, your order may still be processing.'
);
return;
}
try {
// 3⃣ Call confirm endpoint with paymentIntentId
await confirmPayment({ bookingId, paymentIntentId }).unwrap();
await confirmPayment(bookingId).unwrap();
setStatus('success');
toast.success('Payment confirmed! Your order is complete.');
// 4⃣ Clean up stored bookingId
// Clean up all storage
document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
localStorage.removeItem('pendingBookingId');
sessionStorage.removeItem('pendingBookingId');