jQuery addClass example
Change class name on click in jQuery
by atomicfalls
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<div id="result">
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#result {
background: #fff;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 100%;
}
JavaScript
let time = moment().unix();
let url = "https://dev-secure.rocketgate.com/hostedpage/servlet/HostedPagePurchase?";
let hashArgs ="id=1234&merch=1556720801&amount=3.0";
let urlArgs = encodeURIComponent("id")+ "=" +encodeURIComponent("1234")+"&"+
encodeURIComponent("merch")+ "=" +encodeURIComponent("1556720801")+ "&"+
encodeURIComponent("amount")+ "=" +encodeURIComponent("3.0")+ "&"+
encodeURIComponent("time") + "=" +encodeURIComponent(time);
let sharedSecret = "&secret=sharedSecret";
// create hmac using secret key
let hash = CryptoJS.HmacSHA1(hashArgs+sharedSecret, "sharedSecret");
let hashInBase64 = window.btoa(hash);
// URI encode basse64 encoded hash
let computedHash = encodeURIComponent(hashInBase64);
// combine all elements to create RocketGate URL
let fullURL = url + urlArgs + "&hash=" + computedHash;
$( "div#result" ).html( "<p>"+fullURL+"</p>" );