Getting invoice from event Am_Event::SUBSCRIPTION_DELETED

Discussion in 'aMember Pro v.4' started by vitavee, Nov 13, 2015.

Thread Status:
Not open for further replies.
  1. vitavee

    vitavee New Member

    Joined:
    May 19, 2015
    Messages:
    3
    Hello,

    In site.php I have:

    Code:
    Am_Di::getInstance()->hook->add(Am_Event::SUBSCRIPTION_DELETED, 'customOnSubscriptionEnded');
    
    function customOnSubscriptionEnded(Am_Event $event)
    {
        $user = $event->getUser();
    
       // Then there is some custom code to lock the user's license of our product.
    }
    
    How can I also get the invoice related to the ended subscription?

    I want to check if the invoice is still in status RECURRING_ACTIVE or PAID before making any action.

    The reason I need this is to overcome the bug mentioned here:

    http://www.amember.com/forum/threads/issues-with-paypal-plugin.14279/#post-74861
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    You can use the following code:
    PHP:
    $p $event->getProduct();
    $u $event->getUser();
    $access $event->getDi()->accessTable->findFirstBy(array(
         
    'user_id' => $u->pk(),
        
    'product_id' => $p->pk()
    ), 
    'expire_date DESC');

    if (
    $access->invoice_id) {
         
    $invoice $event->getDi()->invoiceTable->load($access->invoice_id);
    }  
    and then access status atribute the following way:
    PHP:
    $invoice->status;
  3. vitavee

    vitavee New Member

    Joined:
    May 19, 2015
    Messages:
    3
    Thanks a lot Caesar, that helps a lot!
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page