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

Javascript "If" statement uncaught refernce

by orangetek Thu Jun 18, 2020 12:39 pm

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: 762
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: Javascript "If" statement uncaught refernce

by Peter Thu Jun 18, 2020 12:59 pm

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

by orangetek Thu Jun 18, 2020 1:27 pm

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

by orangetek Thu Jun 18, 2020 1:29 pm

Case correction should be disabled for EnableJS/DisableJS
Return to Javascript

Who is online

Users browsing this forum: No registered users and 1 guest