Skip to content

Commit

Permalink
Fix #1294 Show subscripton ended_at (cancelled at) date on subscriber…
Browse files Browse the repository at this point in the history
…s list if subscription has ended
  • Loading branch information
chrisjsimpson committed Feb 11, 2024
1 parent a0406b8 commit 172fe45
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion subscribie/blueprints/admin/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions subscribie/blueprints/admin/templates/admin/subscribers.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ <h4>Search...</h4>
<span class="subscription-status">Paid</span>
{% endif %}
</li>
{% if subscription.stripe_status == 'canceled' %}
<li>
<strong>Date ended at:</strong> {{ subscription.stripe_ended_at | timestampToDate }}
</li>
{% endif %}
{% if subscription.stripe_cancel_at %}
<strong>Automatically Cancels at:</strong>
{{ subscription.stripe_cancel_at | timestampToDate }}
Expand Down
2 changes: 2 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 172fe45

Please sign in to comment.