diff --git a/r2/r2/controllers/ipn.py b/r2/r2/controllers/ipn.py index 5d82257a0..0d809a8e0 100644 --- a/r2/r2/controllers/ipn.py +++ b/r2/r2/controllers/ipn.py @@ -849,10 +849,10 @@ class StripeController(GoldPaymentController): @classmethod @handle_stripe_error def set_creditcard(cls, form, user, token): - if not getattr(user, 'stripe_customer_id', None): + if not user.has_stripe_subscription: return - customer = stripe.Customer.retrieve(user.stripe_customer_id) + customer = stripe.Customer.retrieve(user.gold_subscr_id) customer.card = token customer.save() return customer @@ -860,13 +860,13 @@ class StripeController(GoldPaymentController): @classmethod @handle_stripe_error def cancel_subscription(cls, user): - if not getattr(user, 'stripe_customer_id', None): + if not user.has_stripe_subscription: return - customer = stripe.Customer.retrieve(user.stripe_customer_id) + customer = stripe.Customer.retrieve(user.gold_subscr_id) customer.delete() - user.stripe_customer_id = None + user.gold_subscr_id = None user._commit() subject = _('your gold subscription has been cancelled') message = _('if you have any questions please email %(email)s') @@ -915,7 +915,7 @@ class StripeController(GoldPaymentController): return if period: - c.user.stripe_customer_id = customer.id + c.user.gold_subscr_id = customer.id c.user._commit() status = _('subscription created') diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index dac26506f..318e2eb39 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1703,10 +1703,10 @@ class ProfileBar(Templated): self.gold_remaining = timeuntil(self.gold_expiration, precision) - if hasattr(user, "gold_subscr_id"): - self.gold_subscr_id = user.gold_subscr_id - if hasattr(user, "stripe_customer_id"): - self.stripe_customer_id = user.stripe_customer_id + if user.has_paypal_subscription: + self.paypal_subscr_id = user.gold_subscr_id + if user.has_stripe_subscription: + self.stripe_customer_id = user.gold_subscr_id if ((user._id == c.user._id or c.user_is_admin) and user.gold_creddits > 0): @@ -2257,7 +2257,7 @@ class GoldPayment(Templated): class GoldSubscription(Templated): def __init__(self, user): - if hasattr(user, 'stripe_customer_id'): + if user.has_stripe_subscription: details = get_subscription_details(user) else: details = None diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index 74c96c96b..6d51c8d65 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -614,8 +614,17 @@ class Account(Thing): @property def has_gold_subscription(self): - return bool(getattr(self, 'gold_subscr_id', None) or - getattr(self, 'stripe_customer_id', None)) + return bool(getattr(self, 'gold_subscr_id', None)) + + @property + def has_paypal_subscription(self): + return (self.has_gold_subscription and + not self.gold_subscr_id.startswith('cus_')) + + @property + def has_stripe_subscription(self): + return (self.has_gold_subscription and + self.gold_subscr_id.startswith('cus_')) class FakeAccount(Account): diff --git a/r2/r2/models/gold.py b/r2/r2/models/gold.py index bd41aba82..e056b11b4 100644 --- a/r2/r2/models/gold.py +++ b/r2/r2/models/gold.py @@ -312,7 +312,7 @@ def gold_goal_on(date): def account_from_stripe_customer_id(stripe_customer_id): - q = Account._query(Account.c.stripe_customer_id == stripe_customer_id, + q = Account._query(Account.c.gold_subscr_id == stripe_customer_id, Account.c._spam == (True, False), data=True) return next(iter(q), None) @@ -339,7 +339,7 @@ def _get_subscription_details(stripe_customer_id): def get_subscription_details(user): - if not getattr(user, 'stripe_customer_id', None): + if not getattr(user, 'gold_subscr_id', None): return - return _get_subscription_details(user.stripe_customer_id) + return _get_subscription_details(user.gold_subscr_id) diff --git a/r2/r2/templates/profilebar.html b/r2/r2/templates/profilebar.html index cb280018d..2fccb39e4 100644 --- a/r2/r2/templates/profilebar.html +++ b/r2/r2/templates/profilebar.html @@ -124,7 +124,7 @@
${_("of reddit gold remaining")} - %if getattr(thing, "gold_subscr_id", None): + %if getattr(thing, "paypal_subscr_id", None): <% paypal_link = ("https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email) %>