Hooks and Updates

Discussion in 'Customization & add-ons' started by frobark, Nov 19, 2014.

  1. frobark

    frobark New Member

    Joined:
    Jan 11, 2012
    Messages:
    3
    Hi,

    In our site, in addition to the protected folders we have a credits system that limits how many times a user can perform a certain action under each specific plan.

    e.g.
    Plan 1 = 10 credits
    Plan 2 = 25 credits
    etc.

    These credits need to be updated every month on the renewal data of their subscription if they took a monthly plan, or on the same day each month if on a yearly plan.

    I am trying to work out the best way to implement this and which hooks I will need to make use of.

    I already have a separate user table set up in the main app to manage this.

    This thread has a lot of what I need but I am not sure if the events are right for me or not, and it only covers the first execution.

    http://www.amember.com/forum/threads/running-custom-script.17632/

    So the main actions are:

    1. When a new user has successfully paid for their subscription, they get XX credits.

    This is the same as the above thread, but wouldn't INVOICE_STARTED be a better event to use, as it occurs after payment?

    e.g. if I credit them before they pay then someone could potentially start an "upgrade" to a higher plan to get their credits then cancel the process before they pay, while still keeping their old plan which gives them access to the app itself and the new credits.

    2. Every month increment user accounts with an amount of credits according to their plan

    This needs to fire every time a monthly plan is renewed or every month after they join if they are on an annual plan.

    Is there an event for this? I would hope there is one for the renewals, but the yearly ones probably not. In which case, might it be better to have a daily cron job that checks all memberships that renewed in the last 24 hours, or which have a yearly cycle but were started on the same day (or less for days 29-31) and were still active?

    Any ideas on how I might achieve this.

    3. This is a side question, but we would like to also implement one off purchases of extra credits for those people who exceed their plan, but don't want to upgrade to a larger one. What is the best way to do this?

    The best I can think of is a short term "subscription" of 1 second but which has an attached event handler that increments the user's account without affecting their primary subscription.

Share This Page