# Path: ccvpn/common.py
# def get_trial_period_duration():
#     return config.TRIAL_PERIOD_HOURS * timedelta(hours=1)
# 
# Path: payments/models.py
# class Subscription(models.Model):
#     """ Recurring payment subscription. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
#     backend_id = models.CharField(max_length=16, choices=BACKEND_CHOICES)
#     created = models.DateTimeField(auto_now_add=True)
#     period = models.CharField(max_length=16, choices=SUBSCR_PERIOD_CHOICES)
#     last_confirmed_payment = models.DateTimeField(blank=True, null=True)
#     status = models.CharField(max_length=16, choices=SUBSCR_STATUS_CHOICES, default='new')
# 
#     backend_extid = models.CharField(max_length=64, null=True, blank=True)
#     backend_data = JSONField(blank=True)
# 
#     @property
#     def backend(self):
#         """ Returns a global instance of the backend
#         :rtype: BackendBase
#         """
#         return BACKENDS[self.backend_id]
# 
#     @property
#     def months(self):
#         return period_months(self.period)
# 
#     @property
#     def period_amount(self):
#         return self.months * get_price()
# 
#     @property
#     def next_renew(self):
#         """ Approximate date of the next payment """
#         if self.last_confirmed_payment:
#             return self.last_confirmed_payment + timedelta(days=self.months * 30)
#         return self.created + timedelta(days=self.months * 30)
# 
#     @property
#     def monthly_amount(self):
#         return get_price()
# 
#     def create_payment(self):
#         payment = Payment(
#             user=self.user,
#             backend_id=self.backend_id,
#             status='new',
#             time=timedelta(days=30 * self.months),
#             amount=get_price() * self.months,
#             subscription=self,
#         )
#         return payment


import random
from datetime import timedelta
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.utils import timezone
from django.db.models.signals import post_save
from django.dispatch import receiver
from constance import config as site_config
from . import core
from ccvpn.common import get_trial_period_duration
from payments.models import Subscription
    last_vpn_auth = models.DateTimeField(blank=True, null=True)

    referrer = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL,
                                 related_name='referrals')
    referrer_used = models.BooleanField(default=False)
    campaign = models.CharField(blank=True, null=True, max_length=64)

    @property
    def is_paid(self):
        if self.get_subscription():
            return True
        if not self.expiration:
            return False
        return self.expiration > timezone.now()

    @property
    def time_left(self):
        return timezone.now() - self.expiration

    def add_paid_time(self, time):
        now = timezone.now()
        if not self.expiration or self.expiration < now:
            self.expiration = now
        self.expiration += time

        # Propagate update to core
        if core.VPN_AUTH_STORAGE == 'core':
            core.update_user_expiration(self.user)

    def give_trial_period(self):

# Path: ccvpn/common.py
# def get_trial_period_duration():
#     return config.TRIAL_PERIOD_HOURS * timedelta(hours=1)
# 
# Path: payments/models.py
# class Subscription(models.Model):
#     """ Recurring payment subscription. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
#     backend_id = models.CharField(max_length=16, choices=BACKEND_CHOICES)
#     created = models.DateTimeField(auto_now_add=True)
#     period = models.CharField(max_length=16, choices=SUBSCR_PERIOD_CHOICES)
#     last_confirmed_payment = models.DateTimeField(blank=True, null=True)
#     status = models.CharField(max_length=16, choices=SUBSCR_STATUS_CHOICES, default='new')
# 
#     backend_extid = models.CharField(max_length=64, null=True, blank=True)
#     backend_data = JSONField(blank=True)
# 
#     @property
#     def backend(self):
#         """ Returns a global instance of the backend
#         :rtype: BackendBase
#         """
#         return BACKENDS[self.backend_id]
# 
#     @property
#     def months(self):
#         return period_months(self.period)
# 
#     @property
#     def period_amount(self):
#         return self.months * get_price()
# 
#     @property
#     def next_renew(self):
#         """ Approximate date of the next payment """
#         if self.last_confirmed_payment:
#             return self.last_confirmed_payment + timedelta(days=self.months * 30)
#         return self.created + timedelta(days=self.months * 30)
# 
#     @property
#     def monthly_amount(self):
#         return get_price()
# 
#     def create_payment(self):
#         payment = Payment(
#             user=self.user,
#             backend_id=self.backend_id,
#             status='new',
#             time=timedelta(days=30 * self.months),
#             amount=get_price() * self.months,
#             subscription=self,
#         )
#         return payment


# Path: lambdainst/models.py
import random
from datetime import timedelta
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from django.utils import timezone
from django.db.models.signals import post_save
from django.dispatch import receiver
from constance import config as site_config
from . import core
from ccvpn.common import get_trial_period_duration
from payments.models import Subscription

    last_vpn_auth = models.DateTimeField(blank=True, null=True)

    referrer = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL,
                                 related_name='referrals')
    referrer_used = models.BooleanField(default=False)
    campaign = models.CharField(blank=True, null=True, max_length=64)

    @property
    def is_paid(self):
        if self.get_subscription():
            return True
        if not self.expiration:
            return False
        return self.expiration > timezone.now()

    @property
    def time_left(self):
        return timezone.now() - self.expiration

    def add_paid_time(self, time):
        now = timezone.now()
        if not self.expiration or self.expiration < now:
            self.expiration = now
        self.expiration += time

        # Propagate update to core
        if core.VPN_AUTH_STORAGE == 'core':
            core.update_user_expiration(self.user)

    def give_trial_period(self):

        self.add_paid_time(get_trial_period_duration())