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;
             Dictionary<string, object> CustomerOption = new Dictionary<string, object>();

             CustomerOption.Add("name", "faisal");
             CustomerOption.Add("email", "");
             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>


The following are outputs of above code.

CreateCustomer view

Razorpay Dashboard


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories