skip to Main Content

I’m trying to update the cardNonceResponseReceived in our Square payment form JS for SCA (we are based in the UK) and am using the current connect version and following the code examples provided by Square but am getting a error when in the console and the form fails to load as expected. I can’t see what I am missing – any help appreciated.

I’ve checked the current connect-api php-payment for the latest JS example but the problem persists on our live and also the https://github.com/square/connect-api-examples/blob/master/connect-examples/v2/php_payment/js/sq-payment-form.js sample, regardless of calling the sandbox or live environments. The error occurs on all Square’s examples of updated cardNonceResponseReceived examples in the cookbook. I am providing locationId and have updated the code as follows (form the samples provided):

/*
 * callback function: cardNonceResponseReceived
 * Triggered when: SqPaymentForm completes a card nonce request
 */
cardNonceResponseReceived: function (errors, nonce, cardData) {
  // Assign the nonce value to the hidden form field
  document.getElementById('card-nonce').value = nonce;
  const verificationDetails = {
    amount: '100.00',
    intent: "CHARGE",  //Allowed values: "CHARGE", "STORE"
    billingContact: {
      familyName: "Smith",
      givenName: "John",
      email: "[email protected]",
      country: "GB",
      city: "London",
      postalCode: "SW7 4JA",
      phone: "020 7946 0532"
    }
  };
  try {
    paymentform.verifyBuyer(
      nonce,
      verificationDetails,
      callback(err,verification) {
        if (err == null) {
          document.getElementById('buyerVerification-token').value = verification;
        }
    });
    // POST the nonce form to the payment processing page
    document.getElementById('nonce-form').submit();
  } catch (typeError) {
    //TypeError thrown if illegal arguments are passed
  }
}

The console reports SyntaxError: Expected ')' (Edge)
SyntaxError: missing ) after argument list (Firefox) on the line
callback(err,verification) {

3

Answers


  1. Chosen as BEST ANSWER

    The examples provided by Square are inaccurate & will be updated - callback(err,verification) should read function callback(err,verification)


  2. Do this: create a separate call function.

    function verifyBuyerCallback(err,verification) {
      if (err == null) {
        document.getElementById('buyerVerification-token').value = verification;
      }
    }
    
    paymentform.verifyBuyer(nonce, verificationDetails, verifyBuyerCallback);
    Login or Signup to reply.
  3. To clarify,

    paymentform.verifyBuyer(
      nonce,
      verificationDetails,
      callback(err,verification) {
    //--------------------------^
    

    The Javascript syntax for a function call is like callback(err,verification); syntax for an anonymous function definition is like function(err,verification) {...} and syntax for a named function definition is like function callback(err,verification) {...}. So this is saying you want to call an existing function called “callback” as the third argument, and then you have {, which doesn’t make sense. Most commonly this happens when a closing character was missed, which is why all the Javascript engines suggested that ) was missing.

    It should have said function(err,verification) { instead of callback(err,verification) {.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search