mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Adding cancel subscription to account dialog.
This commit is contained in:
parent
be848ff7bd
commit
bb7bd5112e
6 changed files with 56 additions and 6 deletions
|
@ -219,7 +219,24 @@ class Profile(models.Model):
|
|||
payment_gap = (self.premium_expire - most_recent_payment_date).days
|
||||
self.premium_expire = most_recent_payment_date + datetime.timedelta(days=365+payment_gap)
|
||||
self.save()
|
||||
|
||||
def cancel_premium(self):
|
||||
self.cancel_premium_paypal()
|
||||
return self.cancel_premium_stripe()
|
||||
|
||||
def cancel_premium_paypal(self):
|
||||
pass
|
||||
|
||||
def cancel_premium_stripe(self):
|
||||
if not self.stripe_id:
|
||||
return
|
||||
|
||||
stripe.api_key = settings.STRIPE_SECRET
|
||||
stripe_customer = stripe.Customer.retrieve(self.stripe_id)
|
||||
stripe_customer.cancel_subscription()
|
||||
|
||||
return True
|
||||
|
||||
def queue_new_feeds(self, new_feeds=None):
|
||||
if not new_feeds:
|
||||
new_feeds = UserSubscription.objects.filter(user=self.user,
|
||||
|
|
|
@ -15,6 +15,7 @@ urlpatterns = patterns('',
|
|||
url(r'^stripe_form/?', views.stripe_form, name='stripe-form'),
|
||||
url(r'^activities/?', views.load_activities, name='profile-activities'),
|
||||
url(r'^payment_history/?', views.payment_history, name='profile-payment-history'),
|
||||
url(r'^cancel_premium/?', views.cancel_premium, name='profile-cancel-premium'),
|
||||
url(r'^delete_account/?', views.delete_account, name='profile-delete-account'),
|
||||
url(r'^forgot_password_return/?', views.forgot_password_return, name='profile-forgot-password-return'),
|
||||
url(r'^forgot_password/?', views.forgot_password, name='profile-forgot-password'),
|
||||
|
|
|
@ -291,6 +291,13 @@ def payment_history(request):
|
|||
|
||||
return {'payments': history}
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
def cancel_premium(request):
|
||||
canceled = request.user.profile.cancel_premium()
|
||||
|
||||
return {'code': 1 if canceled else -1}
|
||||
|
||||
@login_required
|
||||
@render_to('profile/delete_account.xhtml')
|
||||
def delete_account(request):
|
||||
|
|
|
@ -2535,15 +2535,18 @@ background: transparent;
|
|||
.NB-story-comment .NB-story-comment-like {
|
||||
float: left;
|
||||
width: 16px;
|
||||
background: transparent url('/media/embed/reader/star_grey.png') no-repeat center 0;
|
||||
height: 16px;
|
||||
background: transparent url('/media/embed/icons/circular/g_icn_fav.png') no-repeat center 0;
|
||||
background-size: 14px;
|
||||
text-transform: uppercase;
|
||||
margin-top: -1px;
|
||||
padding: 1px 6px 1px 2px;
|
||||
height: 11px;
|
||||
}
|
||||
.NB-story-comment .NB-story-comment-like:hover,
|
||||
.NB-story-comment .NB-story-comment-like.NB-active {
|
||||
cursor: pointer;
|
||||
background: transparent url('/media/embed/reader/star_green.png') no-repeat center 0;
|
||||
background: transparent url('/media/embed/icons/circular/g_icn_fav_active.png') no-repeat center 0;
|
||||
background-size: 14px;
|
||||
}
|
||||
.NB-story-comment .NB-story-comment-like:active {
|
||||
cursor: pointer;
|
||||
|
@ -7522,7 +7525,8 @@ form.opml_import_form input {
|
|||
background-size: 16px;
|
||||
}
|
||||
.NB-modal-feedchooser .NB-feedchooser-premium-bullets li.NB-5 .NB-feedchooser-premium-bullet-image {
|
||||
background: transparent url('/media/embed/icons/silk/star.png') no-repeat 0 0;
|
||||
background: transparent url('/media/embed/icons/circular/g_icn_fav_active.png') no-repeat 0 0;
|
||||
background-size: 16px;
|
||||
}
|
||||
.NB-modal-feedchooser .NB-feedchooser-premium-bullets li.NB-6 .NB-feedchooser-premium-bullet-image {
|
||||
background: transparent url('/media/embed/icons/silk/lorry.png') no-repeat 0 0;
|
||||
|
@ -7976,6 +7980,7 @@ form.opml_import_form input {
|
|||
}
|
||||
.NB-modal-account .NB-preference-premium .NB-block {
|
||||
margin: 8px 0;
|
||||
display: block;
|
||||
}
|
||||
.NB-modal-account .NB-account-payments {
|
||||
margin: 0;
|
||||
|
|
|
@ -1100,6 +1100,10 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
});
|
||||
},
|
||||
|
||||
cancel_premium_subscription: function(callback, error_callback) {
|
||||
this.make_request('/profile/cancel_premium', {}, callback, error_callback);
|
||||
},
|
||||
|
||||
approve_feed_in_moderation_queue: function(feed_id, date, callback) {
|
||||
this.make_request('/recommendations/approve_feed', {
|
||||
'feed_id' : feed_id,
|
||||
|
|
|
@ -92,14 +92,15 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
|||
' ',
|
||||
NEWSBLUR.utils.format_date(NEWSBLUR.Globals.premium_expire)
|
||||
]),
|
||||
$.make('a', { href: '#', className: 'NB-block NB-account-premium-renew NB-splash-link' }, 'Renew and change your payment amount')
|
||||
$.make('a', { href: '#', className: 'NB-block NB-account-premium-renew NB-splash-link' }, 'Renew and change your payment amount'),
|
||||
$.make('a', { href: '#', className: 'NB-block NB-account-premium-cancel NB-splash-link' }, 'Cancel subscription renewal')
|
||||
]))
|
||||
]),
|
||||
$.make('div', { className: 'NB-preference-label'}, [
|
||||
'Premium'
|
||||
])
|
||||
]),
|
||||
(NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-preference NB-preference-premium' }, [
|
||||
(NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-preference NB-preference-premium-history' }, [
|
||||
$.make('div', { className: 'NB-preference-options' }, [
|
||||
$.make('ul', { className: 'NB-account-payments' }, [
|
||||
$.make('li', { className: 'NB-payments-loading' }, 'Loading...')
|
||||
|
@ -218,6 +219,16 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
|||
});
|
||||
},
|
||||
|
||||
cancel_premium: function() {
|
||||
this.model.cancel_premium_subscription(_.bind(function(data) {
|
||||
$(".NB-preference-premium .NB-error").remove();
|
||||
$(".NB-preference-premium .NB-preference-options").append($.make("div", { className: "NB-error" }, "Your subscription will no longer automatically renew.").fadeIn(500));
|
||||
}, this), _.bind(function(data) {
|
||||
$(".NB-preference-premium .NB-error").remove();
|
||||
$(".NB-preference-premium .NB-preference-options").append($.make("div", { className: "NB-error" }, data.message || "Could not cancel your membership. Contact support.").fadeIn(500));
|
||||
}, this));
|
||||
},
|
||||
|
||||
handle_cancel: function() {
|
||||
var $cancel = $('.NB-modal-cancel', this.$modal);
|
||||
|
||||
|
@ -311,6 +322,11 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
|
|||
|
||||
self.close_and_load_premium();
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-account-premium-cancel' }, function($t, $p) {
|
||||
e.preventDefault();
|
||||
|
||||
self.cancel_premium();
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-link-account-preferences' }, function($t, $p) {
|
||||
e.preventDefault();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue