Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions: allow users to create a new subs on incomplete_expired #9910

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions readthedocs/subscriptions/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"""Constants for subscriptions."""
from djstripe.enums import SubscriptionStatus

# Days after the subscription has ended to disable the organization
DISABLE_AFTER_DAYS = 30

# These status are "terminal", meaning the subscription can't be updated.
# Users need to create a new subscription to use our service.
# https://stripe.com/docs/api/subscriptions/object#subscription_object-status.
TERMINAL_STRIPE_STATUS = [
SubscriptionStatus.canceled,
SubscriptionStatus.incomplete_expired,
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ul>
{% endif %}

{% if stripe_subscription.status != 'canceled' %}
{% if stripe_subscription.status not in terminal_stripe_status %}
<dl>
<dt>{% trans "Plan" %}:</dt>
<dd>
Expand Down
28 changes: 18 additions & 10 deletions readthedocs/subscriptions/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,21 @@ def test_user_without_subscription_and_customer(
customer_retrieve_mock.assert_not_called()

def test_user_with_canceled_subscription(self):
self.subscription.status = 'canceled'
self.stripe_subscription.status = SubscriptionStatus.canceled
self.stripe_subscription.save()
self.subscription.save()
resp = self.client.get(reverse('subscription_detail', args=[self.organization.slug]))
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.context["stripe_subscription"], self.stripe_subscription)
# The Manage Subscription form isn't shown, but the Subscribe is.
self.assertNotContains(resp, 'Manage Subscription')
self.assertContains(resp, 'Create Subscription')
for status in [
SubscriptionStatus.canceled,
SubscriptionStatus.incomplete_expired,
]:
self.subscription.status = status
self.stripe_subscription.status = status
self.stripe_subscription.save()
self.subscription.save()
resp = self.client.get(
reverse("subscription_detail", args=[self.organization.slug])
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(
resp.context["stripe_subscription"], self.stripe_subscription
)
# The Manage Subscription form isn't shown, but the Subscribe is.
self.assertNotContains(resp, "Manage Subscription")
self.assertContains(resp, "Create Subscription")
4 changes: 3 additions & 1 deletion readthedocs/subscriptions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from vanilla import DetailView, GenericView

from readthedocs.organizations.views.base import OrganizationMixin
from readthedocs.subscriptions.constants import TERMINAL_STRIPE_STATUS
from readthedocs.subscriptions.forms import PlanForm
from readthedocs.subscriptions.models import Plan
from readthedocs.subscriptions.utils import get_or_create_stripe_customer
Expand Down Expand Up @@ -62,7 +63,7 @@ def redirect_to_checkout(self, form):
stripe_subscription = self.get_object()
if (
not stripe_subscription
or stripe_subscription.status != SubscriptionStatus.canceled
or stripe_subscription.status not in TERMINAL_STRIPE_STATUS
):
raise Http404()

Expand Down Expand Up @@ -113,6 +114,7 @@ def get_object(self):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["terminal_stripe_status"] = TERMINAL_STRIPE_STATUS
stripe_subscription = self.get_object()
if stripe_subscription:
context[
Expand Down