Cleaning up premium renewal. Needs workflow between upgrading/downgrading plans.

This commit is contained in:
Samuel Clay 2022-01-26 10:53:56 -05:00
parent 26ce1b3e6b
commit cebce60096
4 changed files with 12 additions and 25 deletions

View file

@ -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")

View file

@ -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'

View file

@ -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' }, [

View file

@ -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 %}