SlideShare a Scribd company logo
1 of 36
Download to read offline
Razorpay
Payment
Gateway
Integration
in Laravel
and VueJS 2
www.bacancytechnology.com
In this latest technology world, the
combination of Laravel and VueJS is
unbeatable and very powerful to make any
high-end application that runs smooth.
There is an increasing need for e-
commerce/content-driven websites. You
now need a payment gateway to make easy
transactions. So here is the way to integrate
Razorpay payment gateway to your Laravel
6/7/8 versions along with VueJS.


Without further ado, let’s get started with
the Razorpay Payment Gateway Integration
in Laravel and VueJS 2.
Initial Set-Up:
Laravel and
NPM
Dependencies
Installation
First of all, you need a fresh Laravel version
and node dependencies installed to get
started; run the below commands
mentioned one by one to install the
required stuff.


composer create-project laravel/laravel
razorpay-demo
cd razorpay-demo
composer require laravel/ui
php artisan ui vue
npm install
npm run dev
Note: If you face this error
“Cannot find module
‘webpack/lib/rules/DescriptionDataMatche
rRulePlugin’”


Run this command


npm i vue-loader
Then in the separate terminal, run the
laravel server by using the following
command


php artisan serve
Include
/js/app.js and
app tag in the
view
Your app.js file will be compiled and saved
to public/js/app.js. Make sure to also have a
root element with an id of the app to your
HTML scaffolding. Otherwise, Vue won’t
know where to mount the components.


// resources/views/app.blade.php


<div id="app"></div>
<script src="{{ asset('js/app.js') }}"></script>




Having a developer with both front-end and
back-end insights works as an asset for your
project.


A full-stack developer sees the bigger picture
and codes accordingly, lessening the
troubleshooting time, issues, and bugs. {
break; } the loop of your search and contact us
today!


Try Our 15 Days Risk-Free Trial
VueJS Set-Up:
Razorpay
Payment
Gateway
Integration in
Laravel and
VueJS 2
// resources/js/app.js
import App from './App.vue';
const app = new Vue({
el: '#app',
template: "",
components: {
App,
},
});
Create
App.vue File
This file contains the Payment data for now;
in your real-time application, you need to
pass the user information and amount on
the “pay” button click.


// resources/js/App.vue


<template>
<section class="payment">
<div>
<span>Amount:</span>
<input type="text" v-model="amount" />
<button type="button"
@click="razorPay">Pay with
Razorpay</button>
</div>
</section>
</template>
<script>
import axios from "axios";
export default {
name: "app",
data() {
return {
amount: 100,
};
},
methods: {
razorPay() {
axios
.post("/api/payment/razorpay", { amount:
this.amount })
.then((res) => {
if (res.data) {
window.location.href = "/pay/razorpay?key="
+ res.data.key + "&amount=" + res.data.amount
+ "&order_id=" + res.data.order_id;
}
})
.catch((err) => {});
},
},
};
</script>
Create
Razorpay
Account
Create an Account from here:
https://razorpay.com
Get id and secret from here:
https://dashboard.razorpay.com/app/keys


Open .env file and add RazorPay key and
secret to it


// .env
RZ_KEY_ID=YOUR_KEY
RZ_SECRET=YOUR_SECRET
Set-Up and
Install
Razorpay
Package
Use the below command to install RazorPay
package


composer require razorpay/razorpay
Create config file to access .env values and
use the below code.
// config/values.php


env('RZ_KEY_ID', 'YOUR_KEY'),
'razorpaySecret' => env('RZ_SECRET',
'YOUR_SECRET'),
];
Create
Razorpay
Controller
Use the below command to create a
controller.


php artisan make:controller
RazorPayController
//app/Http/Controllers/RazorPayController
.php
order->create([
'receipt' => '123',
'amount' => $request->amount * 100,
'currency' => 'INR'
]); // Creates Razorpay order
$data = [
"key" =>
Config("values.razorpayKey"),
"amount" => $request->amount *
100,
"order_id" => $orderData['id'],
];
return response()->json($data, 200);
}
function verify(Request $request)
{
$success = true;
$error = "Payment Failed!";
if (empty($request-
>razorpay_payment_id) === false) {
$api = new
Api(Config("values.razorpayKey"),
Config("values.razorpaySecret"));
try {
$attributes = [
'razorpay_order_id' => $request-
>razorpay_order_id,
'razorpay_payment_id' => $request-
>razorpay_payment_id,
'razorpay_signature' => $request-
>razorpay_signature
];
>verifyPaymentSignature($attributes);
} catch (SignatureVerificationError $e) {
$success = false;
$error = 'Razorpay Error : ' . $e-
>getMessage();
}
}
if ($success === true) {
// Update database with success data
// Redirect to success page
return redirect('/');
} else {
// Update database with error data
// Redirect to payment page with error
// Pass $error along with route
return redirect('/');
}
}
}
Add Routes
Moving further in our tutorial: Razorpay
payment gateway integration. Let’s add
routes for displaying the Razorpay page
and verifying requests. Open the
routes/web.php file and use the below
code.


// routes/web.php


use
AppHttpControllersRazorPayController
;
Route::view('/pay/razorpay', 'razorpay');
Route::post('/pay/verify',
[RazorPayController::class, 'verify']);
Now, add an API route to access through
VueJS. For that use the following code.
Moving further in our tutorial: Razorpay
payment gateway integration. Let’s add
routes for displaying the Razorpay page
and verifying requests. Open the
routes/web.php file and use the below
code.


// routes/web.php


use
AppHttpControllersRazorPayController
;
Route::view('/pay/razorpay', 'razorpay');
Route::post('/pay/verify',
[RazorPayController::class, 'verify']);
Now, add an API route to access through
VueJS. For that use the following code.
// routes/api.php


use
AppHttpControllersRazorPayController
;
Route::post('payment/razorpay',
[RazorPayController::class, 'razorpay'])-
>name('paymentRazorpay');
Create
Razorpay
View
This is the Razorpay gateway, users will
enter the credentials and will pay using
various methods. Here you can enter your
company/personal details like name,
description, and logo to show users who
they are paying.


// resources/views/razorpay.blade.php


<script
src="https://checkout.razorpay.com/v1/che
ckout.js"></script>
<form name='razorpayform'
action="/pay/verify" method="POST">
<input type="hidden" name="_token"
value="{{ csrf_token() }}">
<input type="hidden"
name="razorpay_payment_id"
id="razorpay_payment_id">
<input type="hidden"
name="razorpay_signature"
id="razorpay_signature">
<input type="hidden"
name="razorpay_order_id"
id="razorpay_order_id" value="<?php echo
request()->order_id ?>">
</form>
<script>
var options = {
"key": "<?php echo request()->key ?>",
"amount": "<?php echo request()->amount ?
>",
"currency": "INR",
"name": "YOUR COMPANY NAME",
"description": "YOUR COMPANY
DESCRIPTION",
"image": "YOUR COMPANY IMAGE",
"order_id": "<?php echo request()-
>order_id ?>",
"handler": function(response) {
alert(response.razorpay_payment_id);
alert(response.razorpay_order_id);
alert(response.razorpay_signature)
},
"theme": {
"color": "#F37254"
}
};
options.handler = function(response) {
document.getElementById('razorpay_pay
ment_id').value =
response.razorpay_payment_id;
document.getElementById('razorpay_sign
ature').value =
response.razorpay_signature;
document.razorpayform.submit();
};
options.theme.image_padding = false;
options.modal = {
ondismiss: function() {
window.location.href = "/pay?
payment=false"
},
escape: true,
backdropclose: false
};
var rzp1 = new Razorpay(options);
rzp1.on('payment.failed',
function(response) {
alert(response.error.code);
alert(response.error.description);
alert(response.error.source);
alert(response.error.step);
alert(response.error.reason);
alert(response.error.metadata.order_id);
alert(response.error.metadata.payment_id)
;
});
rzp1.open();
</script>
You can also prefill user data if you have already;
you need to add this under options.
prefill: {
name: “USER NAME”,
email: “USER EMAIL”,
phone: “USER CONTACT”
}
Check
Transaction
The user interface will look something like
this.


Now it’s time to check the payment
transaction; for that, visit RazorPay
Dashboard.


Here is the reference image:
The entire source code is available here:
razorpay-payment-gateway-integration-
example. Use the below command to clone
the repository and play around with it.


git clone
https://github.com/keyurkansara/razorpay-
laravel-vue.git
Conclusion
I hope the tutorial: Razorpay payment
gateway integration has helped you as
expected. Feel free to contact us with
questions, suggestions, or feedback. You can
visit VueJS and Laravel tutorials pages and
explore more about both the technology
individually. Each tutorial will provide you
with a github repository so that you can
play around with the code.


Bacancy has a skilled set of developers who
has expertise with backend and frontend
development. Our dedicated full-stack
developers analyze the project
requirements and problems from front-end
and back-end perspectives, providing the
optimum solution. Are you looking for
developers who have both frontend and
backend experience? If yes, then without
wasting a second, contact us and hire
fullstack developers.
Thank You
www.bacancytechnology.com

More Related Content

What's hot

Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing optionsNir Kaufman
 
Introduction to Novell ZENworks Configuration Management Troubleshooting
Introduction to Novell ZENworks Configuration Management TroubleshootingIntroduction to Novell ZENworks Configuration Management Troubleshooting
Introduction to Novell ZENworks Configuration Management TroubleshootingNovell
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソースEnpel
 
Développer sous Sylius en 40 minutes chrono
Développer sous Sylius en 40 minutes chronoDévelopper sous Sylius en 40 minutes chrono
Développer sous Sylius en 40 minutes chronoMaxime Huran 🌈
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxAbhijeetKumar456867
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014JWORKS powered by Ordina
 
Laravel Dusk
Laravel DuskLaravel Dusk
Laravel Duskkingvish
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
Web Design Project Report
Web Design Project ReportWeb Design Project Report
Web Design Project ReportMJ Ferdous
 
Introduction of Progressive Web App
Introduction of Progressive Web AppIntroduction of Progressive Web App
Introduction of Progressive Web AppSankalp Khandelwal
 

What's hot (20)

Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 
Introduction to Novell ZENworks Configuration Management Troubleshooting
Introduction to Novell ZENworks Configuration Management TroubleshootingIntroduction to Novell ZENworks Configuration Management Troubleshooting
Introduction to Novell ZENworks Configuration Management Troubleshooting
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Angular 9
Angular 9 Angular 9
Angular 9
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
 
Développer sous Sylius en 40 minutes chrono
Développer sous Sylius en 40 minutes chronoDévelopper sous Sylius en 40 minutes chrono
Développer sous Sylius en 40 minutes chrono
 
Laravel
LaravelLaravel
Laravel
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptx
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014
 
Laravel Dusk
Laravel DuskLaravel Dusk
Laravel Dusk
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Web Design Project Report
Web Design Project ReportWeb Design Project Report
Web Design Project Report
 
Angular
AngularAngular
Angular
 
Introduction of Progressive Web App
Introduction of Progressive Web AppIntroduction of Progressive Web App
Introduction of Progressive Web App
 
Oauth2.0
Oauth2.0Oauth2.0
Oauth2.0
 

Similar to Razorpay payment gateway integration in laravel and vue js 2

Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftInnovationM
 
How to integrate paytm payment gateway using react js in seven easy steps
How to integrate paytm payment gateway using react js in seven easy stepsHow to integrate paytm payment gateway using react js in seven easy steps
How to integrate paytm payment gateway using react js in seven easy stepsKaty Slemon
 
Learn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfLearn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfBe Problem Solver
 
java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guideZenita Smythe
 
Ajax Rails
Ajax RailsAjax Rails
Ajax Railshot
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appBeginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appKaty Slemon
 
Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Phenom People
 
How to implement multiple authentication guards in laravel 8
How to implement multiple authentication guards in laravel 8How to implement multiple authentication guards in laravel 8
How to implement multiple authentication guards in laravel 8Katy Slemon
 
Java spring mysql without hibernate(2) (1)
Java spring mysql without hibernate(2) (1)Java spring mysql without hibernate(2) (1)
Java spring mysql without hibernate(2) (1)AmedJacobReza
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Jonathan LeBlanc
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel PassportMichael Peacock
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Nicolás Bouhid
 
node.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ionode.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ioSteven Beeckman
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)Amazon Web Services
 

Similar to Razorpay payment gateway integration in laravel and vue js 2 (20)

Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
 
How to integrate paytm payment gateway using react js in seven easy steps
How to integrate paytm payment gateway using react js in seven easy stepsHow to integrate paytm payment gateway using react js in seven easy steps
How to integrate paytm payment gateway using react js in seven easy steps
 
Learn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfLearn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdf
 
java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guide
 
Ajax Rails
Ajax RailsAjax Rails
Ajax Rails
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Payments On Rails
Payments On RailsPayments On Rails
Payments On Rails
 
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appBeginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
 
You Know WebOS
You Know WebOSYou Know WebOS
You Know WebOS
 
Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account
 
Rails course day 6
Rails course day 6Rails course day 6
Rails course day 6
 
How to implement multiple authentication guards in laravel 8
How to implement multiple authentication guards in laravel 8How to implement multiple authentication guards in laravel 8
How to implement multiple authentication guards in laravel 8
 
Laravel tips-2019-04
Laravel tips-2019-04Laravel tips-2019-04
Laravel tips-2019-04
 
Salesforce and sap integration
Salesforce and sap integrationSalesforce and sap integration
Salesforce and sap integration
 
Java spring mysql without hibernate(2) (1)
Java spring mysql without hibernate(2) (1)Java spring mysql without hibernate(2) (1)
Java spring mysql without hibernate(2) (1)
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
node.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ionode.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.io
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
 

More from Katy Slemon

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfKaty Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfKaty Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfKaty Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfKaty Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfKaty Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfKaty Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfKaty Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfKaty Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfKaty Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfKaty Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfKaty Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfKaty Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfKaty Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfKaty Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfKaty Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfKaty Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfKaty Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfKaty Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfKaty Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfKaty Slemon
 

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Razorpay payment gateway integration in laravel and vue js 2

  • 2. In this latest technology world, the combination of Laravel and VueJS is unbeatable and very powerful to make any high-end application that runs smooth. There is an increasing need for e- commerce/content-driven websites. You now need a payment gateway to make easy transactions. So here is the way to integrate Razorpay payment gateway to your Laravel 6/7/8 versions along with VueJS. Without further ado, let’s get started with the Razorpay Payment Gateway Integration in Laravel and VueJS 2.
  • 4. First of all, you need a fresh Laravel version and node dependencies installed to get started; run the below commands mentioned one by one to install the required stuff. composer create-project laravel/laravel razorpay-demo cd razorpay-demo composer require laravel/ui php artisan ui vue npm install npm run dev Note: If you face this error “Cannot find module ‘webpack/lib/rules/DescriptionDataMatche rRulePlugin’” Run this command npm i vue-loader
  • 5. Then in the separate terminal, run the laravel server by using the following command php artisan serve
  • 7. Your app.js file will be compiled and saved to public/js/app.js. Make sure to also have a root element with an id of the app to your HTML scaffolding. Otherwise, Vue won’t know where to mount the components. // resources/views/app.blade.php <div id="app"></div> <script src="{{ asset('js/app.js') }}"></script> Having a developer with both front-end and back-end insights works as an asset for your project. A full-stack developer sees the bigger picture and codes accordingly, lessening the troubleshooting time, issues, and bugs. { break; } the loop of your search and contact us today! Try Our 15 Days Risk-Free Trial
  • 9. // resources/js/app.js import App from './App.vue'; const app = new Vue({ el: '#app', template: "", components: { App, }, });
  • 11. This file contains the Payment data for now; in your real-time application, you need to pass the user information and amount on the “pay” button click. // resources/js/App.vue <template> <section class="payment"> <div> <span>Amount:</span> <input type="text" v-model="amount" /> <button type="button" @click="razorPay">Pay with Razorpay</button> </div> </section> </template> <script> import axios from "axios";
  • 12. export default { name: "app", data() { return { amount: 100, }; }, methods: { razorPay() { axios .post("/api/payment/razorpay", { amount: this.amount }) .then((res) => { if (res.data) { window.location.href = "/pay/razorpay?key=" + res.data.key + "&amount=" + res.data.amount + "&order_id=" + res.data.order_id; } }) .catch((err) => {}); }, }, }; </script>
  • 14. Create an Account from here: https://razorpay.com Get id and secret from here: https://dashboard.razorpay.com/app/keys Open .env file and add RazorPay key and secret to it // .env RZ_KEY_ID=YOUR_KEY RZ_SECRET=YOUR_SECRET
  • 16. Use the below command to install RazorPay package composer require razorpay/razorpay Create config file to access .env values and use the below code. // config/values.php env('RZ_KEY_ID', 'YOUR_KEY'), 'razorpaySecret' => env('RZ_SECRET', 'YOUR_SECRET'), ];
  • 18. Use the below command to create a controller. php artisan make:controller RazorPayController //app/Http/Controllers/RazorPayController .php order->create([ 'receipt' => '123', 'amount' => $request->amount * 100, 'currency' => 'INR' ]); // Creates Razorpay order $data = [ "key" => Config("values.razorpayKey"), "amount" => $request->amount * 100, "order_id" => $orderData['id'], ];
  • 19. return response()->json($data, 200); } function verify(Request $request) { $success = true; $error = "Payment Failed!"; if (empty($request- >razorpay_payment_id) === false) { $api = new Api(Config("values.razorpayKey"), Config("values.razorpaySecret")); try { $attributes = [ 'razorpay_order_id' => $request- >razorpay_order_id, 'razorpay_payment_id' => $request- >razorpay_payment_id, 'razorpay_signature' => $request- >razorpay_signature ];
  • 20. >verifyPaymentSignature($attributes); } catch (SignatureVerificationError $e) { $success = false; $error = 'Razorpay Error : ' . $e- >getMessage(); } } if ($success === true) { // Update database with success data // Redirect to success page return redirect('/'); } else { // Update database with error data // Redirect to payment page with error // Pass $error along with route return redirect('/'); } } }
  • 22. Moving further in our tutorial: Razorpay payment gateway integration. Let’s add routes for displaying the Razorpay page and verifying requests. Open the routes/web.php file and use the below code. // routes/web.php use AppHttpControllersRazorPayController ; Route::view('/pay/razorpay', 'razorpay'); Route::post('/pay/verify', [RazorPayController::class, 'verify']); Now, add an API route to access through VueJS. For that use the following code.
  • 23. Moving further in our tutorial: Razorpay payment gateway integration. Let’s add routes for displaying the Razorpay page and verifying requests. Open the routes/web.php file and use the below code. // routes/web.php use AppHttpControllersRazorPayController ; Route::view('/pay/razorpay', 'razorpay'); Route::post('/pay/verify', [RazorPayController::class, 'verify']); Now, add an API route to access through VueJS. For that use the following code.
  • 26. This is the Razorpay gateway, users will enter the credentials and will pay using various methods. Here you can enter your company/personal details like name, description, and logo to show users who they are paying. // resources/views/razorpay.blade.php <script src="https://checkout.razorpay.com/v1/che ckout.js"></script> <form name='razorpayform' action="/pay/verify" method="POST"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <input type="hidden" name="razorpay_payment_id" id="razorpay_payment_id"> <input type="hidden" name="razorpay_signature" id="razorpay_signature">
  • 27. <input type="hidden" name="razorpay_order_id" id="razorpay_order_id" value="<?php echo request()->order_id ?>"> </form> <script> var options = { "key": "<?php echo request()->key ?>", "amount": "<?php echo request()->amount ? >", "currency": "INR", "name": "YOUR COMPANY NAME", "description": "YOUR COMPANY DESCRIPTION", "image": "YOUR COMPANY IMAGE", "order_id": "<?php echo request()- >order_id ?>", "handler": function(response) { alert(response.razorpay_payment_id); alert(response.razorpay_order_id); alert(response.razorpay_signature) },
  • 28. "theme": { "color": "#F37254" } }; options.handler = function(response) { document.getElementById('razorpay_pay ment_id').value = response.razorpay_payment_id; document.getElementById('razorpay_sign ature').value = response.razorpay_signature; document.razorpayform.submit(); }; options.theme.image_padding = false; options.modal = { ondismiss: function() { window.location.href = "/pay? payment=false" }, escape: true, backdropclose: false };
  • 29. var rzp1 = new Razorpay(options); rzp1.on('payment.failed', function(response) { alert(response.error.code); alert(response.error.description); alert(response.error.source); alert(response.error.step); alert(response.error.reason); alert(response.error.metadata.order_id); alert(response.error.metadata.payment_id) ; }); rzp1.open(); </script> You can also prefill user data if you have already; you need to add this under options.
  • 30. prefill: { name: “USER NAME”, email: “USER EMAIL”, phone: “USER CONTACT” }
  • 32. The user interface will look something like this. Now it’s time to check the payment transaction; for that, visit RazorPay Dashboard. Here is the reference image:
  • 33. The entire source code is available here: razorpay-payment-gateway-integration- example. Use the below command to clone the repository and play around with it. git clone https://github.com/keyurkansara/razorpay- laravel-vue.git
  • 35. I hope the tutorial: Razorpay payment gateway integration has helped you as expected. Feel free to contact us with questions, suggestions, or feedback. You can visit VueJS and Laravel tutorials pages and explore more about both the technology individually. Each tutorial will provide you with a github repository so that you can play around with the code. Bacancy has a skilled set of developers who has expertise with backend and frontend development. Our dedicated full-stack developers analyze the project requirements and problems from front-end and back-end perspectives, providing the optimum solution. Are you looking for developers who have both frontend and backend experience? If yes, then without wasting a second, contact us and hire fullstack developers.