gerardojbaez / laraplans

SaaS style recurring plans for Laravel.
http://laraplans.readthedocs.io
MIT License
180 stars 81 forks source link

Question - valid_until vs ends_at #41

Closed llioor closed 4 years ago

llioor commented 6 years ago

Hi guys, Someone can explain what is the usage/differences of: PlanSubscription "ends_at" attribute and PlanSubscriptionUsage "valid_until" attribute.

I understood that the PlanSubscription talks about the subscription itself when the PlanSubscriptionUsage talks about the usage but I didn't understand the "usage" thing...

Please someone can explain by example. Thank you very much for the package and time saving!

Leo.

gerardojbaez commented 4 years ago

Plan subscription "ends_at" attribute is the date when the subscription ends; for example, when the user has paid for 1 month of service and that month has passed.

As for the "valid_until" attribute of a usage record, it is the date when a usage record needs to be reset. For example, let's say you have a Listings feature, a user has used 10 of them; assuming you have configured Listings to be reset every month, the next time the user uses the Listings feature and the valid_until date has been reached, the Listings usage count is reset back to 0, then increased as per your instructions when using record($feature) method. This feature is optional and is only used when resettable_interval and resettable_count are set. I don't recall why exactly this feature was implemented but it seems unnecessary and redundant 🤔