From cd7c6ffbaf64d08dd4825f139c4fbfd626a28d87 Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Thu, 23 Apr 2026 18:33:33 +0530 Subject: [PATCH 1/5] change payment success file and cards endpoints --- src/Redux/services/cards.service.ts | 8 ++++---- src/pages/PaymentSuccessPage.tsx | 31 +++++++++++++++-------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index efac3eb..a35d083 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -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: (id) => ({ - url: `/website/passes/${id}/confirm-payment`, + query: ({ bookingId, paymentIntentId }: { bookingId: string; paymentIntentId: string }) => ({ + url: `/website/passes/${bookingId}/confirm-payment`, method: "POST", - // body: id, + body: { paymentIntentId }, // ✅ send paymentIntentId to backend }), }), diff --git a/src/pages/PaymentSuccessPage.tsx b/src/pages/PaymentSuccessPage.tsx index 0f6fb1e..bfd2ab0 100644 --- a/src/pages/PaymentSuccessPage.tsx +++ b/src/pages/PaymentSuccessPage.tsx @@ -15,7 +15,6 @@ 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}=`); @@ -39,34 +38,36 @@ export function PaymentSuccessPage({ useEffect(() => { const confirm = async () => { - // Try all possible sources + // 1️⃣ Get bookingId from storage / cookie let bookingId = getCookie('pendingBookingId'); if (!bookingId) bookingId = localStorage.getItem('pendingBookingId'); if (!bookingId) bookingId = sessionStorage.getItem('pendingBookingId'); if (!bookingId) bookingId = searchParams.get('bookingId'); - console.log('Retrieved bookingId from sources:', { - cookie: getCookie('pendingBookingId'), - localStorage: localStorage.getItem('pendingBookingId'), - sessionStorage: sessionStorage.getItem('pendingBookingId'), - queryParam: searchParams.get('bookingId'), - final: bookingId, - }); + // 2️⃣ Get payment_intent from URL (Stripe redirect) + const paymentIntentId = searchParams.get('payment_intent'); + + console.log('🔍 Retrieved data:', { bookingId, paymentIntentId }); if (!bookingId) { setStatus('error'); - setErrorMsg( - 'Booking ID not found. Please contact support with your order details. ' + - 'If you just completed payment, your order may still be processing.' - ); + setErrorMsg('Booking ID not found. Please contact support.'); + return; + } + + if (!paymentIntentId) { + setStatus('error'); + setErrorMsg('Payment intent missing. Please contact support.'); return; } try { - await confirmPayment(bookingId).unwrap(); + // 3️⃣ Call confirm endpoint with paymentIntentId + await confirmPayment({ bookingId, paymentIntentId }).unwrap(); setStatus('success'); toast.success('Payment confirmed! Your order is complete.'); - // Clean up all storage + + // 4️⃣ Clean up stored bookingId document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; localStorage.removeItem('pendingBookingId'); sessionStorage.removeItem('pendingBookingId'); From d3bedeb56d7b1b57cd8160ef4df0c5ccc3a68dbf Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Thu, 23 Apr 2026 19:02:42 +0530 Subject: [PATCH 2/5] Again rechange in payment success --- src/Redux/services/cards.service.ts | 8 ++++---- src/pages/PaymentSuccessPage.tsx | 31 ++++++++++++++--------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index a35d083..efac3eb 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -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, }), }), diff --git a/src/pages/PaymentSuccessPage.tsx b/src/pages/PaymentSuccessPage.tsx index bfd2ab0..0f6fb1e 100644 --- a/src/pages/PaymentSuccessPage.tsx +++ b/src/pages/PaymentSuccessPage.tsx @@ -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'); From a1a5c839dd1ba662d223507912e3745a88479fac Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Thu, 23 Apr 2026 19:28:13 +0530 Subject: [PATCH 3/5] change payment success page and endpoint --- src/Redux/services/cards.service.ts | 8 ++++---- src/pages/PaymentSuccessPage.tsx | 24 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index efac3eb..befbc14 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -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: (id) => ({ - url: `/website/passes/${id}/confirm-payment`, + query: (payload: { id: string; checkoutSessionId: string }) => ({ + url: `/website/passes/${payload.id}/confirm-payment`, method: "POST", - // body: id, + body: { checkoutSessionId: payload.checkoutSessionId }, }), }), diff --git a/src/pages/PaymentSuccessPage.tsx b/src/pages/PaymentSuccessPage.tsx index 0f6fb1e..5872761 100644 --- a/src/pages/PaymentSuccessPage.tsx +++ b/src/pages/PaymentSuccessPage.tsx @@ -39,18 +39,22 @@ export function PaymentSuccessPage({ useEffect(() => { const confirm = async () => { - // Try all possible sources + // 1. Retrieve bookingId from storage (cookie, localStorage, sessionStorage, or query param) let bookingId = getCookie('pendingBookingId'); if (!bookingId) bookingId = localStorage.getItem('pendingBookingId'); if (!bookingId) bookingId = sessionStorage.getItem('pendingBookingId'); if (!bookingId) bookingId = searchParams.get('bookingId'); - console.log('Retrieved bookingId from sources:', { + // 2. Get checkoutSessionId from URL query parameter + const checkoutSessionId = searchParams.get('session_id'); + + console.log('Retrieved data:', { + bookingId: bookingId, + checkoutSessionId: checkoutSessionId, cookie: getCookie('pendingBookingId'), localStorage: localStorage.getItem('pendingBookingId'), sessionStorage: sessionStorage.getItem('pendingBookingId'), - queryParam: searchParams.get('bookingId'), - final: bookingId, + queryBookingId: searchParams.get('bookingId'), }); if (!bookingId) { @@ -62,10 +66,20 @@ export function PaymentSuccessPage({ return; } + if (!checkoutSessionId) { + setStatus('error'); + setErrorMsg( + 'Missing session ID. Please contact support with your order details.' + ); + return; + } + try { - await confirmPayment(bookingId).unwrap(); + // Call API with both id and checkoutSessionId + await confirmPayment({ id: bookingId, checkoutSessionId }).unwrap(); setStatus('success'); toast.success('Payment confirmed! Your order is complete.'); + // Clean up all storage document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; localStorage.removeItem('pendingBookingId'); From 8279715f2c21bc8d3848fe423a0a4ddd63270d9b Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Thu, 23 Apr 2026 19:50:43 +0530 Subject: [PATCH 4/5] change card service file --- src/Redux/services/cards.service.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index befbc14..545d348 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -52,9 +52,8 @@ export const cardsApi = createApi({ confirmCardPayment: builder.mutation({ query: (payload: { id: string; checkoutSessionId: string }) => ({ - url: `/website/passes/${payload.id}/confirm-payment`, + url: `/website/passes/${payload.id}/confirm-payment/${payload.checkoutSessionId}`, method: "POST", - body: { checkoutSessionId: payload.checkoutSessionId }, }), }), From 6a234291317fce323861f68184c6a4746db9a037 Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Thu, 23 Apr 2026 19:55:21 +0530 Subject: [PATCH 5/5] change card service again --- src/Redux/services/cards.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index 545d348..9e1ffdd 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -52,7 +52,7 @@ export const cardsApi = createApi({ confirmCardPayment: builder.mutation({ query: (payload: { id: string; checkoutSessionId: string }) => ({ - url: `/website/passes/${payload.id}/confirm-payment/${payload.checkoutSessionId}`, + url: `/website/passes/${payload.id}/${payload.checkoutSessionId}/confirm-payment/`, method: "POST", }), }),