Simplify Payments with Laravel Razorpay Integration
Laravel Razorpay integration empowers your web application to handle online payments seamlessly and securely. With this integration, you can offer your customers a smooth and reliable payment experience, accepting a wide range of payment methods. It simplifies the checkout process and enhances user satisfaction. Discover how to implement Laravel Razorpay integration to elevate your online payment capabilities and drive business growth.
Effortlessly integrate Google Pay with Laravel
Laravel Razorpay integration
For Laravel Razorpay integration, you need to follow these steps:
- Create a New Laravel Project
If you haven’t already, create a new Laravel project using Composer:
composer create-project --prefer-dist laravel/laravel razorpay-example
cd razorpay-example
- Install Razorpay Package
You can install the Razorpay PHP package using Composer:
composer require razorpay/razorpay
- Set up Razorpay API Keys
You’ll need to sign up for a Razorpay account if you haven’t already. Once you have an account, get your API keys from the Razorpay dashboard. You’ll have a key ID and a key secret. Store these keys in your Laravel .env
file:
RAZORPAY_KEY_ID=your_key_id
RAZORPAY_KEY_SECRET=your_key_secret
- Create a Blade View
Create a Blade view for your payment form, which could be something like resources/views/payment.blade.php
. Here’s an example:
@extends('layouts.app')
@section('content')
<div class="container">
<form action="{{ route('razorpay.payment') }}" method="POST">
@csrf
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="{{ env('RAZORPAY_KEY_ID') }}"
data-amount="50000" {{-- Amount in paise (in this case, 50000 paise = 500 INR) --}}
data-currency="INR"
data-name="Your Company Name"
data-description="Payment for your services"
data-image="https://example.com/your_logo.png"
data-prefill.email="{{ Auth::user()->email }}"
data-prefill.contact=""
></script>
<input type="hidden" custom="Hidden Element" name="hidden">
</form>
</div>
@endsection
Make sure to replace placeholders like Your Company Name
and https://example.com/your_logo.png
with your own information.
- Create a Route
In your routes/web.php
file, create a route that will display the payment form:
Route::get('/payment', 'PaymentController@index')->name('payment');
- Create a Controller
Generate a controller for handling the payment:
php artisan make:controller PaymentController
In the PaymentController.php
file, create two methods – one for displaying the payment form and one for handling the payment response.
use Illuminate\Http\Request;
use Razorpay\Api\Api;
class PaymentController extends Controller
{
public function index()
{
return view('payment');
}
public function create(Request $request)
{
$input = $request->all();
$api = new Api(env('RAZORPAY_KEY_ID'), env('RAZORPAY_KEY_SECRET'));
$order = $api->order->create([
'amount' => $input['amount'], // Amount in paise
'currency' => 'INR',
'payment_capture' => 1, // Auto capture
]);
return view('payment', compact('order'));
}
}
- Create a Route for Payment Response
In your routes/web.php
file, add a route for handling the payment response:
Route::post('/payment/response', 'PaymentController@create')->name('razorpay.payment');
- Update Blade View with Payment Response Handling
Modify your Blade view (payment.blade.php
) to include the Razorpay response handling code:
@extends('layouts.app')
@section('content')
<div class="container">
@if(isset($order))
<form action="{{ route('razorpay.payment') }}" method="POST">
@csrf
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="{{ env('RAZORPAY_KEY_ID') }}"
data-amount="{{ $order->amount }}"
data-currency="INR"
data-name="Your Company Name"
data-description="Payment for your services"
data-image="https://example.com/your_logo.png"
data-prefill.email="{{ Auth::user()->email }}"
data-prefill.contact=""
></script>
<input type="hidden" custom="Hidden Element" name="hidden">
</form>
@endif
</div>
@endsection
- Run Your Laravel Application
Now, you can run your Laravel application using:
php artisan serve
Visit your Laravel application in your web browser and navigate to the /payment
route. You should see the payment form.
Remember that this example is a basic Laravel Razorpay integration. You may need to adapt and enhance it for your specific use case.
These steps will help you in Laravel Razorpay integration
FAQ (Frequently Asked Questions)
Q1: What is Razorpay?
A1: Razorpay is a popular online payment gateway that allows businesses to accept payments on their websites or mobile applications. It provides a secure and straightforward way for customers to pay for products and services.
Q2: Why should I integrate Razorpay with Laravel?
A2: Integrating Razorpay with Laravel offers a reliable and seamless payment processing solution for your web applications. It enhances the user experience, simplifies the checkout process, and allows you to accept payments from various sources.
Q3: Is Razorpay integration in Laravel secure?
A3: Yes, Razorpay is known for its robust security measures. When integrated with Laravel following best practices, it ensures that payment transactions are safe and encrypted, protecting sensitive customer data.
Q4: Can I customize the payment process with Razorpay and Laravel?
A4: Yes, you can customize the payment process to match your specific requirements. Razorpay provides flexible options for tailoring the payment experience, such as creating custom payment forms and handling different payment methods.
Q5: Are there any additional fees for using Razorpay with Laravel?
A5: Razorpay may charge transaction fees based on the payment methods and the plan you choose. Make sure to review their pricing details on the Razorpay website to understand any associated costs.
Conclusion
Incorporating Razorpay into your Laravel application offers a powerful solution for handling online payments. With the ability to customize and secure the payment process, you can provide a convenient and trusted experience for your customers. Razorpay’s flexibility and reliability make it a valuable addition to your web application, enhancing user satisfaction and ultimately contributing to your business’s success. Whether you’re running an e-commerce platform or offering subscription services, the Laravel Razorpay integration is a step towards optimizing your payment capabilities and simplifying the way you receive payments.
Recent Comments