determine whether a user is on a paid tier/category?

Discussion in 'Customization & add-ons' started by easyprompter, Jun 26, 2017.

  1. easyprompter

    easyprompter New Member

    Joined:
    Oct 4, 2016
    Messages:
    28
    I have a paid and a free tier - the products are in "free" or "paid" categories. How do I easily determine whether the currently logged in user is in one of the tiers? I'd prefer not to check each product id but basically get "current category"

    I'm open to either Lite or REST

    Thanks
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    Lite API has two option that you can use.

    1. It have const
    PHP:
    Am_Lite::PAID
    and you can use it as search condition:
    PHP:
    Am_Lite::getInstance()->haveSubscriptions(Am_Lite::PAID);

    2. Another option Am_Lite has method to retrieve product_ids from specific category:
    PHP:
    $pids Am_Lite::getInstance()->getCategoryProducts(1);
    You can use this $pids array to check access then:
    PHP:
    Am_Lite::getInstance()->haveSubscriptions($pids);
    Best Regards.
  3. easyprompter

    easyprompter New Member

    Joined:
    Oct 4, 2016
    Messages:
    28
    Interestingly enough, the AM_Lite:pAID thing didn't work for me - it gave me backwards results, but the latter approach is working - thanks!
    What about detecting when a subscription has expired or unpaid?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    First approach works in case user actually pay for access. I guess you just added access to paid product manually from admin interface, is not it?

    Lite API has method that allow to check whether user had access before:
    PHP:
    Am_Lite::getInstance()->hadSubscriptions($search)  
  5. easyprompter

    easyprompter New Member

    Joined:
    Oct 4, 2016
    Messages:
    28
    That's correct - I added access manually. However, I'd like to know the basic "tier" the person is in regardless of how it was added. Here's what i'm doing:
    PHP:
        $pids Am_Lite::getInstance()->getCategoryProducts(2); //paid
        
    $isPaid Am_Lite::getInstance()->haveSubscriptions($pids);
        
    $isActive Am_Lite::getInstance()->isUserActive();
      
        if (
    $isPaid && $isActive) { //do stuff for paid active users }
    My question is
  6. easyprompter

    easyprompter New Member

    Joined:
    Oct 4, 2016
    Messages:
    28
    So after more testing, here's an issue I have with the above code. I add a free subscription, i then add a paid subscription. i then cancel the paid one. the code above still returns true. How can i evaluate the tier that's current and not canceled/expired/disabled?
  7. easyprompter

    easyprompter New Member

    Joined:
    Oct 4, 2016
    Messages:
    28
    hmm ok so my mistake - my paid tier includes a 14 day trial .. once that date passes, it works as expected.

Share This Page