1
Answer

Payment Gateway

Asht T

Asht T

Jul 09
448
1

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

Answers (1)
2
Prasad Raveendran

Prasad Raveendran

225 8.3k 1.9m Jul 10

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:

  1. Obtain API Details from Bank of India: Contact Bank of India to get the necessary API credentials (Merchant ID, API key, etc.) and documentation.

  2. Set Up Your Project:

    • Ensure you have the necessary references in your ASP.NET project.
    • Create necessary web forms or Razor pages for initiating and receiving payment responses.
  3. Create a Payment Request:

    • Use ADO.NET to store transaction details in your database before redirecting to the payment gateway.
  4. Redirect to the Payment Gateway:

    • Build an HTML form with the required parameters and post it to the Bank of India gateway URL.
  5. Handle the Payment Response:

    • Create an endpoint to handle the response from the payment gateway.
    • Update your database with the transaction status using ADO.NET.

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:

  • Replace "your_connection_string" with your actual database connection string.
  • Implement the GenerateHash and VerifyHash methods based on the Bank of India’s API documentation.
  • Handle exceptions and edge cases appropriately.
  • Ensure to test the integration thoroughly in a sandbox environment before going live.

Make sure to follow the security guidelines and best practices recommended by Bank of India for handling payment data.