smeunus's avatar
Level 12

Help me to understand how to deal with subscriptions, membership.

Assume I have three plan for membership. monthly - yearly - forever

I can charge user based on plan.

How do I deal with when their subscription expired? how to determine that a users subscription is expired?

0 likes
6 replies
Nakov's avatar

@smeunus I would create a task and schedule it to run every night for example. And it will check for the subscription expiry date on users.

https://laravel.com/docs/master/scheduling#introduction

You can have a logic in it for example if expired today, send them a friendly reminder over email, and allow that for 2/3 days. If no action taken by the user then disable their account. For example a datetime field expired_at if set to a value instead of null it means that the user has no active subscription.

2 likes
smeunus's avatar
Level 12

Hi @nakov thank you for the reply. I'm working on Your second suggestion.

Nakov's avatar

@smeunus keep in mind my first answer is only one suggestion :) you must have the CRON job to check every night for example.

1 like
EtiennePeters's avatar

@smeunus I second @nakov on the logic for periodic processing (CRON). It is also wise to keep all the use- and edgecases in mind. For example:

  • Is it possible to switch between plans?
  • Is it possible to have multiple plans at once?
  • Is the functionality for auto-renewal required? If yes, what is the logic behind this?
  • Should a user have the option to pause/restart it's subscription?

On a second note: with this kind of periodic processing, a form of security in your code would be wise to counter the event of data being altered by two (or more) executions of your code (and therefore malformed). For example, this can be accomplished by a processing column in your DB which will be filled with a timestamp (UUID4 is my preference) when the code is executed.

If the job would run only one time at night, this shouldn't be too much of a problem. Nonetheless, this can come in handy at some point during developing.

2 likes

Please or to participate in this conversation.