'No such token' error upon submitting payment request to Stripe

47,684

Solution 1

Are you sure you're using the same API keys on your server and client?
Your server should be using your (live/test) secret key, and your iOS app should be using your (live/ test) publishable key as mentioned here on Stripe Testing.

Solution 2

I had been facing same issue for my test environment and the mistake i had been doing, i was adding the token received by Stripe like this one source: 'tok_18nnwSJ6tVEvTdcVs3dNIhGs' , but for the test environment we have to use source: 'tok_visa'.

Here is the list of test sources provided by Stripe. https://stripe.com/docs/testing#cards

It created customer for me, let me know if it helped anyone else as well.

Solution 3

The accepted answer does not work for me. I am using correct key for client and server, but still the issue is still there. I am sending source from iOS to the server as well, based on stripe example RocketRides, it is sending source ID of the credit card, which is "card_xxx", and that is not gonna work. You will have to add "customer" attribute for the call on your server side.

For example: (python)

stripe.Charge.create(amount=1000, currency='usd', source="card_xxxxx", **customer**='cus_xxxx', application_fee=600,destination={'account': 'acct_xxxx'})

Solution 4

Neither of the answers here worked for me.

I was trying to use Stripe's PHP library to charge a card that I already had on file like this...

$charge = \Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'gbp',
    'card' => 'card_xxx',
    'description' => 'Payment for Sam',
]);

And I was receiving the no such token error above.

To get it to work, I also had to provide the customer id like so...

$charge = \Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'gbp',
    'customer' => 'cus_xxx',
    'card' => 'card_xxx',
    'description' => 'Payment for Sam',
]);

Solution 5

  1. First check api keys wheather they are the same at front end and backend.
  2. If you are using testing api keys then you have to pass source: 'tok_visa' instead of your card source token source: 'tok_kb3kb23k2bk32bk3b2'.
Share:
47,684
Jordan H
Author by

Jordan H

*OS Developer

Updated on July 09, 2022

Comments

  • Jordan H
    Jordan H almost 2 years

    I'm setting up payments using the Stripe API to allow a user to log into their Stripe account on an iPad and accept payments from anyone. To do this, I'm using Stripe Connect to log them in and save their account id, then I'm using the STPPaymentCardTextField to obtain credit card details, then using the Stripe iOS SDK I'm submitting a card (with the test card info - 4242...) and getting back a token via createTokenWithCard. This successfully returns a token. At this point I need to submit that token along with the destination account id (provided to the app after the user logged in) and other info (currency, amount, etc) to my own server to submit the payment to Stripe. I have verified that information is being submitted and forwarded onto Stripe, but Stripe is returning an error:

    { type: 'invalid_request_error',
    app[web.1]:      message: 'No such token: tok_13vxes2eZkKYli2C9bHY1YfX',
    app[web.1]:      param: 'source',
    app[web.1]:      statusCode: 400,
    app[web.1]:      requestId: 'req_7AIT8cEasnzEaq' },
    app[web.1]:   requestId: 'req_7AIT8cEasnzEaq',
    app[web.1]:   statusCode: 400 }
    

    If we submit the credit card info directly, avoiding the token altogether, the payment succeeds. Something is wrong with this token, and we are not sure why it is failing. What could be going wrong here?

    [[STPAPIClient sharedClient] createTokenWithCard:card completion:^(STPToken *token, NSError *error) {
        //submit tokenId and other info to 'charge' endpoint below
    }
    

    NodeJS:

    app.post('/charge', (req, res, next) => {
      stripe.charges.create({
        amount: req.body.amount,
        currency: req.body.currency,
        source: req.body.token,
        description: req.body.description,
        destination: req.body.destination
      }, (err, charge) => {
        if (err) return next(err)
        res.json(charge)
      })
    })
    
  • Jordan H
    Jordan H over 8 years
    The problem was the publishable key didn't match the key shown in Account Settings. Somehow it was changed since I pasted it into my AppDelegate.
  • caleb marincel
    caleb marincel over 8 years
    argh had the same issue. thanks for pointing to the solution @Joey
  • Rob
    Rob over 7 years
    same issue, so simple but I didn't think of it.
  • Christopher Grigg
    Christopher Grigg about 7 years
    I had a slightly different issue where I had to "roll" or create a new 'pk_test' key and it worked.
  • Usher
    Usher over 6 years
    because I have got same "no such toke" error and the accepted answer does not work. In case anyone else found same issue, they can check if they are missing this attribute. programming language is not the key, the key is to add this attribute
  • Fan Jin
    Fan Jin about 6 years
    For me, the issue was I was using a wrong publishable key for my iOS client.
  • Andrew Mast
    Andrew Mast about 6 years
    You are a life saver. I copied some code from another project and forgot to change the publishable key. Thanks!
  • Natanel
    Natanel about 6 years
    Just to clarify, this issue comes up when using the STPPaymentContextDelegate method paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock). paymentResult.source.stripeID is a string formatted as "card_xxxx" which can't be charged on the server by itself with an amount. As Usher correctly points out, you also need to send the customer id.
  • uno
    uno about 5 years
    I am facing similar issue. tok_visa works. but i try using the test numbers and they won't work. Is this normal because i see many people using numberes... even other ecommerce platforms allow the test numbers in sandbox mode so something is up
  • Amit Kadivar
    Amit Kadivar over 4 years
    replace the default public key to your public key in the script tag.
  • pref
    pref over 3 years
    had the same problem . client token was created with PK of another account and SK couldn't validate it on the server side.
  • kuldeep chopra
    kuldeep chopra almost 3 years
    I am using chargebee with stripe and I am getting the same issue and tok_visa fixed the problem. but it was working before when I am using chargebee PC1.0