Page 1 of 1

Javascript "If" statement uncaught refernce

Posted: Thu Jun 18, 2020 12:39 pm
by orangetek
I am using paylike.io to process card payments for my customers. The code below brings up a popup window where customers enter card information. For some reason, the If statement is causing an uncaught reference error. If i remove the If statement, everything works as it should. The code will not actually execute fully because i cant leave my public key there.

Code: Select all

Procedure Main(URL$, Success)
  
  Debug "Script URL: " + URL$
  Debug "Loading status: " + Success
  
   !var paylike = Paylike('xxxxxxxxxxxxxxx');
   !paylike.popup({
   !currency: 'EUR',
   !          amount: 1800,
   !                  }, function( err, res ){
   !If (err)    //***** THIS IS THE PROBLEM****
	!			return console.log(err);

	!	console.log(res.transaction.id);

	!	alert('Thank you!');
   !  });
    
EndProcedure

LoadScript("https://sdk.paylike.io/3.js", @Main())
I get this in the console

Code: Select all

Uncaught ReferenceError: If is not defined
    at Popup.cb (spiderbasic.js:284)
    at Popup.close (3.js?_=1592483878720:1083)
    at 3.js?_=1592483878720:1083

Re: Javascript "If" statement uncaught refernce

Posted: Thu Jun 18, 2020 12:59 pm
by Peter
In Javascript 'if' is written in lower case. ;)

Unfortunately the SpiderBasic - IDE converts every 'if' into 'If', if the line does not start with an exclamation mark (also in the Enable/DisableJs - block). That's why you have to be a little careful.

Re: Javascript "If" statement uncaught refernce

Posted: Thu Jun 18, 2020 1:27 pm
by orangetek
Wow, surely that is easily fixed? It will confuse many new to SB. It works when using EnableJS/DisableJS as long as you dont click away from the line as SB will auto upper case

Re: Javascript "If" statement uncaught refernce

Posted: Thu Jun 18, 2020 1:29 pm
by orangetek
Case correction should be disabled for EnableJS/DisableJS