laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 667 forks source link

It would be great if Cashier had events #1668

Closed whoacowboy closed 4 months ago

whoacowboy commented 4 months ago

Hi, i am in the process of writing a few events for my app that dispatch events at various steps in the subscription process. It would be great if this was built into Cashier.

The following events are what we need, but I could imagine a whole host of events would be extremely useful.

SubscriptionCanceled SubscriptionCancelling SubscriptionCreated SubscriptionPastDue SubscriptionResumed TrialCanceled TrialStarted

I imagine a bunch around invoicing would be super useful as well.

Right now I am creating a StripeEventListenr taking the logic from the Cashier WebhookController stripping out the function code and add the above events.

Best, james

driesvints commented 4 months ago

Hi there, these could indeed be useful but given that we'd have to build in the logic when these occur, things could get complicated fast. For now we'll limit ourselves at just sending out the incoming webhook events.

whoacowboy commented 4 months ago

@driesvints You could start with the low hanging fruit and move up from there. There are a bunch of these events that you have to know are occurring because Cashier is updating the customer's subscription based upon the event.

driesvints commented 4 months ago

I do agree it could be useful. Just might get tricky in determining when these events would actually have to occur since there's no native incoming event for some of them (like the trials you mention). At this time I don't feel comfortable adopting this logic into the library sorry.

whoacowboy commented 4 months ago

No worries, I get it. But there is a case to make for dispatching events for the things you already are tracking, e.g. SubscriptionCreated, Resumed, Canceled, etc. Laravel dispatches many events during the auth process, Login, Register, etc. It's arguable that the subscription events you already monitor might be more important or at least as important as the Auth events.

My use case includes trials but for an initial pass the easier Subscription events might be worth taking a look at.

It's a nice to have. I love Cashier and appreciate you all doing what you do.

Best, james

nikspyratos commented 3 months ago

Would it not make sense to have events that match the webhook events? So a SubscriptionCreated for example. Just dispatch them all out of the webhook handling. No complex logic on when and where in that case.