#simo_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1262389320984297482
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
yes, when I am connecting the user to stripe connect in my app
302 status means there's a redirection. however Stripe webhooks don't support redirections. so you need to make sure the URL you set doesn't have a redirect.
This is the route.ts invoked by the webhook
import { db } from '@/lib/db';
import { stripe } from '@/lib/stripe';
import { headers } from 'next/headers';
export async function POST(req: Request) {
const body = await req.text();
const signature = headers().get('Stripe-Signature') as string;
let event;
try {
console.log('it works!');
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_CONNECT_WEBHOOK_SECRET as string
);
} catch (error: unknown) {
return new Response('webhook error', { status: 400 });
}
console.log('here works too: ', event);
switch (event.type) {
case 'account.updated': {
const account = event.data.object;
console.log('account', account);
console.log('account id: ', account.id);
console.log('account transfers: ', account.capabilities?.transfers);
const data = await db.user.update({
where: {
connectedAccountId: account.id,
},
data: {
stripeConnectedLinked:
account.capabilities?.transfers === 'pending' ||
account.capabilities?.transfers === 'inactive'
? false
: true,
},
});
break;
}
default: {
console.log('unhandled event');
}
}
return new Response(null, { status: 200 });
}
I don't get where the url has the redirect then
because it invokes the route I show you here, and there are no redirects, could be something with nextauth and google?
it's hard to tell where exactly is the issue. but yes there's a redirection hapepning somewhere. maybe in the way your server is configured?
Maybe I found the redirection:
export async function CreateStripeAccountLink() {
const user = await currentUser();
if (!user) {
throw new Error();
}
console.log('name: ' + user.name);
const data = await db.user.findUnique({
where: {
id: user.id,
},
select: {
connectedAccountId: true,
},
});
//TODO: modificare il percorso da vercel a domain
const accountLink = await stripe.accountLinks.create({
account: data?.connectedAccountId as string,
refresh_url:
process.env.NODE_ENV === 'development'
? `http://localhost:3000/tutor/billing`
: `https://smartscholars-git-stripeintegration-simonecapellis-projects.vercel.app/tutor/billing`,
return_url:
process.env.NODE_ENV === 'development'
? `http://localhost:3000/return/${data?.connectedAccountId}`
: `https://smartscholars-git-stripeintegration-simonecapellis-projects.vercel.app/return/${data?.connectedAccountId}`,
type: 'account_onboarding',
});
return redirect(accountLink.url);
}```
this is a function I call to connect the user to Stripe Connect, in actions.ts
Could be if it's called somewhere in your webhook code. You'll need to debug this yourself though. It's hard for me to tell just by looking at snippets of your code without access to your environment. This could be cause by many things (maybe you have another layer in front of your endpoint like a reverse proxy or something that's redirecting requests)
you mean in front of the webhook endpoint?
Cause I'm not invoking middleware on /api route, where can i see that?
yep. well you'd generally know if you have something in front of your endpoint
Are you using nginx or something?
Or any sort of middleware?
it wasn't invoking on /api, but at this point I think it is being called somewhere since when I deleted it it's working
so thank you so much again
Cool glad you got it working