ASP.NET MVC

How To Create Customer Into Razorpay From Asp.Net MVC

In this article, we are going to create/Add Customers into Razorpay from Asp.Net MVC.

For Using Razorpay in our .Net Application we are going to use its NuGet Package named Razorpay.

if you don’t know How To Integrate Razorpay In Asp.Net MVC then click here.

Now, create the CreateCustomer Method and add the following code into the CreateCustomer Method.

public ActionResult CreateCustomer()
     {
         bool IsCustomerCreated = false;
         try
         {
             Dictionary<string, object> CustomerOption = new Dictionary<string, object>();

             CustomerOption.Add("name", "faisal");
             CustomerOption.Add("email", "faisalmpathan.vision@gmail.com");
             CustomerOption.Add("contact", "7016522607");

             Customer ObjCustomer = new Customer().Create(CustomerOption);
             var CustomerId = Convert.ToString(ObjCustomer["id"]);

             if (!string.IsNullOrEmpty(CustomerId))
             {
                 IsCustomerCreated = true;
             }

         }
         catch (Razorpay.Api.Errors.BadRequestError ex)
         {

         }
         catch (Exception ex)
         {

         }
         ViewBag.IsCustomerCreated = IsCustomerCreated;
         return View();
     }

in the above code, we define CustomerOption Dictionary in which we store all options related to Customers. name and contact options are mandatory.

here I give only 3 options name, contact, and email. there are many options available according to your need. you can see that on the Razorpay portal by clicking here.

above code will create new customers with given details if the same customer does not exist else it will go into BadRequestError Exception.

Now, create the CreateCustomer.cshtml View and add the following code into it.

@{
    ViewBag.Title = "CreateCustomer";
}

<div class="jumbotron">

    @if (ViewBag.IsCustomerCreated == true)
    {
        <p class="lead"><label class="label-success">Customer Created successfully.!</label></p>
    }


</div>

The following are outputs of above code.

CreateCustomer view

Razorpay Dashboard

 

Tabish Rangrej

Tabish Rangrej is an Experienced .NET Team Leader, software engineer, and Author with a demonstrated history of working in the IT industry. He has quite well experience in developing, communicating, managing, and writing in his field. He has strong skills and knowledge of ASP.NET C#, ASP.NET MVC, ASP.NET CORE, Angular, AngularJS, Web API, SQL, Entity Framework, JavaScript, Jquery, Different Integrations like Quickbooks, Stripe, Google APIs, Zoho, Orion, Xero, etc., Different versioning tools like TFS, SVN, GIT, etc. and Windows services. Strong engineering professional with a Master of Computer Applications - MCA focused on Computer Science from Veer Narmad South Gujarat University, Surat. Tabish is always ready to accept new challenges and learn new things, he would like to serve better for the community.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago