change payment success file and cards endpoints

This commit is contained in:
Hemant Vishwakarma
2026-04-23 18:33:33 +05:30
parent b3bb9f08cd
commit cd7c6ffbaf
2 changed files with 20 additions and 19 deletions

View File

@@ -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
}),
}),

View File

@@ -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');