Reputation: 11
I want to integrate web api of RazorPay by which I will get the bank details by providing the IFSC code.
I have a code which works fine in ASP.Net Core but not working in ASP.Net 4.7.
ASP.Net core code:
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);
}
}
}
in Response.Content
I am getting an error. Please advise, asp.net relevant code for the same.
Upvotes: 1
Views: 704
Reputation: 1
To use the Razorpay IFSC API in ASP.NET 4.7, you’ll need to adjust your code slightly, as HttpClient handling in .NET Framework may differ from .NET Core. Try the following approach, which should work in ASP.NET 4.7:
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
public async Task<BankModel> GetBankDetailsByIFSC(string ifsc)
{
BankModel bank = null;
using (var httpClient = new HttpClient())
{
var response = await
httpClient.GetAsync($"https://ifsc.razorpay.com/{ifsc}");
if (response.IsSuccessStatusCode)
{
var apiResponse = await response.Content.ReadAsStringAsync();
bank = JsonConvert.DeserializeObject<BankModel>(apiResponse);
}
else
{
// Handle the error response here
throw new Exception("Error fetching bank details.");
}
}
return bank;
}
Explanation: Error Handling: In the above code, I added error handling for failed requests. This will help avoid issues when the IFSC code is invalid or if there’s an API issue. JSON Deserialization: Ensure that BankModel matches the structure of the API response for proper deserialization.
Anyway, for a practical example of how IFSC code lookups work with Razorpay’s API, you might find IFSCDetails helpful as it showcases similar functionality. This might give you some ideas on how to structure your data and handle responses for an IFSC-based lookup.
Let me know if you run into any other issues, or if you’d like guidance on specific parts of the ASP.NET 4.7 integration.
Upvotes: -1