5 HostedPay.js
// direct the payment request with PAN data to the target PaywayWS server
function HostedPaymentClicked ()
{
console.log ( "HostedPaymentClicked" ) ;
// java script htpp request object.
var request = new XMLHttpRequest() ;
// values for the request come from the jsp page.
try
{
// Set up the json request
var requestjson =
{
accountInputMode : "primaryAccountNumber",
paywayRequestToken : document.getElementById('paywayRequestToken').value,
transactionName : document.getElementById('transactionName').value,
transactionSourceId : document.getElementById('transactionSourceId').value,
request : "sendQueuedTransaction",
cardAccount :
{
accountNumber : document.getElementById ( 'accountNumber' ).value,
expirationDate : document.getElementById ( 'expirationDate' ).value,
firstName : document.getElementById('first').value,
lastName : document.getElementById('last').value,
address : document.getElementById('address').value,
city : document.getElementById('city').value,
state : document.getElementById('state').value,
zip : document.getElementById('zip').value,
email : document.getElementById('email').value,
phone : document.getElementById('phone').value,
accountNotes1: "notes1",
accountNotes2: "notes2",
accountNotes3: "notes3"
}
} ;
console.log ( JSON.stringify ( requestjson ) ) ;
console.log ( document.getElementById('serviceLocation' ).value ) ;
// send the request to PaywayWS
request.open('POST', document.getElementById('serviceLocation').value + '/PaywayWS/Payment/CreditCard', true ) ;
request.setRequestHeader("Content-type", "application/json");
request.send( JSON.stringify ( requestjson ) ) ;
}
catch ( err )
{
alert ( err.message ) ;
console.log ( err.message ) ;
}
request.onload = function()
{
try
{
// Check the results of the request using request.responseText. Here
// we just forward it to a results page which prints out the returned JSON object.
// debugging
console.log ( request.responseText ) ;
// set the response in the current document and submit to sample confirmation page
document.getElementById('results').value = request.responseText ;
document.getElementById("ResultsTransaction").submit() ;
}
catch ( err )
{
// error processing, here just log to the console
console.log ( "Submit page error: " + err ) ;
}
} ;
request.onerror = function()
{
console.log ( "Payment error: " + request.responseText ) ;
};
}