Subscribe Us

Complete Example of Razorpay Api to get bank detail by IFSC code using dotnet core

IntroductionIn this article I am going to explain How to use Razorpay Api to get bank detail by IFSC code using dotnet core.


Description: I am creating asp.net core project and create a async method to get branch details on the basis of IFSC Code.




Implementation: Let’s create an asp.net core demo page for demonstration purpose.


Controller Code:


public async Task<IActionResult> GetBranchByIFSCAsync(string ifsc)
        {
            var bank = new BankModel();
            try
            {
                using (var httpClient = new HttpClient())
                {
                    using (var response = await httpClient.GetAsync($"https://ifsc.razorpay.com/{ifsc}"))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();
                        bank = JsonConvert.DeserializeObject<BankModel>(apiResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                return Json(new
                {
                    success = false,
                    message = ex.ToString()

                });

            }
            return Json(new
            {
                success = true,
                bank

            });
        }


View Code:

<div class="form-row">
    <div class="col-md-8">
        <div class="form-group">
            <label class="small mb-1">IFSC Code</label>
            <input class="form-control py-4" id="IFSCCode" aria-describedby="emailHelp" required="required"
                   placeholder="Enter IFSC Cide" />
        </div>
    </div>
    <div class="col-md-4">
        <div class="form-group">
            <label class="small mb-1"></label>
            <button id="btnGetBranch" class="btn btn-primary btn-block mt-2">Check IFSC Code</button>
        </div>
    </div>
</div> 



JS Code

<script>
        $('#btnGetBranch').click(function () {
            getBankDetails();
        });
        var getBankDetails = function () {
            debugger;
            if ($('#IFSCCode').val().length > 0 && $('#IFSCCode').val() != '') {
                $.get("/Home/GetBranchByIFSC/" + $('#IFSCCode').val(), function (data) {
                    if (data.success) {
                        console.log('bank details', data.bank);
                        $('#Branch').val(data.bank.branch);
                        $('#BankName').val(data.bank.bank);
                        $('#BankAddress').val(data.bank.address + ',' + data.bank.city
                            + ',' + data.bank.district + ',' + data.bank.state);
                    }
                });
            }
        }
    </script> 


 

Note: For demonstration purpose I have created dotnet core application. You can do the same in asp.net MVC.



Explanation: As you can see we have created 1 Js method getBankDetails() which will can on click of btnGetBranch. In home controller there is a method GetBranchByIFSC() to fetch data and display on the page.
Result: 
 


 

Post a Comment

2 Comments

  1. Hi Admin,

    When I tried to convert this into asp.net I got error in Content especially.

    await response.Content.ReadAsStringAsync();

    please look into the matter and advise code for asp.net 4.5

    Thanks in advance

    ReplyDelete

Thanks for your valuable time.