From cebce600960fa335d11ce77b7eca85ec2e7ea5ab Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 26 Jan 2022 10:53:56 -0500 Subject: [PATCH] Cleaning up premium renewal. Needs workflow between upgrading/downgrading plans. --- apps/profile/models.py | 5 +++-- media/js/newsblur/reader/reader_account.js | 11 +++++++--- .../js/newsblur/reader/reader_feedchooser.js | 20 ------------------- templates/base.html | 1 + 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/apps/profile/models.py b/apps/profile/models.py index 8caddfafb..bc06a22da 100644 --- a/apps/profile/models.py +++ b/apps/profile/models.py @@ -433,7 +433,7 @@ class Profile(models.Model): stripe_subscriptions = stripe.Subscription.list(customer=stripe_customer.id).data for subscription in stripe_subscriptions: - if subscription.plan.active: + if subscription.plan.active and not subscription.cancel_at: active_plan = subscription.plan.id premium_renewal = True break @@ -597,6 +597,7 @@ class Profile(models.Model): def cancel_premium(self): paypal_cancel = self.cancel_premium_paypal() stripe_cancel = self.cancel_premium_stripe() + self.setup_premium_history() return stripe_cancel or paypal_cancel def cancel_premium_paypal(self, second_most_recent_only=False): @@ -647,7 +648,7 @@ class Profile(models.Model): try: subscriptions = stripe.Subscription.list(customer=stripe_customer) for subscription in subscriptions.data: - stripe.Subscription.delete(subscription['id']) + stripe.Subscription.modify(subscription['id'], cancel_at_period_end=True) logging.user(self.user, "~FRCanceling Stripe subscription: %s" % subscription['id']) except stripe.error.InvalidRequestError: logging.user(self.user, "~FRFailed to cancel Stripe subscription") diff --git a/media/js/newsblur/reader/reader_account.js b/media/js/newsblur/reader/reader_account.js index ffc92a127..708166624 100644 --- a/media/js/newsblur/reader/reader_account.js +++ b/media/js/newsblur/reader/reader_account.js @@ -149,7 +149,9 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, { ])), (NEWSBLUR.Globals.is_premium && $.make('div', [ 'Thank you! You have a ', - $.make('b', 'premium account'), + (NEWSBLUR.Globals.is_pro && $.make('b', 'premium pro account')), + (!NEWSBLUR.Globals.is_pro && NEWSBLUR.Globals.is_archive && $.make('b', 'premium archive account')), + (!NEWSBLUR.Globals.is_pro && !NEWSBLUR.Globals.is_archive && NEWSBLUR.Globals.is_premium && $.make('b', 'premium account')), '.' ])) ]), @@ -159,7 +161,8 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, { ]), (NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-preference NB-preference-premium-renew' }, [ $.make('div', { className: 'NB-preference-options' }, [ - $.make('div', { className: 'NB-block' }, 'Your premium account is paid until:'), + (NEWSBLUR.Globals.premium_renewal && $.make('div', { className: 'NB-block' }, 'Your premium account will renew on:')), + (!NEWSBLUR.Globals.premium_renewal && $.make('div', { className: 'NB-block' }, 'Your premium account will downgrade on:')), $.make('div', { className: 'NB-block' }, [ $.make('span', { className: 'NB-raquo' }, '»'), ' ', @@ -184,7 +187,9 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, { ]), (NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-preference NB-preference-premium-cancel' }, [ $.make('div', { className: 'NB-preference-options' }, [ - $.make('a', { href: '#', className: 'NB-block NB-account-premium-cancel NB-modal-submit-button NB-modal-submit-red' }, 'Cancel subscription renewal') + (NEWSBLUR.Globals.premium_renewal && $.make('a', { href: '#', className: 'NB-block NB-account-premium-cancel NB-modal-submit-button NB-modal-submit-red' }, 'Cancel subscription renewal')), + (!NEWSBLUR.Globals.premium_renewal && "Your subscription is no longer active."), + (!NEWSBLUR.Globals.premium_renewal && $.make('a', { href: '#', className: 'NB-block NB-account-premium-renew NB-modal-submit-button NB-modal-submit-green' }, 'Restart your subscription')) ]), $.make('div', { className: 'NB-preference-label'}, [ 'Premium renewal' diff --git a/media/js/newsblur/reader/reader_feedchooser.js b/media/js/newsblur/reader/reader_feedchooser.js index 05f9aa5b4..8686eadd2 100644 --- a/media/js/newsblur/reader/reader_feedchooser.js +++ b/media/js/newsblur/reader/reader_feedchooser.js @@ -66,26 +66,6 @@ _.extend(NEWSBLUR.ReaderFeedchooser.prototype, { // $.make('h2', { className: 'NB-modal-title' }, 'Choose Your '+this.MAX_FEEDS), (!this.options.chooser_only && $.make('div', { className: 'NB-feedchooser-type NB-right' }, [ (!this.options.premium_only && $.make('div', { className: 'NB-feedchooser-porpoise' }, 'OR')), - (NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-feedchooser-info' }, [ - $.make('div', { className: 'NB-feedchooser-info-type' }, [ - $.make('span', { className: 'NB-feedchooser-subtitle-type-prefix' }, 'Thank you'), - ' for going premium!' - ]), - $.make('h2', { className: 'NB-modal-subtitle' }, [ - 'Your premium account is paid until:', - $.make('br'), - $.make('b', { style: 'display: block; margin: 8px 0' }, [ - $.make('span', { className: 'NB-raquo' }, '»'), - ' ', - NEWSBLUR.Globals.premium_expire && NEWSBLUR.utils.format_date(NEWSBLUR.Globals.premium_expire), - (!NEWSBLUR.Globals.premium_expire && $.make('b', "Never gonna expire. Congrats!")) - ]), - 'You can change your payment method and card details. ', - (NEWSBLUR.Globals.premium_expire < new Date) ? - 'This will charge your card immediately.' : - 'You won\'t be charged until this date.' - ]) - ])), $.make('div', { className: 'NB-feedchooser-premium-plan' }, [ $.make('div', { className: 'NB-feedchooser-info' }, [ $.make('div', { className: 'NB-feedchooser-info-type' }, [ diff --git a/templates/base.html b/templates/base.html index 88aa6b4d8..ff8f045d7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,6 +28,7 @@ 'is_admin' : {{ user.is_staff|yesno:"true,false" }}, 'is_staff' : {{ user.is_staff|yesno:"true,false" }}, 'premium_expire' : {% if user.profile.premium_expire %}new Date('{{ user.profile.premium_expire|date:"Y-m-d" }}'){% else %}null{% endif %}, + 'premium_renewal' : {{ user.profile.premium_renewal|yesno:"true,false" }}, 'secret_token' : "{{ user.profile.secret_token }}", 'username' : "{{ user.username|safe }}", {% if user.pk %}'user_id' : {{ user.pk }},{% endif %}