#Damanmokha
1 messages ยท Page 1 of 1 (latest)
Is this just the sample quickstart app that you downloaded? Or is this your modified version?
This is just a sample code that I used in my project. I copied the specific part from the sample and added it to my React application. It worked fine for the first two steps where the payment intent was successfully created. However, when it comes to the payment collection step, I encountered the error mentioned earlier.
Ah ok so you merged the code into your existing app
Can you share the contents of your attach.js file?
Also what line number is it saying the error is occurring on? Screenshot is cut off
This is my component file, the attach.js file is just react runtime thing, it's asking for authorisation on terminal.collectPaymentMethod, which is on 83 line of my component file which is attached.
Oh looks like you leaked your test mode secret key
You'll need to roll that key now since it's been exposed: https://stripe.com/docs/keys#rolling-keys
opps, sorry. that was not needed in here, added for some hit and trail forgot to remove it ๐
Also apiKey isn't a valid parameter to StripeTerminal.create
yes, I checked that later in API reference. was trying to provide auth token as it was not populating itself.
any idea on that why i am getting auth error?
Let me check with a colleague. I'm not as familiar with terminal
Hello ๐
You're using the Javascript SDK correct?
It sounds like your StripeTerminal object is losing the connectionToken somewhere
https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=js#initialize
Can you try printing terminal before calling collectPaymentMethod?
Can you expand the object?
Do you a reference to the fetchConnectionToken callback function?
Oh I think your fetchConnectionToken() is returning a promise instead of a string value
Can you change the syntax to use async-await instead as shown in the example?
https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=js#connection-token-client-side
for only fetchConnectionToken
yup
let me do it and then check
๐ I believe the function needs to return a string value for the connectionToken that the client-side SDK then uses to perform operations. Currently, the function is returning a promise instead (returned by fetch)
Done but its same.
Hmm it seems to be failing a GET request for the PaymentIntent ๐ค
i checked it's returning string check the fetchConnectionToken line
yes GET request for payment intent is failing and saying to authorise ๐
Great! Are you calling Stripe API endpoint directly from your client-side code?
what is the value for API_ORDER_PAYMENT_INTENT ?
Is it calling your server OR stripe API directly?
API_ORDER_PAYMENT_INTENT
this is my server BE endpoint for generating Intent.
Gotcha. If you comment out the collectPaymentMethod function, do you see the error OR does it go away?
Yup, it goes away,
Fascinating.. Hmm, thinking..
i consoled client_secret just before terminal.collectPaymentMethod, i am getting client_secret, but after that stripe payment intent api fails with authentication.
Can you share the PaymentIntent ID?
this one is the latest pi_3N6bXfE1QPAb4xC506wh31ls
The reader is registered to the same account correct?
Ah you're running the example code that we have in our quick start right?
https://stripe.com/docs/terminal/quickstart?platform=web&client=js
Only diff is you're running it in a react component
yup
Can you comment out the useEffect() that you have in the component and try again?
Huh so weird
hmm, not sure why it is not getting it, the quick start guide works fine for me also. i have matched the code on various level it seems similar but, not sure why it's not appending auth in payment intent.
You've removed the apiKey parameter from StripeTerminal.create correct?
Thanks, trying to see if I can reproduce this
Sure thanks. Will be helpful ๐
Are you using StrictMode?
Also, how exactly are you importing @stripe/terminal-js in your app?
Gotcha.
Okay I tried the same code on my end but couldn't reproduce the behavior ๐ฆ
Can you print API_ORDER_PAYMENT_INTENT before calling .collectPaymentMethod ?
The other thing you can try is initializing the SDK in index.js instead of the component and pass the terminal object as props
it's working on your end?
yup
strange.
you want response from API_ORDER_PAYMENT_INTENT
? before collectPaymentMethod
Just wanted to double check if the URL was correct.
If you look into your network tools and check the failed request headers. what do you see?
For my successful request, I see something like this
Do you see Authorization key in the headers?
it's fine, it's responding the payment intent, as have already console.log just before
yup
no in my request Authorization header is not present.
Ah interesting, that's likely the issue
yes, but i don't see how to send if its not sent automaticly
did you tried the above, in React?
Yup in React
There should be another request to the same path but an OPTIONS request
Can you look at that one and share a screenshot?
Is that one failing too?
I see. Can you try moving the terminal SDK intialization code to index.js file and passing the object down as a prop to your component?
So basically moving StripeTerminal.create. fetchConnectionToken and unexpectedDisconnect to the index file
Could you share the complete code in the App component?
also try restarting your react server + browser for good luck ๐
my App component has diffrent routes!
Also, curious about authInterceptor function
you should disable it
yup
IIRC from Angular concepts
it messes with Authorization headers
because in that i was manipulating the Auth for my Server's auth
let me try removing it
Should've asked for your other code way sooner ๐
No worries, glad we figured it out
I was also sending you the one with the component, i should have also checked the parent components ๐
All good, glad its working now!
Happy to help!
I gotta step away now but if you have any follow ups @lethal dirge can help!
Sure thanks ๐