mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-21 04:48:08 -05:00
Cancel subscription or warn on account delete
If a user has a Stripe subscription, we can delete the customer when the account is deleted. If there's a paypal subscription, a link to paypal will be shown to remind the user to cancel the subscription.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
<h1>${_("delete your reddit account")}</h1>
|
||||
@@ -42,6 +42,21 @@
|
||||
</%utils:round_field>
|
||||
</div>
|
||||
|
||||
%if thing.has_paypal_subscription:
|
||||
<div class="spacer">
|
||||
<%utils:round_field title="${_('please cancel your gold subscription!')}">
|
||||
<div class="rounded white-field">
|
||||
<div class="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)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</%utils:round_field>
|
||||
</div>
|
||||
%endif
|
||||
|
||||
<div class="spacer">
|
||||
<%utils:round_field title="${_('why are you deleting this account?')}" description="(${_('optional')})">
|
||||
<textarea name="delete_message" id="delete-message"></textarea>
|
||||
|
||||
@@ -101,11 +101,8 @@
|
||||
<a href="/gold/about">${_("view gold features/benefits")}</a>
|
||||
</div>
|
||||
%if hasattr(thing, "paypal_subscr_id"):
|
||||
<%
|
||||
paypal_link = ("https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email)
|
||||
%>
|
||||
<div>
|
||||
<a href=${paypal_link}>
|
||||
<a href=${thing.paypal_url}>
|
||||
${_("Recurring Paypal subscription")}
|
||||
</a>
|
||||
 
|
||||
|
||||
Reference in New Issue
Block a user