ASP.NET MVC

How To Get All Payments From Razorpay In Asp.Net MVC

In this article, we are getting or retrieving all paments from Razorpay in Asp.Net MVC.

I am using its NuGet Package named Razorpay In our .Net Application. if you don’t know How To Integrate Razorpay In Asp.Net MVC then click here.

we are getting all payments from Razorpay, you can filter it out also.but for the demonstration I get all payments in this article.

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

public ActionResult GetPayments()
        {
            List<Payment> result = new List<Payment>();
            try
            {
                Dictionary<string, object> options = new Dictionary<string, object>();
                //supported option filters (from, to, count, skip)
                options.Add("count", 50);
                result = client.Payment.All(options);

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

            }
            catch (Exception ex)
            {
            }
            return View(result);
        }

in the above code, I defined options Dictionary in which we store all options related to Payments. there are different options which you can use according to your requirement. you can get more details about it by clicking here.

here I only use the count option.in which you have to give a number of payments to be fetched. The default value is 10. The maximum value is 100. you can use it for pagination, in combination with the Skip parameter. so our code will return 50 payments as we give 50 as a count option.

now create GetPayments.cshtml, and add the following code into it.

@using Razorpay.Api;
@model List<Payment>


@{
    ViewBag.Title = "GetPayments";
}

<h2>GetPayments</h2>
<br />
<div class="row">

    <div class="col-md-12">

        <table class="table table-bordered">

            <tr>
                <th>Paymnet Id</th>
                <th>email</th>
                <th>Amount</th>
                <th>currency</th>
                <th>method</th>
                <th>status</th>
            </tr>

            @foreach (var item in Model)
            {
                <tr>
                    <td>@item.Attributes["id"]</td>
                    <td>@item.Attributes["email"]</td>
                    @{var FinalAmount = Convert.ToInt32(item.Attributes["amount"]) / 100; }
                    <td>@FinalAmount</td>
                    <td>@item.Attributes["currency"]</td>
                    <td>@item.Attributes["method"]</td>
                    <td>@item.Attributes["status"]</td>
                </tr>

            }

        </table>

    </div>

</div>

here we display only few properties of Payment. you can fetch and display according to your needs.

The above code will produce output like below.

GetPayments.cshtml

 

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

3 years ago