Stabilize dependencies.
[wolnelektury.git] / src / paypal / rest.py
index 1e0811b..3590c6f 100644 (file)
@@ -11,7 +11,7 @@ from django.core.urlresolvers import reverse
 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)
 
@@ -114,5 +114,10 @@ def check_agreement(agreement_id):
         return a.state == 'Active'
 
 
+def user_is_subscribed(user):
+    agreements = BillingAgreementModel.objects.filter(user=user)
+    return any(agreement.check_agreement() for agreement in agreements)
+
+
 def execute_agreement(token):
     return BillingAgreement.execute(token)