Javascript "If" statement uncaught refernce

Using Javascript from SpiderBasic
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Javascript "If" statement uncaught refernce

Post 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
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Javascript "If" statement uncaught refernce

Post 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.
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Re: Javascript "If" statement uncaught refernce

Post 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
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Re: Javascript "If" statement uncaught refernce

Post by orangetek »

Case correction should be disabled for EnableJS/DisableJS
Post Reply