Helena
07/23/2020, 8:55 PMbattk
07/23/2020, 8:57 PMHelena
07/23/2020, 9:02 PMif ( request.getMethod() == 'POST' ){
var getRequestXML = nlapiStringToXML(getRequest);
if (getRequestXML != null){
var sharedsecretFromXML = nlapiSelectValue(getRequestXML, '//SharedSecret');
var sharedsecret = nlapiGetContext().getSetting('SCRIPT', 'custscript_punchout_shared_secret');
var buyerCookie = nlapiSelectValue(getRequestXML, '//BuyerCookie');
var webstoreURL = nlapiGetContext().getSetting('SCRIPT', 'custscript_punchout_webstore_url'); // to get the parameter "Punchout Webstore Url"
nlapiLogExecution('debug', 'webstoreURL', webstoreURL);
// <https://forms.na3.netsuite.com/app/site/hosting/scriptlet.nl?script=16&deploy=1&compid=123456&h=4e7fc4ae254bb12779addd>
// SHOULD BE: <https://123456.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=16&deploy=1&compid=123456&h=4e7fc4ae254bb12779ad>
var punchoutURL = nlapiSelectValue(getRequestXML, '//BrowserFormPost/URL');
nlapiLogExecution('debug', 'punchoutURL', punchoutURL);
if (sharedsecretFromXML == sharedsecret){
if (buyerCookie != null){
webstoreURL = nlapiEscapeXML(webstoreURL + '&session=' + buyerCookie);
nlapiLogExecution('debug', 'webstoreURL with cookie', webstoreURL);
//<https://forms.na3.netsuite.com/app/site/hosting/scriptlet.nl?script=16&deploy=1&compid=123456&h=4e7fc4ae254bb12779ad&session=PSFT_20200519165344000222>
xml = string_replace(getFileContents, '<URL>', '<URL>' + webstoreURL);
var cXMLArray = getRequestXML.getElementsByTagName("cXML");
if (cXMLArray != null){
var version = cXMLArray.item(0).getAttribute("version");
var timestamp = cXMLArray.item(0).getAttribute("timestamp");
var payloadID = cXMLArray.item(0).getAttribute("payloadID");
if(version != null){
xml = string_replace(xml, 'version=""', 'version="' + version +'"');
}
if(timestamp != null){
xml = string_replace(xml, 'timestamp=""', 'timestamp="' + timestamp +'"');
}
if(payloadID != null){
xml = string_replace(xml, 'payloadID=""', 'payloadID="' + payloadID +'"');
}
}
var filters = new Array();
filters[0] = new nlobjSearchFilter( 'custrecord_punchout_session', null, 'is', buyerCookie);
var searchresults = nlapiSearchRecord( 'customrecord_punchout_session_url', null, filters, null);
for ( var i = 0; searchresults != null && i < searchresults.length; i++ ) {
// get result values
var searchresult = searchresults[ i ];
var record = searchresult.getId( );
var rectype = searchresult.getRecordType( );
nlapiDeleteRecord(rectype, record);
}
var session_url_record = nlapiCreateRecord( 'customrecord_punchout_session_url');
session_url_record.setFieldValue( 'custrecord_punchout_session', buyerCookie);
session_url_record.setFieldValue( 'custrecord_punchout_session_url', punchoutURL);
var id = nlapiSubmitRecord(session_url_record, true);
}else{
'<message>'+
'buyerCookie is not specified. Please resubmit.'+
'</message>';
}
}else{
xml = '<?xml version="1.0" encoding="utf-8" ?>'+
'<message>'+
'Shared Secret is incorrect. Please resubmit.'+
'</message>';
}
}else{
xml = '<?xml version="1.0" encoding="utf-8" ?>'+
'<message>'+
'Request is not formed correctly. Please resubmit.'+
'</message>';
}
battk
07/23/2020, 9:05 PMHelena
07/23/2020, 9:11 PMbattk
07/23/2020, 9:16 PMHelena
07/23/2020, 9:18 PMbattk
07/23/2020, 9:21 PMbattk
07/23/2020, 9:21 PMHelena
07/23/2020, 9:28 PMHelena
07/23/2020, 9:28 PMbattk
07/23/2020, 9:32 PMbattk
07/23/2020, 9:33 PMHelena
07/23/2020, 9:34 PMHelena
07/23/2020, 9:40 PMbattk
07/23/2020, 9:40 PMbattk
07/23/2020, 9:40 PMHelena
07/23/2020, 9:42 PMbattk
07/23/2020, 9:42 PMbattk
07/23/2020, 9:43 PMbattk
07/23/2020, 9:43 PMbattk
07/23/2020, 9:43 PMHelena
07/23/2020, 9:44 PMHelena
07/23/2020, 9:45 PMstalbert
07/23/2020, 9:47 PMHelena
07/23/2020, 9:48 PM