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

 

Submit a Comment

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

Subscribe

Select Categories