how to use bank of India gateway for online payment, how to write code for for online payment and get response
in asp.net using ado.net. My Website is totaly developed C# dot net using using ado.net connection
how to use bank of India gateway for online payment, how to write code for for online payment and get response
in asp.net using ado.net. My Website is totaly developed C# dot net using using ado.net connection
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prasad RaveendranRank #320 · 7.8K reputationPosted Jul 9, 2024, 9:37 PM EDT
To integrate the Bank of India payment gateway for online payments in your ASP.NET application using ADO.NET, you will typically follow these steps:
Obtain API Details from Bank of India: Contact Bank of India to get the necessary API credentials (Merchant ID, API key, etc.) and documentation.
Set Up Your Project:
Create a Payment Request:
Redirect to the Payment Gateway:
Handle the Payment Response:
Sample Code
Here's a simplified example of how you might implement this:
Payment Initialization (Sending Request to Gateway):
protected void btnPay_Click(object sender, EventArgs e) { string merchantId = "YourMerchantId"; string apiKey = "YourApiKey"; string returnUrl = "https://yourwebsite.com/PaymentResponse"; string amount = "100.00"; // Example amount // Save transaction details in the database using ADO.NET using (SqlConnection con = new SqlConnection("your_connection_string")) { string query = "INSERT INTO Transactions (Amount, Status) OUTPUT INSERTED.ID VALUES (@Amount, @Status)"; using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.Parameters.AddWithValue("@Amount", amount); cmd.Parameters.AddWithValue("@Status", "Pending"); con.Open(); int transactionId = (int)cmd.ExecuteScalar(); con.Close(); // Prepare payment gateway parameters string transactionIdString = transactionId.ToString(); string hash = GenerateHash(merchantId, apiKey, amount, transactionIdString); // Redirect to payment gateway Response.Redirect($"https://bankofindia.com/pay?merchantId={merchantId}&transactionId={transactionIdString}&amount={amount}&returnUrl={returnUrl}&hash={hash}"); } } } private string GenerateHash(string merchantId, string apiKey, string amount, string transactionId) { // Implement hash generation logic based on Bank of India's documentation return "generated_hash"; }Handling the Payment Response:
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string transactionId = Request.Form["transactionId"]; string status = Request.Form["status"]; string hash = Request.Form["hash"]; // Verify the hash if (VerifyHash(transactionId, status, hash)) { // Update transaction status in the database using ADO.NET using (SqlConnection con = new SqlConnection("your_connection_string")) { string query = "UPDATE Transactions SET Status = @Status WHERE ID = @TransactionId"; using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.Parameters.AddWithValue("@Status", status); cmd.Parameters.AddWithValue("@TransactionId", transactionId); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } // Display success or failure message to the user if (status == "Success") { lblMessage.Text = "Payment successful!"; } else { lblMessage.Text = "Payment failed!"; } } else { lblMessage.Text = "Invalid response!"; } } } private bool VerifyHash(string transactionId, string status, string hash) { // Implement hash verification logic based on Bank of India's documentation return true; }Notes:
"your_connection_string"with your actual database connection string.GenerateHashandVerifyHashmethods based on the Bank of India’s API documentation.Make sure to follow the security guidelines and best practices recommended by Bank of India for handling payment data.