Skip to content

Commit 5790137

Browse files
authored
Updates to correct Stripe API for subscription cancellation (#842)
1 parent b50db74 commit 5790137

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

handlers/account.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def get(self):
202202
cancel_flag = "canceled" in (user.stripe_plan_id or "")
203203
updated_flag = self.get_argument("update", "") == "1"
204204
migrated_flag = self.get_argument("migrated", 0)
205+
cancel_error = self.get_argument("cancel-error", "") == "1"
205206
past_due = False
206207
source_card_type = None
207208
source_last_4 = None
@@ -246,6 +247,7 @@ def get(self):
246247
updated_flag=updated_flag,
247248
migrated_flag=migrated_flag,
248249
cancel_flag=cancel_flag,
250+
cancel_error=cancel_error,
249251
production_site=production_site)
250252

251253
@tornado.web.authenticated
@@ -1112,13 +1114,21 @@ class PaymentCancelHandler(BaseHandler):
11121114
@tornado.web.authenticated
11131115
def post(self):
11141116
user = self.get_current_user_object()
1117+
cancel_comments = self.get_argument("cancel_comments", "")
1118+
cancel_reason = self.get_argument("cancel_reason", "")
11151119
if user.stripe_customer_id:
11161120
try:
11171121
customer = stripe.Customer.retrieve(user.stripe_customer_id, expand=["subscriptions"])
11181122
if customer and customer.subscriptions.total_count > 0:
11191123
subscription = customer.subscriptions.data[0]
11201124
if subscription:
1121-
subscription.delete(at_period_end=True)
1125+
cancellation_details = {
1126+
"feedback": cancel_reason,
1127+
"comment": cancel_comments,
1128+
}
1129+
stripe.Subscription.modify(
1130+
subscription.id, cancel_at_period_end=True,
1131+
cancellation_details=cancellation_details)
11221132
if user.stripe_plan_id and ("-canceled" not in user.stripe_plan_id):
11231133
user.stripe_plan_id = user.stripe_plan_id + "-canceled"
11241134
user.stripe_plan_rate = None
@@ -1133,7 +1143,7 @@ def post(self):
11331143

11341144
payment_notifications(user, 'cancellation')
11351145
except stripe.error.InvalidRequestError:
1136-
pass
1146+
self.redirect('/account/settings?cancel-error=1')
11371147
return self.redirect('/account/settings?cancel=1')
11381148

11391149
@tornado.web.authenticated

templates/account/payment-cancel.html

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,56 @@
44
<div class="content content-membership">
55
<h1 class="thank-you">Canceling</h1>
66
<p>
7-
Thanks for trying us out, we're sorry to see you go but understand the site isn't for everyone.
7+
Thanks for trying us out, we&rsquo;re sorry to see you go but understand the site isn&rsquo;t for everyone.
88
</p>
9+
910
<p>
10-
To cancel your account right now, click this button to confirm your the cancellation of your
11-
subscription:
11+
Before you go, please let us know why you&rsquo;re canceling your subscription. Your feedback is not
12+
required, but appreciated!
1213
</p>
1314

14-
<form action="/account/payment/cancel" method="POST">
15-
{{ xsrf_form_html() }}
16-
<input type="submit"
17-
class="subscription-button" value="Yes, Please Cancel" border="0">
18-
</form>
15+
<div class="fun-form">
16+
<form action="/account/payment/cancel" method="POST">
17+
{{ xsrf_form_html() }}
18+
19+
<div class="field">
20+
<label for="cancel-reason">Cancellation Reason:</label>
21+
<div class="field-input">
22+
<select name="cancel_reason" id="cancel-reason">
23+
<option>--</option>
24+
<option value="customer_service">Customer service issue</option>
25+
<option value="missing_features">MLTSHP is missing feature(s) I&rsquo;d like</option>
26+
<option value="switched_service">I found an alternative</option>
27+
<option value="too_complex">MLTSHP is complex or hard to use</option>
28+
<option value="too_expensive">MLTSHP is too expensive</option>
29+
<option value="unused">Not using it enough</option>
30+
<option value="other">Other reason not listed</option>
31+
</select>
32+
</div>
33+
<div class="field-help">
34+
Please let us know why you&rsquo;re canceling!
35+
</div>
36+
</div>
37+
38+
<div class="field">
39+
<label for="cancel-comments">Any additional comments?</label>
40+
<div class="field-input">
41+
<textarea name="cancel_comments" id="cancel-comments" rows="4" cols="40"></textarea>
42+
</div>
43+
</div>
44+
45+
<div class="field field-submit">
46+
<input class="btn btn-danger" type="submit"
47+
class="subscription-button" value="Yes, Please Cancel">
48+
</div>
49+
</form>
50+
</div>
1951

2052
<div class="clear"><!-- --></div>
53+
2154
<p>
2255
If you have any questions or need help please email us at <a href="mailto:hello@mltshp.com">hello@mltshp.com</a>
23-
and we'll get back to you as soon as possible.
56+
and we&rsquo;ll get back to you as soon as possible.
2457
</p>
2558
</div>
2659
{% end %}

templates/account/settings.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
{% block main %}
3333
<div class="content content-settings">
34+
{% if cancel_error %}
35+
<div class="alert alert--danger">
36+
<strong>We weren&rsquo;t able to cancel your subscription.</strong>
37+
Please <a href="mailto:hello@mltshp.com">contact us</a>
38+
about this and we&rsquo;ll take care of it.
39+
</div>
40+
{% end %}
41+
3442
<div class="settings-header">
3543
<h1>Your Settings</h1>
3644
<div class="settings-navigation">
@@ -134,7 +142,7 @@ <h3>MLKSHK Restore Status</h3>
134142
Your MLKSHK posts are safe and sound and ready to be restored. Click the button below
135143
to start restoring your content.
136144
</p>
137-
<a class="btn btn-primary btn-shadow" href="/account/mlkshk-migrate">Let's Go!</a>
145+
<a class="btn btn-primary btn-shadow" href="/account/mlkshk-migrate">Let&rsquo;s Go!</a>
138146
{% end %}
139147
</div>
140148
</div>
@@ -213,13 +221,13 @@ <h4>Your Membership Plan: <a href="/account/membership">{{ plan_name }}</a></h4>
213221
{% end %}
214222

215223
{% if not cancel_flag %}
216-
<p>If you'd like to cancel your subscription <a href="/account/payment/cancel">you can do so here</a>.</p>
224+
<p>If you&rsquo;d like to cancel your subscription <a href="/account/payment/cancel">you can do so here</a>.</p>
217225
{% end %}
218226
{% else %}
219227
{% if user.stripe_customer_id %}
220228
<p>
221229
You have no active MLTSHP subscription. <a href="/account/membership">Click here to re-subscribe</a>
222-
if you'd like to support MLTSHP!
230+
if you&rsquo;d like to support MLTSHP!
223231
</p>
224232

225233
<p><hr></p>
@@ -245,7 +253,7 @@ <h4>Your Membership Plan: <a href="/account/membership">{{ plan_name }}</a></h4>
245253

246254
{% else %}
247255
<p>
248-
You are currently using a free account. If you'd like
256+
You are currently using a free account. If you&rsquo;d like
249257
to support MLTSHP and get some nifty new benefits you can
250258
<a href="/account/membership">upgrade to a paid account</a>.
251259
</p>

0 commit comments

Comments
 (0)