Answer the question
In order to leave comments, you need to log in
How to implement a monthly subscription?
I want to implement a monthly subscription for users, the essence is this: the user pays for a month of subscription and exactly after 28 days it disappears and certain privileges are turned off for the user, what is the best way to calculate this period in the database and how to turn off their privileges according to the schedule?
Answer the question
In order to leave comments, you need to log in
Paid: 29 was added to the current date (28 + today, i.e. full - we always give 28) and set the timestamp.
At user actions, we check: the current date is less than or equal to the timestamp, if "YES" - then the privilege is working, "NO" - the privilege period has ended and set the "EXPIRED" flag in the database.
PS: Why is the monthly subscription 28 days and not more?
We make a table of subscriptions, in it the start date, end date, user.
No schedules are needed. Moreover, you can run into the case when you change the user's privileges from subscribed to not subscribed on a schedule, and at this moment the user will renew the subscription. Verification that the user is subscribed must be done each time the user's privileges are requested, by querying the table described above. Condition = user, plus the current time is between two dates. If the entry is found, there are privileges.
If you do not use a calendar month, that is, a subscription for, for example, October 2019, then subscribe for a period (the month must be a month, not 28 days). Оплата
: user code, payment date, subscription start date, end date. The subscription start date is either calculated from the user's last subscription or requested. End date - calculate according to the tariff that is valid for the specified period. You may need a separate table Тариф
: date of introduction, number of days, price.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question