diff --git a/r2/r2/controllers/ipn.py b/r2/r2/controllers/ipn.py index 35e30addf..7b1c1a362 100644 --- a/r2/r2/controllers/ipn.py +++ b/r2/r2/controllers/ipn.py @@ -953,8 +953,7 @@ class StripeController(GoldPaymentController): # to cancel the charge g.log.error('no account for stripe invoice: %s', invoice) try: - customer = stripe.Customer.retrieve(customer_id) - customer.delete() + cancel_stripe_subscription(customer_id) except stripe.InvalidRequestError: pass elif status == 'customer.subscription.deleted': @@ -1075,8 +1074,7 @@ class StripeController(GoldPaymentController): if not user.has_stripe_subscription: return - customer = stripe.Customer.retrieve(user.gold_subscr_id) - customer.delete() + cancel_stripe_subscription(user.gold_subscr_id) user.gold_subscr_id = None user._commit() @@ -1389,3 +1387,8 @@ def reverse_gold_purchase(transaction_id): message = 'sorry, but the payment was reversed' send_system_message(recipient, subject, message) update_gold_transaction(transaction_id, 'reversed') + + +def cancel_stripe_subscription(user): + customer = stripe.Customer.retrieve(user.gold_subscr_id) + customer.delete() diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index be03f55d7..2a3e514b1 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -66,9 +66,10 @@ from r2.models import ( from r2.models.bidding import Bid from r2.models.gold import ( calculate_server_seconds, + days_to_pennies, + paypal_subscription_url, gold_payments_by_user, gold_received_by_user, - days_to_pennies, get_current_value_of_month, gold_goal_on, gold_revenue_steady, @@ -1104,7 +1105,12 @@ class PrefApps(Templated): class PrefDelete(Templated): """Preference form for deleting a user's own account.""" - pass + def __init__(self): + self.has_paypal_subscription = c.user.has_paypal_subscription + if self.has_paypal_subscription: + self.paypal_subscr_id = c.user.gold_subscr_id + self.paypal_url = paypal_subscription_url() + Templated.__init__(self) class MessagePage(Reddit): @@ -2042,6 +2048,7 @@ class ProfileBar(Templated): if user.has_paypal_subscription: self.paypal_subscr_id = user.gold_subscr_id + self.paypal_url = paypal_subscription_url() if user.has_stripe_subscription: self.stripe_customer_id = user.gold_subscr_id @@ -2711,7 +2718,7 @@ class GoldSubscription(Templated): if user.has_paypal_subscription: self.has_paypal_subscription = True self.paypal_subscr_id = user.gold_subscr_id - self.paypal_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email + self.paypal_url = paypal_subscription_url() else: self.has_paypal_subscription = False diff --git a/r2/r2/models/gold.py b/r2/r2/models/gold.py index 41066628a..79df02f49 100644 --- a/r2/r2/models/gold.py +++ b/r2/r2/models/gold.py @@ -513,6 +513,10 @@ def get_subscription_details(user): return _get_subscription_details(user.gold_subscr_id) +def paypal_subscription_url(): + return "https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email + + def get_discounted_price(gold_price): discount = float(getattr(g, 'BTC_DISCOUNT', '0')) price = (gold_price.pennies * (1 - discount)) / 100. diff --git a/r2/r2/templates/prefdelete.html b/r2/r2/templates/prefdelete.html index 563fbf61b..602684bbc 100644 --- a/r2/r2/templates/prefdelete.html +++ b/r2/r2/templates/prefdelete.html @@ -23,7 +23,7 @@ <%! from r2.lib.filters import safemarkdown, jssafe %> -<%namespace file="utils.html" import="error_field"/> +<%namespace file="utils.html" import="error_field, text_with_links"/> <%namespace name="utils" file="utils.html"/>

${_("delete your reddit account")}

@@ -42,6 +42,21 @@ +%if thing.has_paypal_subscription: +
+ <%utils:round_field title="${_('please cancel your gold subscription!')}"> +
+
+ ${text_with_links( + _("log in to %%(paypal_link)s to cancel your subscription (%(subscr_id)s).") % dict(subscr_id=thing.paypal_subscr_id), + paypal_link=dict(link_text="paypal", path=thing.paypal_url) + )} +
+
+ +
+%endif +
<%utils:round_field title="${_('why are you deleting this account?')}" description="(${_('optional')})"> diff --git a/r2/r2/templates/profilebar.html b/r2/r2/templates/profilebar.html index 87e1e0fd3..fc6c78c77 100644 --- a/r2/r2/templates/profilebar.html +++ b/r2/r2/templates/profilebar.html @@ -101,11 +101,8 @@ ${_("view gold features/benefits")}
%if hasattr(thing, "paypal_subscr_id"): - <% - paypal_link = ("https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email) - %>
- + ${_("Recurring Paypal subscription")}