Skip to content

Commit

Permalink
SUSPENDED subscriptions can be renewed
Browse files Browse the repository at this point in the history
  • Loading branch information
jarshwah committed Dec 29, 2020
1 parent 5824c87 commit 82cdb23
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.1.1 (2020-12-29)

- Subscriptions in `SUSPENDED` state can now be `renewed()` which solves an issue
with payment callbacks correctly identifying a payment success.

## v2.1.0 (2020-06-01)

- Introduced a boolean setting `SUBSCRIPTIONS_STUCK_RETRY`, defaulting to `False`, that will
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ readme = "README.md"
homepage = "http://github.com/kogan/"
repository = "http://github.com/kogan/django-subscriptions/"
documentation = "http://github.com/kogan/django-subscriptions/"
version = "2.1.0"
version = "2.1.1"
description = "A django package for managing subscription states"
license = "BSD-3-Clause"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/subscriptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.0"
__version__ = "2.1.1"
4 changes: 3 additions & 1 deletion src/subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def post_renew(self):

@fsm_log_description
@transition(
field=state, source=[State.ACTIVE, State.RENEWING, State.ERROR], target=State.ACTIVE
field=state,
source=[State.ACTIVE, State.RENEWING, State.SUSPENDED, State.ERROR],
target=State.ACTIVE,
)
def renewed(self, new_end_date, new_reference, description=None):
self.reason = ""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,12 @@ def test_trigger_stuck_retry(self):
self.assertNotEqual(due.state, due_fresh.state)
self.assertEqual(not_due.state, not_due_fresh.state)
self.assertEqual(ended.state, ended_fresh.state)

def test_renewed_from_suspended(self):
"""
A subscription in SUSPENDED can be RENEWED if new information arrives after
the fact.
"""
sub = Subscription.objects.create(state=State.SUSPENDED, end=self.days_ago)
sub.renewed(timezone.now() + timedelta(days=7), "MYREF", "Renewed from SUSPENDED")
self.assertEqual(sub.state, State.ACTIVE)

0 comments on commit 82cdb23

Please sign in to comment.