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
]);
}`
list of routes
GET|HEAD / ........................................................................................................................................ event.index
GET|HEAD confirm-password .......................................................................... password.confirm › Auth\ConfirmablePasswordController@show
POST confirm-password ............................................................................................ Auth\ConfirmablePasswordController@store
GET|HEAD dashboard .................................................................................................................................. dashboard
POST email/verification-notification ............................................... verification.send › Auth\EmailVerificationNotificationController@store
GET|HEAD events/{event} ........................................................................................................................... events.show
GET|HEAD forgot-password ........................................................................... password.request › Auth\PasswordResetLinkController@create
POST forgot-password .............................................................................. password.email › Auth\PasswordResetLinkController@store
GET|HEAD login ............................................................................................. login › Auth\AuthenticatedSessionController@create
POST login ...................................................................................................... Auth\AuthenticatedSessionController@store
POST logout .......................................................................................... logout › Auth\AuthenticatedSessionController@destroy
PUT password ............................................................................................ password.update › Auth\PasswordController@update
POST payment-verify ............................................................................................. payment.verify › PaymentController@verify
GET|HEAD profile ........................................................................................................ profile.edit › ProfileController@edit
PATCH profile .................................................................................................... profile.update › ProfileController@update
DELETE profile .................................................................................................. profile.destroy › ProfileController@destroy
POST razorpay ......................................................................................... payment.razorpay › PaymentController@processPayment
GET|HEAD register ............................................................................................. register › Auth\RegisteredUserController@create
POST register ......................................................................................................... Auth\RegisteredUserController@store
POST reset-password ..................................................................................... password.store › Auth\NewPasswordController@store
GET|HEAD reset-password/{token} ............................................................................ password.reset › Auth\NewPasswordController@create
GET|HEAD sanctum/csrf-cookie ................................................................ sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
POST seats/check-availability .................................................................. seats.checkAvailability › SeatController@checkAvailability
GET|HEAD tickets ................................................................................................................................ tickets.index
GET|HEAD up ...................................................................................................................................................
GET|HEAD verify-email ............................................................................ verification.notice › Auth\EmailVerificationPromptController
GET|HEAD verify-email/{id}/{hash} ............................................................................ verification.verify › Auth\VerifyEmailController
Showing [27] routes
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 ?