Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Tools
    • Json Beautifier
    • Html Beautifier
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
02 Nov
2020

Payumoney Integration With Asp.Net MVC

by Shubham Batra

8689

Download Attachment

PayuMoney- 

It is a payments getway getting popular now a days. Actually there are few other payments getways like Stripe,Paypal. And PayuMoney is also getting more popular now a days.

So in this article we will learn how to do Payumoney Integration With Asp.Net MVC.

So for this puprpose you must have Client Key and Secret before starting integration of PayuMoney. You can go through https://www.payu.in/developer-guide. There you can generate merchant key for your project. After having merchant key and test credentials we can move to the next steps as described below:-

Step 1 : Paste the code in controller

So for this step we have to copy the Action method given below in our controller . Index method will be used to run the page. While Payment Success method will be called after the payment is successful and Payment Failed method will be called in case our payment transaction is failed.

Here we have to know about how those two actions will be hit. Those two will be passed in surl and furl. Which basically stands for success url and failure url.

surl- It is basically the url where you website will redirect after successfull payment. Or in short its the success url. 

furl-It is basically the url where you website will redirect after failure of  payment. Failure can happen due to wrong otp or wrong card details. So in that case it will go to furl.

Hash: PayuMoney actually expects few parameters as mandatory. And after surl,furl Hash is a mandatory parameter. It is basically a encrypted form of values. You can use the action provided in code snippet for generating hash.

Hash must be created based on following formula

sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||SALT)

     public ActionResult Index()
        {
            
            return View();
        }

        [HttpPost]
        public ActionResult PaymentSuccess()
        {
            var form = Request.Form.ToString();
            ViewBag.mihpayid = Request.Form["mihpayid"].ToString();
            ViewBag.paymentId = Request.Form["paymentId"].ToString();
            ViewBag.mode = Request.Form["Mode"].ToString();
            ViewBag.status = Request.Form["status"].ToString();
            ViewBag.txnid = Request.Form["txnid"].ToString();
            ViewBag.amount = Request.Form["amount"].ToString();
            return View("PaymentSuccess");
        }

        [HttpPost]
        public ActionResult PaymentFailed()
        {
            var form = Request.Form.ToString();
            return View("Index");
        }

        public ActionResult Hash(string txnid, string key, string salt, string amount, string productinfo, string firstname, string email, string phone, string udf5,string udf1)
        {
         

            string d = key + "|" + txnid + "|" + amount + "|" + productinfo + "|" + firstname + "|" + email + "|"+ udf1 +"||||" + udf5 + "||||||" + salt;
            return Json(GetStringFromHash(d), JsonRequestBehavior.AllowGet);

        }
        private static string GetStringFromHash(string text)
        {
            byte[] message = Encoding.UTF8.GetBytes(text);

            UnicodeEncoding UE = new UnicodeEncoding();
            byte[] hashValue;
            SHA512Managed hashString = new SHA512Managed();
            string hex = "";
            hashValue = hashString.ComputeHash(message);
            foreach (byte x in hashValue)
            {
                hex += String.Format("{0:x2}", x);
            }
            return hex;
        }
      

Step 2: Add this script in _layout.cs.html

 <script id="bolt" src="https://sboxcheckout-static.citruspay.com/bolt/run/bolt.min.js" bolt-color="e34524" bolt-logo="http://boltiswatching.com/wp-content/uploads/2015/09/Bolt-Logo-e14421724859591.png"></script>


Step 3: Paste the code in Index.cs.html

After completing the controller part. We can now move to the html side. So for using PayuMoney we have to create a form and have to add few mandatory fields there as explained in code snippet. And if you missed any of those your PayuMoney  will not work.

TestUrl-   https://test.payu.in/_payment

Production Url- https://secure.payu.in/_payment

We have to pass these url in action attribute of form

 @{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

  <form action="https://secure.payu.in/_payment" method="post" id="payment_form">
            <input type="hidden" id="udf5" name="udf5" value="payu_paisa" />
            <input type="hidden" id="udf1" name="udf1" value="91" />
            <input type="hidden" id="surl" name="surl" value="https://localhost:44301/Home/PaymentSuccess" />
            <input type="hidden" id="furl" name="furl" value="https://localhost:44301/Home/PaymentFailed" />
            <div class="dv">
                <span class="text"><label>Merchant Key:</label></span>
                <span><input type="password" id="key" name="key" placeholder="Enter your Merchant Key" value="" /></span>
                <input type="text" id="key" name="service_provider" value="payu_paisa" />
            </div>

            <div class="dv">
                <span class="text"><label>Merchant Salt:</label></span>
                <span><input type="password" id="salt" name="salt" placeholder="Enter your Merchant Salt" value="" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Transaction/Order ID:</label></span>
                <span><input type="text" id="txnid" name="txnid" placeholder="Transaction ID" value="12345" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Amount:</label></span>
                <span><input type="text" id="amount" name="amount" placeholder="Amount" value="1.00" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Product Info:</label></span>
                <span><input type="text" id="pinfo" name="productinfo" placeholder="Product Info" value="P01" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>First Name:</label></span>
                <span><input type="text" id="fname" name="firstname" placeholder="First Name" value="Code2night" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Email ID:</label></span>
                <span><input type="text" id="email" name="email" placeholder="Enter Email ID" value="" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Mobile/Cell Number:</label></span>
                <span><input type="text" id="mobile" name="phone" placeholder="Mobile/Cell Number" value="6767788999" /></span>
            </div>

            <div class="dv">
                <span class="text"><label>Hash:</label></span>
                <span><input type="text" id="hash" name="hash" placeholder="Hash" value="" /></span>
            </div>
            <div id="alertinfo" class="dv"></div>

            <div><input type="submit" value="Pay" /></div>
        </form>
<script>
       $('#payment_form').bind('keyup blur', function () {
            $.ajax({
                url: '/Home/hash',
                type: 'post',
                data: JSON.stringify({
                    key: $('#key').val(),
                    salt: $('#salt').val(),
                    txnid: $('#txnid').val(),
                    amount: $('#amount').val(),
                    productinfo: $('#pinfo').val(),
                    firstname: $('#fname').val(),
                    email: $('#email').val(),
                    mobile: $('#mobile').val(),
                    udf5: $('#udf5').val(),
                    udf1: $('#udf1').val()
                }),
                contentType: "application/json",
                dataType: 'json',
                success: function (json) {
                    $('#hash').val(json);
                }
            });
        });
</script>

Final Output

Now run the application and you will see a form. Fill data in the form and click on pay. While filling the form make sure your merchant key and merchant salt is correct.

After click on Pay you will be redirected to this screen. Here you will find various options to complete payment. you can choose any of the option and fill correct details and click on pay now.


you can also use upi system for payment in India.

After the payment is completed. you will see this popup. Click on done and it will redirect to the url which is present inside surl parameter.


In this action you will get all the returned parameters from payuMoney. You can get all the details related to payment for your use. You can see some of them in below screenshot like how to get those.

So this is how you can integrate payumoney in you Asp.Net MVC application.

  • |
  • Payumoney Integration With AspNet MVC

Comments

Follow Us On Social Media - Like Us On Facebook

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Image Optimize in C#
Scheduler
Web Api in Aspnet MVC
Web API CRUD Operations
Web API CRUD Operations In ASPNET MVC Application
create a read only MySQL user
Scheduler Service
Task scheduler in AspNet
Task Scheduler
Git Tutorial for Beginners and Intermediate
Git Tutorial
Git
Github
commit
repository
push
pull request
branches
Git Branching and Merging
Branching
Merging
compress images csharp
compress jpeg csharp
compress png csharp
compress tiff csharp
Slick Slider
Slick Slider Responsive
Csharp
OpenJson
Sql server
Json
Numbers validation javascript
Allow only numbers to be typed in a textbox
Number validation in JavaScript
Numric only validation in javascript
Alphanumeric validation javascript
Allow only Alphanumeric to be typed in a textbox
Alphanumeric validation in JavaScript
Number And Decimal validation javascript
Allow only Number And Decimal to be typed in a textbox
Number And Decimal validation in JavaScriptA
Alphabets validation javascript
Allow only Alphabets to be typed in a textbox
Alphabets validation in JavaScript
Aphabet validations using js
Jquery
Validations
AspNet Core MVC Publish using FTP (File Transfer Protocol)
AspNet MVC Publish using FTP (File Transfer Protocol)
AspNet MVC Publish using FTP
AspNet Core MVC Publish using FTP
Publish using FTP
How to add whatsapp share button on a website
How to add a WhatsApp share button on a website
apiwhatsappcom
Share to whatsapp
HTTP Error 50031 Failed to load ASP NET Core runtime
Http Error
The Extender Provider failed to return an Extender for this object
Twilio SMS and ASPNET Core 60
How to Send an SMS with ASPNET Core
Using Dependency Injection with Twilio SMS and ASPNET Core 21
Twillio
Twillio in AspNet
Twillio SMS Integration
Number And Decimal validation in JavaScript
Quickblox
Quickblox javascript sdk
javascript sdk
Audio and video call using js
Quickblox audio call
Quickblox video call
Winforms
DevExpress
Net
Reading Values From Appsettingsjson In ASPNET Core 31 and 60
appsettingsjson
ASPNET Core
Reading Values From appsettingsjson
countdown timer
Timer in js
Jquery InputMask
Input masking
Masking using jquery
Phone mask
Email mask
Input mask using jquery
Firebase
Firebase Database
Firesharp
Firebase using Aspnet
Neo4J
Neo4j Driver
Neo4J in Aspnet
Graph Database
JWT
JWT Token
JWT in AspNet
JWT in Aspnet MVC
Validate jwt token
Twilio SMS And ASPNET MVC
How To Send An SMS With ASPNET MVC
Twillio In AspNet
Implementation Of SignalR With NET Core
Build Real time Applications with ASPNET Core SignalR
NET Core
SignalR
SignalR With NET Core
signalr in aspnet core
Owin Authentication
Owin
Microsoft Owin
Owin in Api
Owin authentication in Api
Twillio Logs
Get Twillio Logs
Paypal
Paypal Integration in AspNet MVC
Paypal Integration
Unable to connect to any of the specified MySQL hosts
Aspnet Core
Paypal in Aspnet core
Payout in Paypal
Paypal Payment Gateway
Payouts
Hangfire with ASPNET Core
Hangfire in ASPNET Core 31
Hangfire in ASPNET
Hangfire
Web Api
Api
Aspnet core
AutoMapper
Automapper in Aspnet MVC
Angular Material Select Dropdown with Image
StreamReader
Json to C#
JWT Token Authentication And Authorizations In Web API
C# Collections
Collections (C#)
Fibonacci series in Java
Display Fibonacci Series
First C# Program
What is C?
C
C Programming
Narrowing Casting
Widening Casting
Java Type Casting
How to Connect to a Database with MySQL Workbench
read only MySQL user
GROUP_CONCAT()
Multiple rows to one comma separated value in Sql Server
Converting commas or other delimiters to a Table or List in SQL Server
Sql Server
Finding table references
T Sql
Finding tables by column name
Renaming column in Sql
RazorPay in Aspnet MVC
RazorPay in net
RazorPay in MVC
RazorPay Integration in AspNet
Implementing RazorPay in Aspnet
aspnetmvc
Ninject In ASPNET MVC
csharp
designpattern
ef
Python
OpenCV
Face Detection
Realtime face detection
AI
How to set Date and time format in IIS Manager
IIS Manager
IIS
Internet Information Services (IIS) Manager
Internet Information Services (IIS)
Internet Information Services
Error Handling In AspNet Core
Exception Handling Asp Net Core
Exception Handling
Exception Handling Asp Net
Creating Log Files in MVC
Error Handling in MVC
Exception Handling in AspNet
Handling Exceptions and Creating Error Logs in Asp net Mvc using base controller
net
Code2Tonight
Stopping Browser Reload On Save
Repository Pattern with ADONet in MVC
Repository Pattern With ASPNET MVC And AdoNet
MVC Crud Operation
Jquery Full Calender Integrated With ASPNET
Full Calendar
Jquery Calendar
Slick Slider Example
responsive carousels
Entity Framework
Intergrate SummerNote Text Editor into AspNet MVC
Web Config
Auto Redirection
Redirection from Http to https
Url Rewriting
Implement Stripe Payment Gateway In ASPNET Core
Stripe Payment Gateway
StripeNet
Convert HTML String To Image In C#
HTMLtoImage
Convert Html to Image in AspNet
Postgre
PgAdmin4
PostgreSql
A Non Fatal Error Occured During Cluster Initialisation In Postgre SQL
Microsoft Outlook
Outlook Appointments
Microsoft Exchange Service
Send Email With HTML Template And PDF Using ASPNet C#
Send Email
Email with html template
email with pdf attachment
email with html and pdf
Microsoft Outlook Contacts
Outlook
Microsoft Exhchange Service
JSON
Convert string with dot notation to JSON
HTTP Error 5025 ANCM Out Of Process Startup Failure
Internet Information Service
Net core
Payumoney Integration With AspNet MVC
Prism js
Highlighting Syntax
Syntax Highlighting
code stylings
c#
Jquery AJax
Ajax
Implement Stripe Payment Gateway In ASPNET
Using Checkout in an ASPNET Web Forms application
Stripe Payment
Stripe Payment Integration
Stripe Integeration
How to upload Image file using AJAX andjQuery
upload Image file using AJAX and jquery
Ajax call
file upload using ajax
file uploading using ajax and jquery
ConfigurationBuilder does not contain a definition for SetBasePath
Reading app json file in dot net core
Appsetting jso
Dot Net Core
Globalization and localization in ASPNET Core
Asp Net Core with Resource file resx
How to get the resx file strings in asp net core
Culture in Net core
Localisation in AspNet Core
Url Encryption in AspNet MVC
Url Encryption in C#
Url Encryption
Custom Helpers
Caching in ASPNET Core using Redis Cache
Redis Cache
Caching in ASPNET Core
ASPNET Core Redis Cache
Slick Slider with single slide
Slick
Vue js
Child Components
How to reload vue js child components
Net Core
Visual Studio
Net core 31
Razor
Zoom sdk
Zoom c# wrapper Inegration
zoom Integration in c#
Zoom Integration
Zoom window sdk
vue js toggle button
vue js
toggle buttons
vuejs
vue js toggle switch
VueJs
SignalR in Net Core
Chat App in Vue js
Chat App using SignalR
AspNet Chat app
JPlayer
Html5 Audio Video Player
Music Player
QR Code Generator
QR Code
Jquery QR Code
Google Maps
Google map api
Places API
Google map Places API in AspNet
Jquery Autocomplete
Autocomplete
Jquery UI Autocomplete
ExcelDataReader
Import data from excel in AspNet
Card Number Formatting
Amex Card Format
Card Format
FCM
Cloud Messaging
Android Notifications
FCM Notifications for IOS
IOS Notifications
Angular js
apply css on child components in Angular js
Angular Mentions
Google Sign In
Google Login
Google Oauth Api
Social Login
Aspnet Mvc
Google + Api
Create and publish a package using Visual Studio (NET Framework
Windows)
Create and publish a nuget package
create your own nuget package
Image compress
Image optimization
compress Image
optimize Image
WebForm
AspNet Web Pages
Batch Script
Database backup
Powershell
ASpNet
Sql Server Backup
AspNet core 31
Aspnet core 21
HttpCookies in AspNet Core
Custom FIlter attribute
Custom Authentication
LinkedIn Authentication
Login using LinkedIN
Social Login in AspNet
LinkedIn Authentication in AspNet MVC
LinkedIn Login in aspnet MVC
Shuffle List in c#
C#Net
Google Login in AspNet MVC
GoogleAuthentication Nuget package
Password Encryption
RFC Encryption
Encryption and Decryption
Encryption in AspNet
Base 64 Encryption
Base 64 Decryption
Swagger UI
Swashbuckle
SwashbuckleAspNetCore
Rest API
Postman
Api Testing
SSRS
SSRS Report
ASPNET MVC
ASPNET MVC SSRS Report
ssrs report
XlWorkbook
ClosedXml
Excel Export
Blazor
Syncfusion
SFGrid
Syncfusion SFgrid
Net core 60
DataTable to List
Extension Methods
Microsoft Access Database Engine
Ace Ole Db 120
MicrosoftACEOLEDB120
OLE DB
Aspnet MVC
Ace OLE DB
rdlc
Report Viewer
RDLC Report
Max Request Length
Thank you for Downloading....!

Subscribe for more tutorials

Support our team

Continue with Downloading

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Kurukshetra
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2023 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Json Beautifier