Secure QR Payload (TypeScript)

An example of generating a Secure QR Payload signature and building the QR URL in TypeScript (Node.js / server-side only).

import { createHmac } from "crypto";

function generateSignature(key: string, amount: number, id: string): string {
  const message = `${key}||${Math.trunc(amount)}||${id}`;
  return createHmac("sha256", key).update(message, "utf8").digest("hex");
}

const key       = "my-validation-key";
const id        = "ORDER-001";
const amount    = 10050;
const snapcode  = "mymerchant";

const signature = generateSignature(key, amount, id);
const qrUrl     = `https://pos.snapscan.io/qr/${snapcode}?id=${id}&amount=${amount}&signature=${signature}`;