Leart Rudi
Leart Rudi

Reputation: 15

STRIPE.JS Error

Stripe.js Trying to implement Stripe in a project and i keep getting this error Any idea what should i do ???

Stripe is not defined fix or add /global $/

-----> "stripe_card_token"=>"undefined"}} <------

 $(document).ready(function() {
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
  // Watch for a form submission:
  $("#form-submit-btn").click(function(event) {
    event.preventDefault();
    $('input[type=submit]').prop('disabled', true);
    var error = false;
    var ccNum = $('#card_number').val(),
        cvcNum = $('#card_code').val(),
        expMonth = $('#card_month').val(),
        expYear = $('#card_year').val();

    if (!error) {
      // Get the Stripe token:
      Stripe.createToken({
        number: ccNum,
        cvc: cvcNum,
        exp_month: expMonth,
        exp_year: expYear
      }, stripeResponseHandler);
    }
    return false;
  }); // form submission

  function stripeResponseHandler(status, response) {
    // Get a reference to the form:
    var f = $("#new_user");

    // Get the token from the response:
    var token = response.id;

    // Add the token to the form:
    f.append('<input type="hidden" name="user[stripe_card_token]" value="' + token + '" />');

    // Submit the form:
    f.get(0).submit(); 
  }
});

Upvotes: 0

Views: 259

Answers (1)

Daniel Diekmeier
Daniel Diekmeier

Reputation: 3434

I think your first error is from the linter you're using. You can add /* global Stripe */ as the first line (depending on the linter you use).

Upvotes: 1

Related Questions