Integrating iPay88 with ASP.NET MVC Around Verified Transactions

Editorial illustration.

Originally published 23 June 2023; rewritten and reviewed on 15 October 2026.

A payment gateway introduces two separate conversations: the customer’s browser journey and the server-to-server conversation about money. They rarely finish at the exact same moment. In Malaysia, a customer paying via FPX on Maybank2u or CIMB Clicks might approve the transfer on their phone, see the bank confirmation, and immediately close the browser tab before the redirect back to your site even finishes. If your ASP.NET MVC app only marks orders as paid on the return URL, you will spend every Monday morning reconciling “missing” payments against the merchant portal.

The fix is to design your local order state so either conversation can drop or arrive twice without inventing a fake payment or double-fulfilling an order.

Work from the merchant specification

Start with the exact iPay88 integration specification issued for your merchant account, payment product, and environment. Do not copy a hash formula from a ten-year-old blog post and assume it matches your account. Older iPay88 integrations used SHA-1 with Base64 encoding, while newer specs use SHA-256 or HMAC-SHA512 with specific field ordering.

Double-check the exact rules for:

  • Amount formatting: iPay88 expects Amount with two decimal places (for example, 125.50 for RM125.50), while the signature string typically strips the decimal point and commas (12550). Verify your merchant doc’s exact string concatenation order.
  • Currency and PaymentId: MYR for Ringgit Malaysia, and optional PaymentId values if you want to pre-select FPX, cards, or e-wallets instead of showing iPay88’s default method selector.
  • Secret handling: Never put MerchantKey in JavaScript, hidden HTML inputs, or client-side Razor models. Compute the request signature on the server right before rendering the auto-submitting form to iPay88’s endpoint.

Here is the general pattern for computing a signature server-side in C# (adapt the exact hash algorithm and field order to your assigned iPay88 spec):

public static string ComputeSignature(string merchantKey, string merchantCode, string refNo, decimal amount, string currency)
{
    var formattedAmount = amount.ToString("0.00", CultureInfo.InvariantCulture)
                                .Replace(".", string.Empty)
                                .Replace(",", string.Empty);

    var raw = $"{merchantKey}{merchantCode}{refNo}{formattedAmount}{currency}";
    using var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(merchantKey));
    var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(raw));
    return BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();
}

Give the order a stable reference

Before redirecting the customer away, persist the order in your database with a unique RefNo, the authoritative Amount and Currency calculated on the server, and an initial status of Pending. Never trust an order total posted back from a hidden form field on checkout.

When iPay88 sends the server-to-server notification to your BackendURL, treat it as untrusted input until your handler verifies four things in order:

  1. Signature authenticity: Recompute the response signature using your stored MerchantKey, the expected MerchantCode, PaymentId, RefNo, your local expected Amount (or verified amount), Currency, and Status, then compare using a constant-time check.
  2. Order and merchant match: Confirm RefNo exists in your database and MerchantCode matches your configured account.
  3. Amount and status: Verify Status == "1", Currency == "MYR", and the paid amount matches the order’s stored total.
  4. Idempotency: If the order is already Paid, do not send a second confirmation email, deduct stock twice, or issue a second invoice. Simply return the acknowledgment iPay88 expects (RECEIVEOK as plain text) so it stops retrying.

Meanwhile, your browser ResponseURL should simply read the order’s current database status—or show a clear “Payment pending confirmation” message if BackendURL has not arrived yet—rather than blindly flipping the order to Paid.

Exercise operational failures

Before going live, test the messy scenarios that actually happen in production:

  • Cancelled or timed-out FPX session: Confirm the order stays Pending or moves to Failed/Cancelled cleanly, and the customer can retry without generating conflicting RefNo collisions.
  • Duplicate BackendURL callbacks: Replay the same callback twice against staging and verify stock and email triggers only fire once.
  • WAF or Cloudflare interference: If your site sits behind Cloudflare, check that Bot Fight Mode or WAF rules do not challenge or block iPay88’s BackendURL POST requests. A 403 on BackendURL is one of the most common reasons live callbacks silently fail.
  • Safe logging: Log RefNo, TransId, Status, ErrDesc, and TraceId for support reconciliation, but never log MerchantKey or full card metadata.

A solid payment integration keeps the customer’s screen simple—paid, pending, cancelled, or failed—backed by state your server actually verified.