diff --git a/app/forms.py b/app/forms.py index 2f02dece..d5531780 100644 --- a/app/forms.py +++ b/app/forms.py @@ -20,9 +20,13 @@ class MemberSignupForm(SignupForm): first_name = forms.CharField(max_length=150) last_name = forms.CharField(max_length=150) gdpr_email_consent = forms.BooleanField( - required=False, - label="Can we email you with news and updates from the Left Book Club?", + required=True, + label="LBC can email me about my books and membership (required)", ) + # promotional_consent = forms.BooleanField( + # required=False, + # label="LBC can email me about special offers and promotions", + # ) field_order = [ "email", @@ -32,7 +36,7 @@ class MemberSignupForm(SignupForm): "password1", # "password2", # ignored when not present "gdpr_email_consent", - "terms_and_conditions", + # "promotional_consent", ] def save(self, request): diff --git a/app/models/django.py b/app/models/django.py index 857a8041..3f8d3abf 100644 --- a/app/models/django.py +++ b/app/models/django.py @@ -1,5 +1,3 @@ -import json - import djstripe import stripe from allauth.account.models import EmailAddress @@ -17,7 +15,7 @@ subscription_with_promocode, ) -from .stripe import LBCProduct +from .stripe import LBCProduct, LBCSubscription def custom_user_casual_name(user: AbstractUser) -> str: @@ -94,10 +92,11 @@ def stripe_customer_id(self) -> str: ] @property - def active_subscription(self) -> djstripe.models.Subscription: + def active_subscription(self) -> LBCSubscription: try: sub = ( - self.stripe_customer.subscriptions.filter( + LBCSubscription.objects.filter( + customer=self.stripe_customer, # Was started + wasn't cancelled status__in=self.valid_subscription_statuses, # Is in period @@ -113,7 +112,7 @@ def active_subscription(self) -> djstripe.models.Subscription: return None @property - def old_subscription(self) -> djstripe.models.Subscription: + def old_subscription(self) -> LBCSubscription: try: sub = ( self.stripe_customer.subscriptions.filter( @@ -140,6 +139,10 @@ def has_overdue_payment(self): == djstripe.enums.SubscriptionStatus.past_due ) + @property + def is_cancelling_member(self): + return self.is_member and self.active_subscription.cancel_at is not None + @property def is_expired_member(self): return not self.is_member and self.old_subscription is not None @@ -161,7 +164,7 @@ def primary_product(self) -> LBCProduct: try: if self.active_subscription is not None: product = get_primary_product_for_djstripe_subscription( - self.active_subscription + self.active_subscription.lbc ) return product except: @@ -190,9 +193,7 @@ def gifts_bought(self): @property def gift_giver(self): try: - gift_giver_subscription = self.active_subscription.gift_giver_subscription - sub = djstripe.models.Subscription.objects.get(id=gift_giver_subscription) - user = sub.customer.subscriber + user = self.active_subscription.gift_giver_subscription.customer.subscriber return user except: return None diff --git a/app/models/stripe.py b/app/models/stripe.py index e731b708..ae80e0d3 100644 --- a/app/models/stripe.py +++ b/app/models/stripe.py @@ -45,9 +45,29 @@ def primary_product_id(self): def customer_id(self): return self.customer.id + @property + def gift_giver_subscription(self): + """ + If this subscription was created as a result of a neighbouring gift subscription + """ + related_subscription_id = self.metadata.get("gift_giver_subscription", None) + if related_subscription_id: + return LBCSubscription.objects.filter(id=related_subscription_id).first() + + @property + def gift_recipient_subscription(self): + """ + If this subscription was created as a result of a neighbouring gift subscription + """ + related_subscription_id = self.metadata.get("gift_recipient_subscription", None) + if related_subscription_id: + return LBCSubscription.objects.filter(id=related_subscription_id).first() + + @property def is_gift_giver(self): self.metadata.get("gift_mode", None) is not None + @property def is_gift_receiver(self): self.metadata.get("gift_giver_subscription", None) is not None @@ -143,14 +163,6 @@ def get_prices_for_country(self, iso_a2: str, **kwargs): product=self.id, active=True, metadata__shipping=zone.code, **kwargs ).order_by("unit_amount") - def gift_giver_subscription(self): - """ - If this subscription was created as a result of a neighbouring gift subscription - """ - related_subscription_id = self.metadata.get("gift_giver_subscription", None) - if related_subscription_id: - return djstripe.models.Subscription.get(id=related_subscription_id) - @property def book_types(self): book_types = self.metadata.get("book_types", None) @@ -159,6 +171,7 @@ def book_types(self): return book_types return list() + @property def current_book(self): from app.models.wagtail import BookPage diff --git a/app/settings/base.py b/app/settings/base.py index 7d4af49b..a646e3e1 100644 --- a/app/settings/base.py +++ b/app/settings/base.py @@ -304,6 +304,7 @@ SHOPIFY_COLLECTION_ID = os.environ.get("SHOPIFY_COLLECTION_ID", "402936398057") SHOPIFY_PRIVATE_APP_PASSWORD = os.environ.get("SHOPIFY_PRIVATE_APP_PASSWORD", None) SHOPIFY_APP_API_SECRET = os.environ.get("SHOPIFY_APP_API_SECRET", "") +SHOPIFY_WEBHOOK_PATH = os.environ.get("SHOPIFY_WEBHOOK_PATH", "shopify/webhooks/") # CSP X_FRAME_OPTIONS = "SAMEORIGIN" diff --git a/app/signals.py b/app/signals.py index b4738f17..77d92c45 100644 --- a/app/signals.py +++ b/app/signals.py @@ -61,6 +61,8 @@ def cancel_gift_recipient_subscription(event, **kwargs): def sync(*args, data: shopify.Product, **kwargs): from app.models.wagtail import BaseShopifyProductPage + print("products_updated", data) + product_id = data.get("id") print("Product", product_id, "was updated") BookPage.sync_from_shopify_product_id(product_id) @@ -70,6 +72,8 @@ def sync(*args, data: shopify.Product, **kwargs): def sync(*args, data: shopify.Product, **kwargs): from app.models.wagtail import BaseShopifyProductPage + print("products_create", data) + product_id = data.get("id") print("Product", product_id, "was created") BookPage.sync_from_shopify_product_id(product_id) @@ -79,6 +83,8 @@ def sync(*args, data: shopify.Product, **kwargs): def sync(*args, data: shopify.Product, **kwargs): from app.models.wagtail import BaseShopifyProductPage + print("products_delete", data) + product_id = data.get("id") print("Product", product_id, "was deleted") BookPage.objects.filter(shopify_product_id=product_id).delete() diff --git a/app/templates/account/cancel.html b/app/templates/account/cancel.html index efc9da01..911f1119 100644 --- a/app/templates/account/cancel.html +++ b/app/templates/account/cancel.html @@ -5,20 +5,51 @@ {% block account_content %}
Membership will expire on {{subscription.cancel_at}}
- {% elif gift_mode %} - {% comment %} Cancelling a gift plan {% endcomment %} + {% elif subscription.gift_recipient_subscription %} + {% comment %} Cancelling a gift giver subscription {% endcomment %}- You'll no longer be billed by LBC. The gift membership that was redeemed - {% if gift_recipient_subscription %} by {{ gift_recipient_subscription.customer.name }} {% endif %} - will end on {{ subscription.current_period_end }}. + {% if subscription.gift_recipient_subscription %} + This gift card was redeemed by {{ subscription.gift_recipient_subscription.customer.subscriber }}. + If you cancel, they'll stop receiving books on {{ subscription.current_period_end }}. + {% else %} + This gift card was never redeemed. + {% endif %} + You'll no longer be billed by LBC.
+ {% elif subscription.gift_giver_subscription %} + {% comment %} Cancelling a gift recipient subscription {% endcomment %} ++ Your membership is being paid for by {{ user.gift_giver }}. If you cancel, they'll no longer pay your membership fee and your membership will will end on {{ subscription.current_period_end }}. +
+