#Having issues with Stripe Webhooks in App Router

11 messages · Page 1 of 1 (latest)

thick pawnBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

urban eagle
#

Just adding the switch part becuase of character count

        switch (event.type) {
            case 'checkout.session.completed':
                const session = event.data.object;
                console.log('Checkout session completedddddddddddddddddddd:', session);

                // Extract Clerk user ID and Stripe customer ID from the metadata
                const clerkUserId = session.metadata?.clerkUserId;
                const stripeCustomerId = session.customer;
                console.log('Clerk user ID:', clerkUserId, 'Stripe Customer ID:', stripeCustomerId);

                if (clerkUserId && stripeCustomerId) {
                    try {
                        // Fetch the current user's metadata
                        const user = await clerkClient.users.getUser(clerkUserId);
                        const currentMetadata = user.publicMetadata || {};

                        // Merge the current metadata with the new metadata
                        const updatedMetadata = {
                            ...currentMetadata,
                            subscription: "active",
                            stripeCustomerId: stripeCustomerId
                        };

                        // Update the user's metadata with the merged metadata
                        await clerkClient.users.updateUserMetadata(clerkUserId, {
                            publicMetadata: updatedMetadata
                        });

                        console.log('User metadata updated successfully');
                    } catch (clerkError) {
                        console.error("Error updating Clerk user metadata:", clerkError);
                    }
                }
                break;
            // ... handle other event types
            default:
                console.log(`Unhandled event type ${event.type}`);
        }```
radiant acorn
#

I created exactly the same some days ago and it’s working fine. How do you construct the webhook event? @urban eagle

urban eagle
#

@radiant acorn I guess moreso my question is, in the code above, where can I see the output of:

console.log('Checkout session completedddddddddddddddddddd:', session); when Stripe sends me the checkout.session.completed event? I am handling the event itself fine but cannot see logs.

It does not show up in my terminal or console

#

I feel like this should be simple but can't figure it out

radiant acorn
#

you normally should be able to see them inside your vercel (or online other online provider) logs. The code itself works fine?

urban eagle
#

The code itself it working fine, at least according to Stripe's CLI. Where would I see it just running on localhost though?

radiant acorn
#

normally inside your IDE. If you also use webstorm, I can show you where 🙂

radiant acorn
#

@urban eagle found?

radiant acorn
#

@urban eagle ?

urban eagle
#

It ended up having to do with api keys - all good!