-
Notifications
You must be signed in to change notification settings - Fork 704
Description
Cashier Stripe Version
15.3.2
Laravel Version
10.48.12
PHP Version
8.2
Database Driver & Version
10.11.7-MariaDB-1:10.11.7+maria~ubu2204
Description
This is a continuation of closed tickets #1734 #1678 #1307 and probably others.
As several people have stated in the comments on these tickets the duplicate subscription error is definitely a problem - we have had 20+ in the last few days. I'm actually surprised the webhook is so fast that it is received before Cashier creates the subscription in the database, but I concur with other users reporting this that it does indeed happen.
I believe a potential cause of this is the index was added in this commit 3 and a half years ago, but the upgrade guide doesn't make any mention of this, which is likely why some users do not have this index (myself included). Manually adding the index also introduces the issue of having to clear our the duplicate rows.
The second issue is that the webhook doesn't wrap the insert queries in a try/catch
block, meaning if the index does exist it will throw a database exception. Stripe will receive a 500 error response and will re-try it - the second attempt will work as either the query in the webhook handler or the create subscription function will find the existing subscription, however if Stripe receives too many non-2xx response codes it can disable the webhook, which is not desirable and should be avoided.
In summary, as well as the upgrade guide making a note to add this index, the webhook should suppress any exceptions regarding uniqueness to prevent Stripe disabling the webhook due to high error rates.
Steps To Reproduce
As others mentioned this issue does not always occur, but if the timing is right, you will either end up with two subscriptions or a database exception.