I developing a referral code system where I am assigning a referral code to each user which is valid for 30 times. It means it should expire when used 30 times.
The idea is that each user can share this referral code to 30 new users. And it should automatically expire if its has been used 30 times.
At the same time once it is used 30 times the user can extend their trial period for 15 days.
Just create a Code datatype, create a new record, assign it to the user, use a field in the Code datatype to track the number of times it is used by other users.
You can check that number when you need so and act accordingly when it has reached the limit.