Supabase stripe webhook listening to events that are not triggered from the app

Hi,
We have a stripe webhook setup that is used for our Stripe Connect Customers. This webhook is triggered when a payment is made from the weweb that is listening to this Stripe Webhook.
Not what is happening is there are auto-subscriptions setup on our stripe account for non weweb customers and this webhook is also getting triggered on payment_intent.succeeded for these users. How can I stop the webhook getting triggered for all the payment_intent.succeeded? I want it to only listen to this event, when it is triggered from the weweb app.

I think you need to add meta-data to your payment_intent.succeeded then in the Supabase webhook, you filter for example for metadata.source = weweb-payment. I used this for my NodeJS project, this is how I handled this. It’s not the exact same thing, but it’s pretty similar.

 try {
        event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
    }
    catch (err) {
        return res.status(400).send(`Webhook Error: ${err.message}`);
    }

    if ( event.type === 'checkout.session.completed' ) {

        const { metadata, customer_details } = event.data.object;

        if (metadata.type === 'digital-goods') {
            const digitalGoodsPath = path.join(rootDir, 'content', 'goodies');

            if (metadata.product === 'rbac-script') {
                   // Your logic for the (in my case) product that has 'rbac-script' metadata
            }

        } else return res.status(400).send(`Object is not defined.`);

    }

By the way, you can use Stripe Wrapper | Works With Supabase to avoid this entirely maybe?

This is how my (in this case payment link) works, with metadata and all.

1 Like

@Broberto thank you sharing this. I’ll give it a try!