lmsqueezy / laravel

A package to easily integrate your Laravel application with Lemon Squeezy.
https://lemonsqueezy.com
MIT License
468 stars 47 forks source link

What is the proper way to handle a subscription end due to billable removal? #90

Closed pdziewa closed 1 month ago

pdziewa commented 1 month ago

Hi!

I have a little problem as I mentioned in a title.

Currently, I have code like this:

$billable->subscription()->cancel();
$billable->delete();

The issue arises when the application receives a webhook from Lemon Squeezy (subscription_cancelled, subscription_updated) at which point $billable is already removed. This triggers an error:

LemonSqueezy\Laravel\Events\SubscriptionCancelled::__construct(): Argument #1 ($billable) must be of type Illuminate\Database\Eloquent\Model, null given

How can I properly handle the end or removal of the subscription?

driesvints commented 1 month ago

Thanks @pdziewa. I've sent in a PR here to address this: https://github.com/lmsqueezy/laravel/pull/91