Esempio n. 1
0
 def subscription_update(self):
     cur_sub_active = self.sub_active
     license = persist_db.get('license')
     if not license:
         self.sub_active = False
         self.sub_status = None
         self.sub_amount = None
         self.sub_period_end = None
         self.sub_cancel_at_period_end = None
     else:
         try:
             response = utils.request.get(SUBSCRIPTION_SERVER,
                 json_data={'license': license},
                 timeout=HTTP_REQUEST_TIMEOUT)
             # License key invalid
             if response.status_code == 470:
                 persist_db.remove('license')
                 self.subscription_update()
                 return
             data = response.json()
         except:
             logger.exception('Failed to check subscription status...')
             data = {}
         self.sub_active = data.get('active', True)
         self.sub_status = data.get('status', 'unknown')
         self.sub_amount = data.get('amount')
         self.sub_period_end = data.get('period_end')
         self.sub_cancel_at_period_end = data.get('cancel_at_period_end')
     if cur_sub_active is not None and cur_sub_active != self.sub_active:
         if self.sub_active:
             Event(type=SUBSCRIPTION_ACTIVE)
         else:
             Event(type=SUBSCRIPTION_INACTIVE)
Esempio n. 2
0
 def subscription_dict(self):
     return {
         'license': bool(persist_db.get('license')),
         'active': self.sub_active,
         'status': self.sub_status,
         'amount': self.sub_amount,
         'period_end': self.sub_period_end,
         'cancel_at_period_end': self.sub_cancel_at_period_end,
     }