when i send a get request here every thing works perfectly fine but post request gives me errors
react method for sending to payment.razorpay
route
`const handlePayment = ()=>{
localStorage.setItem(‘selectedSeats’, selectedSeats);
axios.post(route('seats.checkAvailability'), { selectedSeats })
.then(response => {
console.log('Success:', response.data);
try{
axios.post(route('payment.razorpay'), {
selectedSeats,
totalAmount: total,
user: auth.user
},
{headers:{"Content-Type" : "application/json"}}
);
} catch (error) {
console.error(error.response.data);
}
})
.catch(error => {
console.log('in catch');
setErr(error.response.data.error);
});
};`
here is the route
Route::post('/razorpay', [PaymentController::class, 'processPayment'])->middleware(['auth'])->name('payment.razorpay');
function in PaymentController
` public function processPayment( Request $request)
{
dd('here');
$request->validate([
'selectedSeats' => 'required|array',
'total' => 'required|numeric|min:0',
'$user' => 'required'
]);
$selectedSeats = $request->input('selectedSeats');
$totalAmount = $request->input('total');
$user = $request->user();
$api_key = config('services.razorpay.razorpay_key');
$api_secret = config('services.razorpay.razorpay_secret');
$api = new Api($api_key, $api_secret);
try {
$order = $api->order->create([
'amount' => $totalAmount * 100,
'currency' => 'INR',
'receipt' => 'order_receipt_id_123',
'payment_capture' => 1 // Auto capture payment
]);
} catch (Exception $e) {
return response()->json(['status' => 'error', 'message' => 'Failed to create Razorpay order'], 500);
}
$data = [
"key" => $api_key,
"amount" => $order['amount'], // In paise
"currency" => $order['currency'],
"name" => $user->name,
"description" => "Ticket Purchase",
"image" => "https://cdn.razorpay.com/logos/GhRQcyean79PqE_medium.png",
"prefill" => [
"name" => $user->name,
"email" => $user->email
],
"theme" => [
"color" => "#3399cc"
],
"order_id" => $order['id'], // Pass the order ID from Razorpay
];
return Inertia::render('Checkout', [
'data' => $data, // No need to json_encode here, Inertia will handle it
'selectedSeats' => $selectedSeats, // Pass selected seats to the view
'totalAmount' => $totalAmount, // Pass the total amount
]);
}`
i tried adding a dd() at the start of the function but the request wont even reach there
i also tried using Inertia.post
should i keep this as a get route cause it works perfectly fine, if yes where should i pass the data ?