, , ,

How to integrate to IPAY88 payment gateway from the asp.net MVC web application?

Posted by

Integrating with the IPAY88 payment gateway in an ASP.NET MVC web application involves several steps. Here’s a high-level overview of the integration process:

  1. Sign up and obtain credentials:
  • Visit the IPAY88 website (https://www.ipay88.com/) and sign up for a merchant account.
  • Once your account is approved, you will receive the necessary credentials, such as Merchant Code, Merchant Key, and Response URL.
  1. Add references and libraries:
  • Download the IPAY88 SDK or library provided by IPAY88.
  • Add the required references and dependencies to your ASP.NET MVC project.
  1. Set up payment form:
  • Create a payment form in your ASP.NET MVC view, including the necessary fields for capturing payment details.
  • Configure the form to submit the data to the IPAY88 payment gateway.
  1. Handle the response:
  • Set up an endpoint or action method in your ASP.NET MVC controller to handle the response from the IPAY88 payment gateway.
  • Process the response data, such as verifying the payment status, updating your application’s database, and displaying a confirmation page to the user.
  1. Test and deploy:
  • Test the payment integration thoroughly, including different payment scenarios and error handling.
  • Once you are satisfied with the testing, deploy your ASP.NET MVC application to your production environment.

It’s important to consult the IPAY88 documentation and developer resources for detailed instructions specific to their payment gateway integration. They may provide sample code, documentation, and guidance on implementing various features like generating checksums, handling callbacks, and more.

Please note that the specific implementation details may vary based on the version of the IPAY88 SDK or library you are using and any specific requirements or features you want to implement in your application.

Sample Code in MVC

Integrating with the IPAY88 payment gateway in C# involves several steps, including generating checksums, setting up the payment form, and handling the response. Here’s an example code snippet to give you an idea of how the integration can be implemented:

using System;
using System.Security.Cryptography;
using System.Text;
using System.Web.Mvc;

public class Ipay88Controller : Controller
    private const string MerchantCode = "your-merchant-code";
    private const string MerchantKey = "your-merchant-key";

    public ActionResult ProcessPayment()
        // Generate payment parameters
        var paymentParams = new
            MerchantCode = MerchantCode,
            PaymentId = "your-payment-id",
            RefNo = "your-order-reference-number",
            Amount = "your-amount",
            Currency = "MYR",
            ProdDesc = "your-product-description",
            UserName = "user-name",
            UserEmail = "user-email",
            ResponseUrl = "your-response-url",
            BackendUrl = "your-backend-url",
            Remark = "additional-remarks",
            Lang = "UTF-8",
            Signature = GenerateSignature("your-order-reference-number", "your-amount")

        // Build the payment form
        var formBuilder = new StringBuilder();
        formBuilder.Append("<form method='post' action='https://www.mobile88.com/epayment/entry.asp'>");
        foreach (var property in paymentParams.GetType().GetProperties())
            formBuilder.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", property.Name, property.GetValue(paymentParams));
        formBuilder.Append("<input type='submit' value='Proceed to Payment' />");

        // Render the payment form
        return Content(formBuilder.ToString(), "text/html");

    public ActionResult HandleResponse()
        // Handle the response from IPAY88
        string refNo = Request.Form["RefNo"];
        string amount = Request.Form["Amount"];
        string currency = Request.Form["Currency"];
        string resultCode = Request.Form["ResultCode"];
        string signature = Request.Form["Signature"];

        // Verify the signature
        bool isValidSignature = VerifySignature(refNo, amount, currency, resultCode, signature);

        // Process the payment response
        if (isValidSignature && resultCode == "00")
            // Payment successful
            // Process your logic and update the order status
            return Content("Payment Successful");
            // Payment failed or tampered response
            // Handle the failure or tampered response accordingly
            return Content("Payment Failed");

    private string GenerateSignature(string refNo, string amount)
        // Generate a checksum based on your merchant key and payment parameters
        string signatureString = MerchantKey + MerchantCode + refNo + amount;
        byte[] signatureBytes = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(signatureString));
        string signature = BitConverter.ToString(signatureBytes).Replace("-", string.Empty).ToLower();
        return signature;

    private bool VerifySignature(string refNo, string amount, string currency, string resultCode, string signature)
        // Generate the expected signature and compare with the received signature
        string expectedSignature = GenerateSignature(refNo, amount);
        return string.Equals(signature, expectedSignature, StringComparison.OrdinalIgnoreCase);

In the above code, the ProcessPayment action method generates the payment parameters required by IPAY88, including the merchant code, payment ID, order reference number, amount, and other details. It also generates a signature using the GenerateSignature method, which computes a checksum based on the merchant key and payment parameters.

The payment form is built dynamically using a StringBuilder and includes hidden input fields for each payment parameter. The form is then submitted to the IPAY88 payment gateway URL.

The HandleResponse action method handles the response from IPAY88. It retrieves the relevant parameters from the request form, including the order reference number, amount, currency, result code, and signature. It verifies the signature using the VerifySignature method and processes the payment response accordingly.

Please note that this is a simplified example, and you may need to adjust the code based on your specific requirements and the IPAY88 integration documentation. The example assumes you have an ASP.NET MVC controller named Ipay88Controller and routes set up accordingly.

Make sure to replace the placeholder values like your-merchant-code, your-merchant-key, your-payment-id, your-order-reference-number, your-amount, your-product-description, user-name, user-email, your-response-url, and your-backend-url with your actual values.

Remember to refer to the IPAY88 documentation and developer resources for the specific requirements and implementation details of their payment gateway integration.