
Editorial illustration.
Originally published 23 June 2023; rewritten and reviewed on 15 October 2026.
A legacy checkout can sit quietly in production for years, processing RM50 or RM500 orders without complaint, until a merchant account changes hands, an API key rotates, or a framework upgrade forces you to open the controller again. When revisiting the MOLPay example from my earlier post, the mistake I see most often is developers copying an old hash snippet from a 2016 blog post without checking what contract the merchant account actually runs on today.
MOLPay itself went through rebranding to Razer Merchant Services (RMS) and later Fiuu. Depending on when the merchant onboarded, their account might be using an older hosted payment page flow, a newer REST-style endpoint, or specific signature algorithms. Before writing a single line of C#, verify the exact integration guide tied to that live Merchant ID.
Verify the merchant contract before touching code
Confirm the current merchant identifier, enabled payment channels (FPX, cards, DuitNow QR, or e-wallets like Touch 'n Go eWallet and GrabPay), and the exact hashing specification in the merchant portal. Never assume that a legacy MD5 vcode / skey formula from an archived sample matches a newly provisioned account, as newer endpoints may use SHA-256 or HMAC-SHA256 with different field ordering.
Keep sandbox and production credentials strictly separated in server-side configuration. In an ASP.NET MVC application, store them in Web.config (transformed per environment or injected via deployment secrets) rather than hardcoding them in a controller or passing a verify key into a Razor view:
<appSettings>
<add key="Gateway:MerchantId" value="YOUR_MERCHANT_ID" />
<add key="Gateway:VerifyKey" value="STORE_IN_DEPLOYMENT_SECRETS" />
<add key="Gateway:SecretKey" value="STORE_IN_DEPLOYMENT_SECRETS" />
<add key="Gateway:CheckoutUrl" value="https://sandbox.merchant.razer.com/RMS/pay/" />
</appSettings>
If anything in the vendor documentation is ambiguous—such as character encoding on product descriptions, decimal formatting (120.00 vs 120), or whether the callback expects a specific plain-text acknowledgement token—ask the gateway’s technical support to confirm it against your Merchant ID before going live.
Keep totals, currency, and order identity on the server
Create the local order record in your database before redirecting the customer to the gateway. Calculate the payable amount from your own product catalogue, shipping rules, and tax logic on the server, and persist it with a Pending status and a unique merchant order reference.
Never trust hidden <input> fields posted back from the browser as proof of what the customer owes or paid. Even when using a hosted payment page that submits form fields via POST, those values are only for initiating the session; the server must still validate every callback against the stored order record.
Prepare local order (Status = Pending, Amount = RM 149.00, Currency = MYR)
→ Compute request signature on the server using protected credentials
→ Redirect customer to the gateway's hosted checkout
→ Receive browser return AND/OR server-to-server callback
→ Verify response signature against the stored VerifyKey / SecretKey
→ Confirm orderid, amount, currency, and status == "00" (success)
→ Transition order to Paid once inside a guarded database transaction
In ASP.NET MVC, your callback action ([HttpPost] and [AllowAnonymous], since the gateway posts directly without a user session cookie) should verify the incoming signature first, then check both orderid and amount against your database:
[HttpPost]
[AllowAnonymous]
public ActionResult PaymentCallback(FormCollection form)
{
var tranId = form["tranID"];
var orderId = form["orderid"];
var status = form["status"];
var amount = form["amount"];
var currency = form["currency"];
var receivedSkey = form["skey"];
if (!IsValidGatewaySignature(form, receivedSkey))
{
return new HttpStatusCodeResult(400, "Invalid signature");
}
var order = _orderRepo.GetByReference(orderId);
if (order == null)
{
return HttpNotFound();
}
if (!decimal.TryParse(amount, NumberStyles.Number, CultureInfo.InvariantCulture, out var paidAmount)
|| paidAmount != order.TotalAmount
|| !string.Equals(currency, order.Currency, StringComparison.OrdinalIgnoreCase))
{
_logger.Warn($"Amount/currency mismatch for order {orderId}");
return new HttpStatusCodeResult(400, "Order mismatch");
}
if (status == "00" && order.Status != OrderStatus.Paid)
{
_orderRepo.MarkAsPaid(order.Id, tranId, DateTime.UtcNow);
}
// Legacy RMS/MOLPay callbacks expect an explicit acknowledgement token
return Content("CBTOKEN:MPSTATOK", "text/plain");
}
Remember to check the exact field list and order required by your account’s skey specification when implementing IsValidGatewaySignature—some versions hash tranID + orderid + status + domain + amount + currency first and then hash that result with paydate + domain + key0 + appcode + verifyKey.
Make interrupted checkouts and duplicate callbacks recoverable
In real Malaysian e-commerce traffic, FPX payments are notorious for interrupted browser journeys. A customer approves the transaction on Maybank2u or CIMB Clicks, sees the bank confirmation screen, and immediately closes the browser tab before the redirect ever reaches your ReturnUrl. Meanwhile, the gateway’s background callback might arrive seconds later, or retry three times if your server took too long to respond.
If your fulfilment logic lives only on the browser return page, that customer paid and got no order confirmation. If your callback handler isn’t idempotent, three retries will send three confirmation emails or deduct stock three times.
Build both paths to converge on the same guarded state transition:
- Browser return URL: Re-verify the payload if present, read the current order status from your database, and display the result. If the order is still
Pendingbecause the callback hasn’t landed yet, show a clear “Confirming payment” state or poll a lightweight status endpoint rather than assuming failure. - Server callback URL: Handle retries safely by checking
order.Status != OrderStatus.Paidinside a database transaction or atomic update before triggering emails, invoices, or inventory changes. - Reconciliation job: Keep a scheduled background check (or manual admin “Sync Status” button) that queries the gateway’s transaction status API for orders stuck in
Pendingfor more than 15 minutes. That way, even if both the browser return and the webhook were dropped during a brief network blip, your operations team can resolve the payment cleanly without asking the customer to pay twice.