1 year ago

Stripe Cannot get Token

Posted 1 year ago by Asad

This is i have included in my head

       <script src=""></script>

This is mine Form

           <form action="/payment" method="post" id="payment-form">
           <div class="form-row">
            <label for="card-element">
              Credit or debit card
             <div id="card-element">
               <!-- A Stripe Element will be inserted here. -->
               <!-- Used to display Element errors. -->
              <div id="card-errors" role="alert"></div>
            <button>Submit Payment</button>

This is mine script

  var stripe = Stripe('pk_test_kzEtBzSaYTdH861psURrqZR1');
  var elements = stripe.elements();

    var style = {
 base: {
    // Add your base input styles here. For example:
    fontSize: '16px',
    color: "#32325d",

      // Create an instance of the card Element. 
     var card = elements.create('card', {style: style});

  // Add an instance of the card Element into the `card-element` <div>.

card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
    displayError.textContent = event.error.message;
} else {
    displayError.textContent = '';

    var form = document.getElementById('payment-form'); 
    form.addEventListener('submit', function(event) {

    stripe.createToken(card).then(function(result) {
    if (result.error) {
    // Inform the customer that there was an error.
     var errorElement = document.getElementById('card-errors');
    errorElement.textContent = result.error.message;
   } else {
  // Send the token to your server.

}); function stripeTokenHandler(token) { // Insert the token ID into the form so it gets submitted to the server console.log(token);

  var form = document.getElementById('payment-form');
  var hiddenInput = document.createElement('input');
  hiddenInput.setAttribute('type', 'hidden');
  hiddenInput.setAttribute('name', 'stripeToken');

 // Submit the form
//   form.submit();


Please sign in or create an account to participate in this conversation.