payloadcms/plugin-stripe

deleteFromStripe hook throws error whenever we have a delete webhook configured

souhailfaiz opened this issue · 3 comments

Hi, currently there is no SkipSync functionality for payload.delete() function. This means that whenever we delete something from Stripe Dashboard and have a deleted webhook configured to use payload.delete() function. It will basically execute the DeleteFromStripe.ts hook (in this plugin) and that will again try to delete the collection from stripe. But obviously it does not exist anymore and therefore throws an error.

To solve this we need a mechanism like SkipSync but I do not see how we can pass any arguments to the payload.delete() function, so not sure if this is even possible...?

I would personally suggest to add a GET request before deleting a record from Stripe inside the DeleteFromStripe.ts hook method. If we could not find any record we should just log something and skip deleting.

What are your thoughts on this matter?

@souhailfaiz this makes perfect sense to me, and your solution is a good one—although one simpler way to do this might be to not throw this API Error but instead silently log it to the console. This way we can save from making that additional request to the Stripe API.

I'm trying to decide which would be better. To be honest I'm leaning toward your solution because it will ensure that no deletion is left behind, despite the performance implication. What do you think?

I just published this in 0.0.13, give it a shot! And big thank you for reporting this 🙌

@jacobsfletch Ahh thanks for the very fast reply and merge (even faster than me responding to you hehe).

Silently logging would indeed be the simple solution and reduces the extra call. But since this is only for the "delete" hook function, I personally think that it is acceptable to do an extra request so that we can ensure deletion.

In a real world application I don't think apps should use deletion that much... you want to keep as much data as possible. But that depends on the use case of course.

Anyways, appreciate your very fast fix!