#bwurtz999

1 messages · Page 1 of 1 (latest)

weak etherBOT
waxen flame
#

Hi
Could you please five more details ? what you want to achieve exactly and/or what part of your code is generating this ?

spare palm
#

I'm trying to generate a connection token with the JS SDK

#
async function fetchConnectionToken() {
  // Your backend should call /v1/terminal/connection_tokens and return the JSON response from Stripe
  const response = await fetch("{{ route('location-stripe-connection') }}?useCaseId={{ $useCaseId }}&organizationId={{ $organization_id }}&locationId={{ $location_id }}", { method: "POST" });
  console.log(response);
  try {
      const data = await response.json();
  } catch(error) {
    console.log(error);
    handleCardReaderError();
  }
  return data.secret;
}
#

I'm using the fecthConnectionToken syntax provided by the docs

waxen flame
spare palm
#

Yes

#

I haven't changed this since I initially got it working. And now it's throwing an error

waxen flame
spare palm
#

Yes

waxen flame
#

you have a backend endpoint that call /v1/terminal/connection_tokens API ?

spare palm
#

Yes

#

that is working fine

#

both locally and in production

#

I've verified that

#

But for some reason on my checkout page the request fails

waxen flame
#

onFetchConnectionToken failure. Please make sure your function creates a new connection token via your backend
Is this a response from Stripe API or your frontend is formatting this ?

spare palm
#

That's from Stripe

#

No I don't have a failed request ID. The request is never even reaching my API. But when I copy the request URL and run it externally using Insomnia it works as expected and creates the token

waxen flame
#

The request is never even reaching my API
You mean the call from your frontend to your own backend is not sent ?

spare palm
#

It attempts to send... but it generates an error

waxen flame
#

That's from Stripe
No I don't have a failed request ID
I'm a bit confused, if it's a response from an API Stripe call, you should have an API call

spare palm
#

But you can see in the screenshot the actual API endpoint is working fine

waxen flame
#

could you make a screenshot where you are seeing the error message please ?

spare palm
#

From this page, the request returns a 302

#

But in Insomnia I get a 200 as expected

waxen flame
waxen flame
#

try calling/debugging your js function fetchConnectionToken outside of StripeTerminal.create and see if it calls your backend correctly or not from your frontend

#

Make sure there is no middleware between your frontend and backend that is causing the redirection somhow

spare palm
#

It fails on its own outside of Stripe

#

This is so weird

waxen flame
#

because the function fetchConnectionToken can't reachout to you own backend not to Stripe APIs... and when you call the endpoint using Insomnia it works... it must be something between your frontend and backend which is causing

#

are you having this in the same machine? e.g. your local environment where you run your both backend and frontend on the same machine ?

spare palm
#

The middleware... wow

#

Yeah I did change that. I completely missed that

#

That's definitely the problem

waxen flame
#

I think so too

spare palm
#

Thank you thank you

#

It's always so helpful to chat with someone about what's going on

waxen flame
#

You're welcome!