name('home'); Route::get('dashboard', function () { return Inertia::render('Dashboard'); })->middleware(['auth', 'verified'])->name('dashboard'); // Route::get('/cards', [App\Http\Controllers\CardController::class, 'index'])->name('cards.index'); Route::get('/tirage',[App\Http\Controllers\CardController::class, 'index'])->name('cards.shuffle'); Route::post('/draw-card', [App\Http\Controllers\CardController::class, 'drawCard']); Route::post('/create-checkout-session', [App\Http\Controllers\StripeController::class, 'createCheckoutSession']); Route::post('/checkout-rendez-vous', [App\Http\Controllers\StripeController::class, 'createRendezVousSession']); Route::post('/stripe/webhook', [App\Http\Controllers\WebhookController::class, 'handleWebhook']); // Wise payment routes Route::post('/create-wise-payment', [App\Http\Controllers\WiseController::class, 'createPaymentSession']); Route::post('/wise/webhook', [App\Http\Controllers\WiseController::class, 'handleWebhook']); Route::get('/wise/validate-payment', [App\Http\Controllers\WiseController::class, 'validatePayment']); Route::get('/wise/verify', function () { return Inertia::render('wise/VerifyPayment'); })->name('wise.verify'); Route::get('/rendez-vous', [App\Http\Controllers\AppointmentController::class, 'index']); Route::get('/resultat', [App\Http\Controllers\CardController::class, 'cartResult']); Route::get('/resultat-gratuit', function(Request $request) { return Inertia::render('cards/FreeCardResult'); })->name('cards.freeResult'); Route::get('paiement', function () { return Inertia::render('Checkout'); })->name('paiement'); Route::get('/success', function (Request $request) { $clientSessionId = $request->query('client_session_id'); if (!$clientSessionId) { return Inertia::render('payments/Error', ['message' => 'Invalid payment session.']); } $payment = Payment::where('client_session_id', $clientSessionId)->first(); if (!$payment) { Log::warning('Payment record not found on success page', ['client_session_id' => $clientSessionId]); return Inertia::render('payments/Error', ['message' => 'Payment record not found.']); } // If payment is already succeeded in our database if ($payment->status === 'succeeded') { return Inertia::render('payments/Success', [ 'paymentSuccess' => true, 'drawCount' => $payment->draw_count, 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); } // If payment is pending, check with Stripe to handle race condition if ($payment->status === 'pending') { try { \Stripe\Stripe::setApiKey(env('STRIPE_SECRET_KEY')); $session = \Stripe\Checkout\Session::retrieve($clientSessionId); if ($session->payment_status === 'paid' && $session->status === 'complete') { // Payment confirmed, update our record $payment->update(['status' => 'succeeded']); Log::info('Payment status updated on success page via direct Stripe check', [ 'client_session_id' => $clientSessionId, 'payment_id' => $payment->id ]); return Inertia::render('payments/Success', [ 'paymentSuccess' => true, 'drawCount' => $payment->draw_count, 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); } // Payment still pending, show pending page return Inertia::render('payments/Pending', [ 'message' => 'Payment is still being processed. Please wait...', 'clientSessionId' => $clientSessionId, 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); } catch (\Exception $e) { Log::error('Stripe session check failed on success page: ' . $e->getMessage(), [ 'client_session_id' => $clientSessionId, 'payment_id' => $payment->id ]); // Show pending page on Stripe check failure return Inertia::render('payments/Pending', [ 'message' => 'Verifying payment status. Please wait...', 'clientSessionId' => $clientSessionId, 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); } } // Payment failed or cancelled if ($payment->status === 'failed') { return Inertia::render('payments/Error', [ 'message' => 'Payment failed. Please try again.', 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); } // Any other status return Inertia::render('payments/Error', [ 'message' => 'Payment status: ' . $payment->status, 'paymentProvider' => $payment->payment_provider ?? 'stripe' ]); })->name('payment.success'); Route::get('/rendez-vous/success', function (Request $request){ $clientSessionId = $request->query('client_session_id'); $payment = Payment::where('client_session_id', $clientSessionId) ->where('status', 'succeeded') // Only check for succeeded payments ->first(); if ($payment) { return Inertia::render('AppointSuccess', [ 'appointment_date' => $payment->appointment_date, ]); } })->name('appoint.success'); Route::get('/cancel', function () { return Inertia::render('payments/Error'); // Your error page })->name('payments.cancel'); Route::get('/term-condition', function () { return Inertia::render('TermCondition'); // Your terms and conditions page })->name('term-condition'); Route::get('/politique-confidalite', function () { return Inertia::render('PolitiqueConf'); // Your terms and conditions page })->name('politique-conf'); // CSV import endpoint for cards Route::post('/cards/import', [CardImportController::class, 'store'])->middleware(['auth']); require __DIR__.'/settings.php'; require __DIR__.'/auth.php';