from django.http import HttpResponse
from django.utils.encoding import force_unicode
+from paypal.rest import user_is_subscribed
from reporting.utils import read_chunks
# Use the system (hardware-based) random number generator if it exists.
def is_subscribed(user):
- return user.is_authenticated() # TEMPORARY
+ return user_is_subscribed(user)
plan = models.ForeignKey(BillingPlan)
active = models.BooleanField(max_length=32)
token = models.CharField(max_length=32)
+
+ def get_agreement(self):
+ from .rest import get_agreement
+ return get_agreement(self.agreement_id)
+
+ def check_agreement(self):
+ from .rest import check_agreement
+ return check_agreement(self.agreement_id)
from django.utils import timezone
from paypalrestsdk import BillingPlan, BillingAgreement, ResourceNotFound
from django.conf import settings
-from .models import BillingPlan as BillingPlanModel
+from .models import BillingPlan as BillingPlanModel, BillingAgreement as BillingAgreementModel
paypalrestsdk.configure(settings.PAYPAL_CONFIG)
return a.state == 'Active'
+def user_is_subscribed(user):
+ try:
+ agreement = BillingAgreementModel.objects.get(user=user)
+ except BillingAgreementModel.DoesNotExist:
+ return False
+ return agreement.check_agreement()
+
+
def execute_agreement(token):
return BillingAgreement.execute(token)