PHP code example of adicode-technologies / laravel-razorpay-easy
1. Go to this page and download the library: Download adicode-technologies/laravel-razorpay-easy library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adicode-technologies / laravel-razorpay-easy example snippets
bash
php artisan vendor:publish --provider="AdicodeTechnologies\LaravelRazorpayEasy\RazorpayServiceProvider"
bash
php artisan migrate
php
// routes/web.php
Route::post('orders/{order}/payment/callback', [OrderController::class, 'handlePaymentCallback'])
->name('orders.payment.callback');
// OrderController.php
public function handlePaymentCallback(Request $request, Order $order)
{
try {
// Process the payment
$payment = app('razorpay')->processPayment($request->all());
// Associate with order
$payment->payable_id = $order->id;
$payment->payable_type = get_class($order);
$payment->save();
// Update order status
$order->update(['status' => 'paid']);
return redirect()->route('orders.show', $order)
->with('success', 'Payment completed successfully!');
} catch (\Exception $e) {
return redirect()->route('orders.show', $order)
->with('error', 'Payment failed: ' . $e->getMessage());
}
}