From 172fe450eb7d271033744c00c337abd15691f17e Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Sun, 11 Feb 2024 21:46:30 +0000 Subject: [PATCH] Fix #1294 Show subscripton ended_at (cancelled at) date on subscribers list if subscription has ended --- ...6225c6_add_subscription_stripe_ended_at.py | 25 +++++++++++++++++++ subscribie/blueprints/admin/subscription.py | 7 +++++- .../admin/templates/admin/subscribers.html | 5 ++++ subscribie/models.py | 2 ++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/48074e6225c6_add_subscription_stripe_ended_at.py diff --git a/migrations/versions/48074e6225c6_add_subscription_stripe_ended_at.py b/migrations/versions/48074e6225c6_add_subscription_stripe_ended_at.py new file mode 100644 index 00000000..37868d5c --- /dev/null +++ b/migrations/versions/48074e6225c6_add_subscription_stripe_ended_at.py @@ -0,0 +1,25 @@ +"""add subscription stripe_ended_at + +Revision ID: 48074e6225c6 +Revises: 207556b3039b +Create Date: 2024-02-11 17:21:19.287478 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "48074e6225c6" +down_revision = "207556b3039b" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("subscription", schema=None) as batch_op: + batch_op.add_column(sa.Column("stripe_ended_at", sa.Integer(), nullable=True)) + + +def downgrade(): + pass diff --git a/subscribie/blueprints/admin/subscription.py b/subscribie/blueprints/admin/subscription.py index 66275181..06857c60 100644 --- a/subscribie/blueprints/admin/subscription.py +++ b/subscribie/blueprints/admin/subscription.py @@ -24,7 +24,9 @@ def update_stripe_subscription_statuses(app): stripe.api_key = get_stripe_secret_key() connect_account = get_stripe_connect_account() if stripe.api_key is None: - log.warning("Stripe api key not set refusing to update subscription statuses") # noqa: E501 + log.warning( + "Stripe api key not set refusing to update subscription statuses" + ) # noqa: E501 if connect_account is None: log.warning( "Stripe connect account not set. Refusing to update subscription statuses" # noqa: E501 @@ -53,6 +55,9 @@ def update_stripe_subscription_statuses(app): ) subscription.stripe_status = stripeSubscription.status + # Update stripeSubscription.ended_at if stripe subscription has ended # noqa: E501 + if stripeSubscription.ended_at is not None: + subscription.stripe_ended_at = stripeSubscription.ended_at log.info(subscription.stripe_status) log.info(subscription.stripe_subscription_id) database.session.commit() diff --git a/subscribie/blueprints/admin/templates/admin/subscribers.html b/subscribie/blueprints/admin/templates/admin/subscribers.html index 9953cc5e..bdcca11a 100644 --- a/subscribie/blueprints/admin/templates/admin/subscribers.html +++ b/subscribie/blueprints/admin/templates/admin/subscribers.html @@ -136,6 +136,11 @@

Search...

Paid {% endif %} + {% if subscription.stripe_status == 'canceled' %} +
  • + Date ended at: {{ subscription.stripe_ended_at | timestampToDate }} +
  • + {% endif %} {% if subscription.stripe_cancel_at %} Automatically Cancels at: {{ subscription.stripe_cancel_at | timestampToDate }} diff --git a/subscribie/models.py b/subscribie/models.py index 710b8b2b..697424c2 100644 --- a/subscribie/models.py +++ b/subscribie/models.py @@ -383,6 +383,8 @@ class Subscription(database.Model): stripe_subscription_id = database.Column(database.String()) stripe_external_id = database.Column(database.String()) stripe_status = database.Column(database.String()) + stripe_ended_at = database.Column(database.Integer(), nullable=True) + # stripe_cancel_at is the 'live' setting (which may change) # and must be checked via cron/webhooks. Plan.cancel_at allows # a shop owner to set a cancel_at date before subscribers sign-up,