jensengar
jensengar

Reputation: 6167

Stripe token with id not found

I'm trying to set up stripe connect but am getting an error when creating a charge. Any idea what I'm doing wrong?

client

Stripe.setPublishableKey([CUSTOMERS_PUBLISHABLE_KEY]);
Stripe.card.createToken({
    number: card.number,
    cvc: card.cvc,
    exp_month: card.exp.month,
    exp_year: card.exp.year
}, stripeResponseHandler);

the response to this call looks like this:

{
  "id": "tok_169ZyxF6SmAjeAPKC9YF7YAi",
  "livemode": false,
  "created": 1433330667,
  "used": false,
  "object": "token",
  "type": "card",
  "card": {...}
  },
  "client_ip": "..."
}

server

var stripe = require('stripe')(config.stripeSecretKey);

stripe.charges.create({
    amount: totalPrice,
    application_fee: appFee,
    currency: 'usd',
    source: paymentToken,   // from above: tok_169ZyxF6SmAjeAPKC9YF7YAi
    destination: [CUSTOMERS_STRIPE_USERID]
}, function(err, charge){
    if (err)
        // Error: There is no token with ID tok_169ZyxF6SmAjeAPKC9YF7YAi.
            // at Error._Error (c:\dev\leaguespeed-node\node_modules\stripe\lib\Error.js:12:17)
            // at Error.module.exports.protoExtend.Constructor (c:\dev\leaguespeed-node\node_modules\stripe\lib\utils.js:113:13)
            // at Error.module.exports.protoExtend.Constructor (c:\dev\leaguespeed-node\node_modules\stripe\lib\utils.js:113:13)
            // at Function.StripeError.generate (c:\dev\leaguespeed-node\node_modules\stripe\lib\Error.js:56:14)
            // at IncomingMessage.StripeResource._responseHandler (c:\dev\leaguespeed-node\node_modules\stripe\lib\StripeResource.js:133:39)
            // at IncomingMessage.emit (events.js:117:20)
            // at _stream_readable.js:938:16
            // at process._tickCallback (node.js:419:13)

        return defer.reject(err);
    else
    {
        defer.resolve(charge);
    }
});

Upvotes: 1

Views: 788

Answers (1)

koopajah
koopajah

Reputation: 25552

The issue here is that you are creating the card token with the connected user's publishable key. Then, you try to charge that token on the platform using the destination parameter. This won't work as that token is not known by the platform and only by the connected account.

You need to use the Platform's publishable key when creating the token if you want to charge on the platform.

Also, Stripe recently modified the flow and any card token created with the Platform's publishable key would work on any of your connected accounts too. This means that you don't need to use the connected account's publishable key anymore and you can simply use the Platform's everywhere.

Upvotes: 1

Related Questions