Thursday, 4 May 2017

Stripe: No such token Error

I just switched from Stripe's "test secret Key" to a "live secret key" as I am preparing to launch my website. The test secret key has always worked perfectly.

Now that I have the site live and am using the live secret key for some reason I am getting this error: "similar object exists in test mode, but a live mode key was used to make this request."

This is my set up:

stripe = require("stripe")("sk_live_stripelivekeyhere") 

Then I charge my user's when they're creating their account as shown below:

user.save(function(err) {
    console.log('this is the problem' + ' ' + err)
    if(err){
    return res.redirect('/buy')
    }
    var token = req.body.stripeToken; // Using Express
    var charge = stripe.charges.create({
    amount: 749,
    currency: "usd",
    description: "Example charge",
    source: token,

    }, function(err, charge) {
        if(err) {
          console.log(err);
          return res.redirect('/buy')
        }
        console.log('charged')
        req.logIn(user, function(err) {
          if(err) {
            console.log(err);
          }
          console.log('all looks good')
          res.redirect('/results');
        });
    });
  });
});



via AndrewLeonardi

No comments:

Post a Comment