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)