function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sflearningsflearning 

Convert Onclick javascript to Ligntning Action...Urgent!!!

Here is my javascript code...we are integrating salesforce with third party app thru callout...
 
{!RequireScript("/soap/ajax/11.1/connection.js")} 
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js')} 
var $jq = jQuery.noConflict(); 

function processPayment() { 



var amt = prompt('enter amount to authorize','{!Opportunity.Amount}');

if(amt != '' && amt != null){ 
amt = parseFloat(amt.replace(/.*\$/,'').replace(/[^.\d]/g,'')) 
}
if (isNaN(amt) == true) { 
alert('Please enter a numeric value for authorization amount'); 
return (false); 
}
 
var api = new t3(); 

var orequest = new loginrequest('gateway', 'userid', 'userPassword', 'application', 'version');  

var createtransaction = new authtransaction(); 
createtransaction['@refname'] = "auth"; 
createtransaction.account = "Jumpcrew-cc-test"; 
createtransaction.salesdocumentname = '{!Opportunity.Event_Code__c}'; 
createtransaction.amount = amt; 
createtransaction.transactiontype = "Authorization"; 
createtransaction.description = "Auth from Salesforce"; 
createtransaction.storedaccount = new storedcard('{!Opportunity.t_CC_StoredAccountID__c}'); 
createtransaction.customer = customercode; 

var ocreate = new create(createtransaction); 
orequest.setContent(ocreate); 
api.process(orequest, processSuccess, processFailure); 
} 

function authtransaction() { 
this['@refname'] = null; 
this.account = null; 
this.salesdocumentname = null; 
this.amount = null; 
this.transactiontype = null; 
this.description = null; 
this.authorizationcode = null; 
this.customer = null; 
this.contact = null; 
this.creditcard = null; 
this.storedaccount = null; 
} 

function processSuccess(data) { 
if (data.response.authentication['@responsestatus'] != 'success') { 
errorMessage(data.response.authentication.errors); 
return; 
} 
if (typeof data.response.content.create === 'object') { 
var createctr = data.response.content.create.length; 
if (createctr == undefined) { 
data.response.content.create[0] = data.response.content.create; 
createctr = 1; 
} 
for (var i = 0; i < createctr; i++) { 
var r = data.response.content.create[i]; 

if (typeof r.transaction === 'object') { 
if (r.transaction['@responsestatus'] == "success") { 
var opp = new sforce.SObject('Opportunity'); 
opp.id = '{!Opportunity.Id}'; 
opp.t_AuthID__c = r.transaction.authorizationcode; 
opp.t_Sequence_No__c = r.transaction.id; 
var result = sforce.connection.update([opp]); 
alert('Approved: ' + r.transaction.authorizationcode); 
window.location.reload(); 
} 
else { 
errorMessage(r.transaction.errors); 
} 
} 
} 
} 
} 
function errorMessage(errors) { 
if (typeof errors.error === "undefined") { 
var err = errors[0]; 
alert('Declined: ' + err.description + ' (' + err.number + ')'); 
} 
else if (errors.error.length == undefined) { 
var err = errors.error; 
alert('Declined: ' + err.description + ' (' + err.number + ')'); 
} 
else { 
var temp = 'Declined:\n'; 
for (var e = 0; e < errors.error.length; e++) { 
var err = errors.error[e]; 
temp = temp + err.description + ' (' + err.number + ')\n'; 
} 
alert(temp); 
} 
} 
function processFailure(data) { 
alert('Failure: ' + data); 
} 
function t3() { 
this.request = new request(); 
request.prototype = { 
setContent: function (obj, continueonfailure) { 
if (obj.length == undefined) { 
this.content = new singlefunction(obj, continueonfailure); 
} 
else { 
this.content = new multifunctions(obj, continueonfailure); 
} 
} 
} 
loginrequest.prototype = { 
setContent: function (obj) { 
if (obj.length == undefined) { 
this.content = new singlefunction(obj); 
} 
else { 
this.content = new multifunctions(obj); 
} 
} 
} 
} 
function multifunctions(obj, continueonfailure) { 
if (typeof continueonfailure !== 'undefined') { 
this['@continueonfailure'] = continueonfailure; 
} 
var readctr = 0; 
var createctr = 0; 
var updatectr = 0; 
var removectr = 0; 
var ifctr = 0; 
for (var i = 0; i < obj.length; i++) { 
if (obj[i] instanceof read) { 
readctr = readctr + 1; 
if (readctr == 1) { 
this.read = obj[i]; 
} 
else { 
if (readctr == 2) { 
var tmp = this.read; 
this.read = []; 
this.read[0] = tmp; 
} 
this.read[readctr - 1] = obj[i]; 
} 
} 
else if (obj[i] instanceof create) { 
createctr = createctr + 1; 
if (createctr == 1) { 
this.create = obj[i]; 
} 
else { 
if (createctr == 2) { 
var tmp = this.create; 
this.create = []; 
this.create[0] = tmp; 
} 
this.create[createctr - 1] = obj[i]; 
} 
} 
else if (obj[i] instanceof update) { 
updatectr = updatectr + 1; 
if (updatectr == 1) { 
this.update = obj[i]; 
} 
else { 
if (updatectr == 2) { 
var tmp = this.update; 
this.update = []; 
this.update[0] = tmp; 
} 
this.update[updatectr - 1] = obj[i]; 
} 
} 
else if (obj[i] instanceof remove) { 
removectr = removectr + 1; 
if (removectr == 1) { 
this.remove = obj[i]; 
} 
else { 
if (removectr == 2) { 
var tmp = this.remove; 
this.remove = []; 
this.remove[0] = tmp; 
} 
this.remove[removectr - 1] = obj[i]; 
} 
} 
else if (obj[i] instanceof _if) { 
ifctr = ifctr + 1; 
if (ifctr == 1) { 
this.if = obj[i]; 
} 
else { 
if (ifctr == 2) { 
var tmp = this.if; 
this.if = []; 
this.if[0] = tmp; 
} 
this.if[ifctr - 1] = obj[i]; 
} 
} 
} 
} 
function singlefunction(obj, continueonfailure) { 
if (typeof continueonfailure !== 'undefined') { 
this['@continueonfailure'] = continueonfailure; 
} 
if (obj instanceof create) { 
this.create = obj; 
} 
else if (obj instanceof read) { 
this.read = obj; 
} 
else if (obj instanceof update) { 
this.update = obj; 
} 
else if (obj instanceof remove) { 
this.remove = obj; 
} 
else if (obj instanceof _if) { 
this.if = obj; 
} 
} 

t3.prototype = { 
process: function (req, onsuccess, onfailure) { 
if (request.prototype.setContent != undefined) 
delete request.prototype.setContent; 
if (loginrequest.prototype.setContent != undefined) 
delete loginrequest.prototype.setContent; 
if (req.content != undefined && req.content != 'undefined') { 
for (var key in req.content) { 
if (key != undefined && key != 'if' && key != '@continueonfailure') { 
if (req.content.hasOwnProperty(key)) { 
var f = req.content[key]; // function 
if (f.length == undefined) { 
if (f instanceof read) { 
} 
else { 
for (var k in f) { 
if (key != undefined) { 
if (f.hasOwnProperty(k)) { 
var o = f[k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
else { 
for (i = 0; i < f.length; i++) { 
if (f[i] instanceof read) { 
} 
else { 
for (var k in f[i]) { 
if (key != undefined) { 
if (f[i].hasOwnProperty(k)) { 
var o = f[i][k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
} 
} 
} 
} 
} 

$jq.support.cors = true; 
var apidata = new api(req); 
$jq.ajax({ 
type: 'post', 
cache: false, 
dataType: "json", 
url: 'https://api.t3.com/json', 
data: apidata 
}).done(function (data) { 
if ((data.response.authentication != undefined) && (data.response.authentication["@responsestatus"] != "success") && (data.response.authentication.errors.length == undefined)) { 
var temp = data.response.authentication.errors.error; 
data.response.authentication.errors = []; 
data.response.authentication.errors[0] = temp; 
} 
onsuccess(data); 
}).error(function (jqXHR, textStatus, errorThrown) { 
onfailure(jqXHR.responseText || jqXHR.statusText || textStatus); 
}); 
}, 
processFromIntacct: function (req, onsuccess, onfailure, pagename, isasync) { 
if (request.prototype.setContent != undefined) 
delete request.prototype.setContent; 
if (loginrequest.prototype.setContent != undefined) 
delete loginrequest.prototype.setContent; 
if (req.content != undefined && req.content != 'undefined') { 
for (var key in req.content) { 
if (key != undefined && key != 'if' && key != '@continueonfailure') { 
if (req.content.hasOwnProperty(key)) { 
var f = req.content[key]; // function 
if (f.length == undefined) { 
if (f instanceof read) { 
} 
else { 
for (var k in f) { 
if (key != undefined) { 
if (f.hasOwnProperty(k)) { 
var o = f[k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
else { 
for (i = 0; i < f.length; i++) { 
if (f[i] instanceof read) { 
} 
else { 
for (var k in f[i]) { 
if (key != undefined) { 
if (f[i].hasOwnProperty(k)) { 
var o = f[i][k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
} 
} 
} 
else if (key == 'if') { 
if (req.content.hasOwnProperty(key)) { 
var f = req.content[key]; // function 
preparenestedif(f); 
} 
} 
} 
} 
jq.support.cors = true; 
var apidata = new api(req); 
pagename = (typeof pagename === "undefined") ? '' : pagename; 
isasync = (typeof isasync === "undefined") ? true : isasync; 
jq.ajax({ 
type: 'post', 
cache: false, 
async: isasync, 
dataType: "json", 
url: 'https://api.t3.com/json', 
data: apidata 
}).done(function (data) { 
if (data.response.authentication != undefined) { 
if ((data.response.authentication["@responsestatus"] != "success") && (data.response.authentication.errors.length == undefined)) { 
var temp = data.response.authentication.errors.error; 
data.response.authentication.errors = []; 
data.response.authentication.errors[0] = temp; 
} 
} 
onsuccess(data, pagename); 
}).error(function (jqXHR, textStatus, errorThrown) { 
if (pagename == 'sso' || pagename == 'login') { 
alert('error single sign on'); 
} 
onfailure(jqXHR.responseText || jqXHR.statusText || textStatus); 
}); 
} 
} 
function getjsonstring(req) { 
if (request.prototype.setContent != undefined) 
delete request.prototype.setContent; 
if (loginrequest.prototype.setContent != undefined) 
delete loginrequest.prototype.setContent; 
if (req.content != undefined && req.content != 'undefined') { 
for (var key in req.content) { 
if (key != undefined) { 
if (req.content.hasOwnProperty(key)) { 
var f = req.content[key]; // function 
if (f.length == undefined) { 
if (f instanceof read) { 
} 
else { 
for (var k in f) { 
if (key != undefined) { 
if (f.hasOwnProperty(k)) { 
var o = f[k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
else { 
for (i = 0; i < f.length; i++) { 
if (f[i] instanceof read) { 
} 
else { 
for (var k in f[i]) { 
if (key != undefined) { 
if (f[i].hasOwnProperty(k)) { 
var o = f[i][k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
} 
} 
} 
} 
} 
var apidata = JSON.stringify(new api(req)); 
return apidata; 
} 
function preparenestedif(obj) { 
if (obj.length != undefined) { 
for (o = 0; o < obj.length; o++) { 
preparesingleif(obj[o]); 
} 
} 
else { 
preparesingleif(obj); 
} 
} 
function preparesingleif(obj) { 
for (var key in obj) { 
if (key != undefined) { 
if (key != '@condition') { 
if (obj.hasOwnProperty(key)) { 
var f = obj[key]; // function 
if (f.length == undefined) { 
if (f instanceof read) { 
} 
else { 
for (var k in f) { 
if (key != undefined) { 
if (f.hasOwnProperty(k)) { 
var o = f[k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
else { 
for (i = 0; i < f.length; i++) { 
if (f[i] instanceof read) { 
} 
else { 
for (var k in f[i]) { 
if (key != undefined) { 
if (f[i].hasOwnProperty(k)) { 
var o = f[i][k]; // object 
o.prepare(); 
} 
} 
} 
} 
} 
} 
} 
} 
} 
} 
} 
function encoderequest(request) { 
return encodeURIComponent(request); 
} 
function decoderesponse(response) { 
return decodeURIComponent((response + '').replace(/\+/g, '%20')); 
} 
function msieversion() { 
var ua = window.navigator.userAgent; 
var msie = ua.indexOf("MSIE "); 
var ret = 0; 
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { ret = 1; } 
return ret; 
} 
function api(req) { 
if (req instanceof request) { 
this.request = new request(); 
} 
else if (req instanceof loginrequest) { 
this.request = new loginrequest(); 
} 
this.request = req; 
} 
function request(t_session_id) { 
this.authentication = new authentication(); 
this.authentication.sessionid = t_session_id; 
this.content = undefined; 
} 

function loginrequest(gateway, emailaddress, userpassword, application, version) { 
this.authentication = new userloginauthentication(); 
this.authentication.user.gateway = gateway; 
this.authentication.user.emailaddress = emailaddress; 
this.authentication.user.password = userpassword; 
this.authentication.user.application = application; 
this.authentication.user.version = version; 
this.content = undefined; 
} 
 
function sessionauthenthicationrequest(tsessionid) { 
this.authentication = new authentication(); 
this.authentication.sessionid = tsessionid; 
} 
function authentication() { 
this.sessionid = ''; 
} 
function intacctauthenticationrequest(intacctsessionid, application, version, entity) { 
this.authentication = new intacctauthentication(); 
this.authentication.intacct.sessionid = intacctsessionid; 
this.authentication.intacct.application = application; 
this.authentication.intacct.version = version; 
this.authentication.intacct.entity = entity; 
this.content = undefined; 
} 
function intacctauthentication() { 
this.intacct = new intacct(); 
function intacct() { 
this.sessionid = ''; 
this.application = ''; 
this.version = ''; 
this.entity = ''; 
} 
} 
function intacctlogin(intacctsessionid, intacctemailaddress, intacctpassword, application, version, entity) { 
this.authentication = new intacctuserloginauthentication(); 
this.authentication.intacct.sessionid = intacctsessionid; 
this.authentication.intacct.emailaddress = intacctemailaddress; 
this.authentication.intacct.password = intacctpassword; 
this.authentication.intacct.application = application; 
this.authentication.intacct.version = version; 
this.authentication.intacct.entity = entity; 
this.content = undefined; 
} 
function intacctuserloginauthentication() { 
this.intacct = new intacct(); 
function intacct() { 
this.sessionid = ''; 
this.emailaddress = ''; 
this.password = ''; 
this.application = ''; 
this.version = ''; 
this.entity = ''; 
} 
} 
function senderauthentication() { 
this.sessionid = ""; 
} 
function userauthentication() { 
this.sessionid = ""; 
} 
function read(object, fields, query, orderby, refname, nestobj) { 
this['@object'] = object; 
this['@fields'] = fields; 
if (typeof query !== 'undefined') this['@query'] = query; 
if (typeof orderby !== 'undefined') this['@orderby'] = orderby; 
if (typeof refname !== 'undefined') this['@refname'] = refname; 
if (typeof nestobj !== 'undefined') { 
var readctr = 0; 
var createctr = 0; 
var updatectr = 0; 
var removectr = 0; 
if (nestobj.length == undefined) { 
var nestobjtemp = nestobj; nestobj = []; nestobj[0] = nestobjtemp; 
} 
for (var i = 0; i < nestobj.length; i++) { 
if (nestobj[i] instanceof read) { 
readctr = readctr + 1; 
if (readctr == 1) { 
this.read = nestobj[i]; 
} 
else { 
if (readctr == 2) { 
var tmp = this.read; 
this.read = []; 
this.read[0] = tmp; 
} 
this.read[readctr - 1] = nestobj[i]; 
} 
} 
else if (nestobj[i] instanceof create) { 
createctr = createctr + 1; 
if (createctr == 1) { 
this.create = nestobj[i]; 
} 
else { 
if (createctr == 2) { 
var tmp = this.create; 
this.create = []; 
this.create[0] = tmp; 
} 
this.create[createctr - 1] = nestobj[i]; 
} 
} 
else if (nestobj[i] instanceof update) { 
updatectr = updatectr + 1; 
if (updatectr == 1) { 
this.update = nestobj[i]; 
} 
else { 
if (updatectr == 2) { 
var tmp = this.update; 
this.update = []; 
this.update[0] = tmp; 
} 
this.update[updatectr - 1] = nestobj[i]; 
} 
} 
else if (nestobj[i] instanceof remove) { 
removectr = removectr + 1; 
if (removectr == 1) { 
this.remove = nestobj[i]; 
} 
else { 
if (removectr == 2) { 
var tmp = this.remove; 
this.remove = []; 
this.remove[0] = tmp; 
} 
this.remove[removectr - 1] = nestobj[i]; 
} 
} 
} 
} 
} 

function usergroup(name, id) { 
this.id = id; 
this.name = name; 
} 



processPayment();