#tibo1002

1 messages · Page 1 of 1 (latest)

stark jackalBOT
tulip rivet
#

Hello, can you tell me where exactly you are seeing the 307?

#

If it is the dashboard page for the event, it may be your server that is responding with the 307

ruby rover
#

In the dashboard and with the stripe listen command

tulip rivet
#

Can you show me a screenshot of where you are seeing the 307?

ruby rover
#

I included the request to the billing portal and the redirect

tulip rivet
#

Ah, so that means that your server is responding with a 307

#

To be clear, these events are coming from Stripe and we expect just a simple 200 code back

ruby rover
#

Is it because of my redirect method ?

tulip rivet
#

Yes

#

Also to clarify, this webhook happens because of the end customer, but the webhook itself has no affect on the end customer's browser session. Sending a redirect back to Stripe for this webhook will not redirect the user in their browser

ruby rover
#

So I don't need a redirect ?

tulip rivet
#

For a webhook response? No

ruby rover
#

The redirect here is not for the webhook but to send the user to the billing portal page

tulip rivet
#

That would be required client-side. The issue is that the redirect is how you are responding to webhook events

#

For the redirect to work, your client needs to reach out to your server and that is the thing to respond with a 307 redirect for

ruby rover
#

So it'd be better if I used a res.redirect at the end of my billing portal endpoint ?

tulip rivet
#

Correct

stark jackalBOT
ruby rover
#

The problem is that when I use a res.redirect I get a problem with CORS error with "Access-Control-Allow-Origin" missing
That's why I was using router.push() instead
This is the code with the redirect:

const portalSession = await stripe.billingPortal.sessions.create({
  customer: customerId,
  return_url: returnUrl,
});
res.redirect(300, portalSession.url);
tulip rivet
#

Can you send the full CORS error that you are getting?

ruby rover
#

It's in French:

Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur https://billing.stripe.com/p/session/test_YWNjdF8xTnNpQ3JEcm90NWFRclZCLF9Pb1A0Sk1XOENkek81cnI4OGhBY3ptSFFoQ0ZlbkJa0100yU7xwkLq. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant. Code d’état : 200.

And:

Blocage d’une requête multiorigine (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur https://billing.stripe.com/p/session/test_YWNjdF8xTnNpQ3JEcm90NWFRclZCLF9Pb1A0Sk1XOENkek81cnI4OGhBY3ptSFFoQ0ZlbkJa0100yU7xwkLq. Raison : échec de la requête CORS. Code d’état : (null).

And I'm also getting an axios network error

tulip rivet
#

Can you send me your client code for the request that you are responding to with this redirect?

ruby rover
#

If you want the axios.post it's in the screenshot above.

tulip rivet
#

Can you try returning a 200 code along with the URL and see if your page can receive the text of the URL that you sent back?

#

For certain types or post request, you can't respond with a redirect. You need to send the URL back and then have the client do a redirect

#

Oh and actually have you tried including a "Access-Control-Allow-Origin" header as that is the one that the CORS errors mentions is missing?

ruby rover
#

Doing the redirect client-side is what I was doing with the router.push ?

#

I did not try to do that.
I was mostly following this StackOverflow thread

tulip rivet
ruby rover
#

I'm using NextJS but I guess that it's the same.
I tried returning a 200 in the res.redirect and it was not working (I currently have a 300 like in the docs but it's not working too).

tulip rivet
#

Unfortunately I'm not that knowledgable about next.js and am not finding info here. I think this may be something that you need to take to a Next.js forum. At this point the error is entirely between your specific server and client. It is about a Stripe URL but this error would happen for any URL passed like this.

ruby rover
#

Thx I'll do that.
Big thanks for taking your time trying to find a solution to my problem and explaining the potential cause.
👍👍👍

tulip rivet
#

Sounds good! Sorry I was not able to help more