39

Can't find any information on this particular error anywhere so please bear with me.

My Angular/NodeJS app has a payment page (for monthly and annual subscriptions) handled through Stripe.

I've created the subscription types in my Stripe dashboard (two subscriptions: StarterAnnual and StarterMonthly), and I've set up the handler like so:

  var handler = StripeCheckout.configure({
          key: 'pk_test_qs8Ot1USopAZAyLN3gNXma0T',
          image: '/img/stripe-logo.png',
          locale: 'auto',
          email: $scope.user.email,
          token: function(token) {
            console.log(token)
            var tempObj = {
                stripeToken : token,
                email : $scope.user.email,
                cost : $scope.plan.price * 100
                plan : $scope.plan.name
            }
            $http.post('/api/makePayment', tempObj).then(function(data){
                console.log('stripe data', data);
            },function(err){
                console.log('stripe error', err);
            })
          }
        });

        handler.open({
          name: '<bizname>',
          description: $scope.plan.name,
          amount: $scope.plan.price * 100
        });

In my Node route, I'm doing this:

exports.makePayment = function(req,res){

  var stripeToken = req.body.stripeToken,
            email = req.body.email,
             cost = req.body.cost,
             plan = req.body.plan;

  var tempObj = {
    source: stripeToken,
    plan: plan,
    email: email
  }

  console.log(tempObj); // Everything looks fine in this log

  stripe.customers.create(tempObj, function(err, customer) {
    if(err){
      console.log("Stripe Error");
      console.log(err);
    }else{
      console.log(customer);
      res.status(200).send(customer);
    }

  });
}

When I try to make a payment I get:

Stripe Error
{ [Error: token is not supported.]
  type: 'StripeInvalidRequestError',
  stack: 'Error: token is not supported.\n    at Error._Error (/node_modules/stripe/lib/Error.js:12:17)\n    at Error.Constructor (/node_modules/stripe/lib/utils.js:105:13)\n    at Error.Constructor (/node_modules/stripe/lib/utils.js:105:13)\n    at Function.StripeError.generate (/node_modules/stripe/lib/Error.js:56:14)\n    at IncomingMessage.<anonymous> (/node_modules/stripe/lib/StripeResource.js:138:39)\n    at emitNone (events.js:72:20)\n    at IncomingMessage.emit (events.js:166:7)\n    at endReadableNT (_stream_readable.js:905:12)\n    at doNTCallback2 (node.js:452:9)\n    at process._tickCallback (node.js:366:17)',
  rawType: 'invalid_request_error',
  code: undefined,
  param: 'source',
  message: 'token is not supported.',
  detail: undefined,
  raw: 
   { type: 'invalid_request_error',
     message: 'token is not supported.',
     param: 'source',
     statusCode: 400,
     requestId: 'req_7hzY3mEgeM3nNJ' },
  requestId: 'req_7hzY3mEgeM3nNJ',
  statusCode: 400 }

I've pretty much just used code straight out of the docs, what am I doing wrong here? Do I need to set things up differently for creating a customer when doing a subscription?

JVG
  • 20,198
  • 47
  • 132
  • 210

1 Answers1

87

Found the answer on Stripe's IRC channel: It's not mentioned in the official docs, but Stripe is expecting the token ID, rather than the full token itself.

Simply passing source: stripeToken.id solved the problem for me.

JVG
  • 20,198
  • 47
  • 132
  • 210
  • 6
    THANK YOU! Not only is it not mentioned, it's incorrect in the samples. – ScottCate Aug 30 '16 at 21:32
  • 4
    4 hours gone. WHY isn't this in the docs?? Thank to dear sir. –  Oct 17 '16 at 17:46
  • 1
    Thank you! Stripe has great docs, but they're pretty muddy when it comes to dealing with the tokens. – skwidbreth Mar 31 '17 at 00:14
  • This was helpful. I was stuck for a while. What was wrong for me was from the client I was sending `token.id` when in fact it would not work unless I sent the entire token object to the server and then `token.id` to stripe server side. – Alex Grant Apr 19 '17 at 17:23
  • Thank you, spent way too much time trying to figure out why my token was invalid. Studied the docs and it doesn't cover this anywhere. – Bodie Leonard Jun 11 '17 at 02:39
  • If you're using PHP, the token you get might be in an array instead of an object, in which case you'll need to use `$token['id']`. – Justin Michael Feb 12 '19 at 01:06