Showing results for 
Search instead for 
Did you mean: 

implement getHostedpaymentPageRequest in Javascript

I need to call  getHostedpaymentPageRequest and generate a token using javascript with in HTML. I am using provided code to display the form. But i need to generate token and pass the token information to my payment page. there is no example of javascript code on their webiste to generate the token.

Here is my code:

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>HostedPayment Test Page</title>

<script src="scripts/lib/jquery.min.js"></script>
<script type="text/javascript">

$(function () {

$("#btnOpenAuthorizeNetIFrame").click(function () {
$("#send_token").attr({ "action": "", "target": "add_payment" }).submit();




Open in an iframe to complete transaction
<button id="btnOpenAuthorizeNetIFrame" onclick="">Show Payment Form</button>
<div id="iframe_holder" class="center-block" style="width:90%;max-width: 1000px;height:90%max-height: 1000px">
<iframe id="add_payment" class="embed-responsive-item panel" name="add_payment" width="100%" height="1000" frameborder="0" scrolling="yes" hidden="false">
<form id="send_token" action="" method="post" target="add_payment" >
<input type="hidden" name="token" value="TOKEN VALUE" />


<script type="text/javascript">

(function () {
if (!window.AuthorizeNetIFrame) window.AuthorizeNetIFrame = {};
AuthorizeNetIFrame.onReceiveCommunication = function (querystr) {
var params = parseQueryString(querystr);
switch (params["action"]) {
case "successfulSave":
case "cancel":
case "resizeWindow":
var w = parseInt(params["100%"]);
var h = parseInt(params["100%"]);
var ifrm = document.getElementById("add_payment"); = w.toString() + "px"; = h.toString() + "px";
case "transactResponse":
var ifrm = document.getElementById("add_payment"); = 'none';

function parseQueryString(str) {
var vars = [];
var arr = str.split('&');
var pair;
for (var i = 0; i < arr.length; i++) {
pair = arr[i].split('=');
vars[pair[0]] = unescape(pair[1]);
return vars;



Please help I need to generate token using javascript. 


@furqanmajeed007 to get the token you don't use client side JS. You use node.js. 

All Star

The problem with doing this client-side isn't a technical issue but a security issue.   You'd be initiating requests from the client's ip address and running it on the client's browser and having to expose your credentials to do so.  So it seems like a bad idea.

But there's probably nothing stopping you from doing this client-side.

You can find code examples here: