x

Submit sqpayment form using ajax

Hi,

 

I followed your tutorial on how to create the sqpayment form and was able to successfully charge a card using sandbox credentials. 

My question is, is it okay to submit the form to the backend using ajax instead of 

 

Here's the code from the sqpaymentform-basic.js, I am planning to replace this code document.getElementById('nonce-form').submit(); to a ajax POST request to our backend. My reason is that I do not want the user to go to another page, instead stay on the same page and render the successful/failure charge there. 

 

 

cardNonceResponseReceived: function (errors, nonce, cardData) {
      if (errors) {
        // Log errors from nonce generation to the Javascript console
        console.log("Encountered errors:");
        errors.forEach(function (error) {
          console.log('  ' + error.message);
          alert(error.message);
        });

        return;
      }
      // Assign the nonce value to the hidden form field
      document.getElementById('card-nonce').value = nonce;

      // POST the nonce form to the payment processing page
      document.getElementById('nonce-form').submit();

    }

 

 

917 Views
Message 1 of 1
Report
0 REPLIES 0