Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)   }) }) 
like image 949
Jordan H Avatar asked Oct 14 '15 22:10

Jordan H


People also ask

What does invalid stripe token mean?

The “Invalid Token” message indicates that a link has either been used previously, or has expired. To generate a new link, reset your password again through the main login screen.

What is the use of stripe token?

Tokenization is the process Stripe uses to collect sensitive card or bank account details, or personally identifiable information (PII), directly from your customers in a secure manner. A token representing this information is returned to your server to use.


2 Answers

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.

like image 116
jflinter Avatar answered Oct 06 '22 01:10

jflinter


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.

like image 40
Hamza Khan Avatar answered Oct 06 '22 00:10

Hamza Khan