#Farhaan-Token
1 messages · Page 1 of 1 (latest)
Hi there, you should call stripe.createToken (https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement) in the frontend to create the token and pass the token to your backend.
BTW, using Tokens API is the old way, if you are new to Stripe, I'll highly recommend you to use the PaymentIntents API + PaymentElements https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
Actually we are not using tokens for payment. We are using it to create customers on platform account using default card.
curl --location --request POST 'https://api.stripe.com/v1/customers'
--header 'Authorization: Basic c2tfdGVzdF81MUc2Ukk4QWxudTdtVlNXbFF0YkVzMDJHRGxFMkNYdG9yV3A3MkJvcE51T2RsdG83NU9XZzRURFAyZ0NzWUN5M0UwODl5MXptWW80bTFkbG9YeDg1eWtHSDAwa1JQcHoxWVE6'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'email=MasterCard@yopmail.com'
--data-urlencode 'source=tok_1LItgsAlnu7mVSWlvVI67wsR'
--data-urlencode 'name=MasterCard'
So here, you see that I need token in source. So I am trying to create the token for this thing. So shall I create a token in react using stripe.createToken(), take that token and pass it to node, to stripe.tokens.create()?
You can just pass the token created from frontend to source here, you don't need to call stripe.tokens.create() in the backend.
btw, you should remove the Authroization header in chat, discord is a public place so everyone can see
To play safe I'd suggest you to roll the key asap. https://stripe.com/docs/keys#rolling-keys
If I pass the token created from front-end, I get this error.
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: 'tok_1LRsXRPJQbmTO8cWGTKwzu1G'",
"param": "source",
"type": "invalid_request_error"
}
Hence I am confused thinking that there's something wrong with my token
Can you share the request ID (req_xxx)? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
I actually didnt get the request ID, I just got this error in postman.
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: 'tok_1LRsXRPJQbmTO8cWGTKwzu1G'",
"param": "source",
"type": "invalid_request_error"
}
}
You can find the request ID from Stripe Dashboard, please check the link that I sent earlier.
req_bVTdfWGlBVvgBw
Thanks. From my end I can see that the token was created in a different account, that's why it cannot be found
Can you double if you are using the correct publishable key / secret key pair in your integration?
cool, thanks, I got the issue
Actually while creating token, I am passing cardNumberElement, in which I am also passing cardNumberElement._controller._stripeAccount
Is there anyway so I can remove this?
Why are you passing the stripeAccount ?
Did you specify the stripeAccount when initializing Stripe.js ?
yeah that's the issue. I think I will change it. Yes I did so. Maybe I shouldn't do that
You only need to add the stripeAccount if you are making a call on connected account. https://stripe.com/docs/connect/authentication