def bulk_delete(cls, ids): """ Override the general bulk_delete method because we need to delete them one at a time while also deleting them on Stripe. :param ids: List of ids to be deleted :type ids: list :return: int """ delete_count = 0 for id in ids: user = User.query.get(id) if user is None: continue if user.payment_id is None: user.delete() else: subscription = Subscription() cancelled = subscription.cancel(user=user) # If successful, delete it locally. if cancelled: user.delete() delete_count += 1 return delete_count
def users_cancel_subscription(): form = UserCancelSubscriptionForm() if form.validate_on_submit(): user = User.query.get(request.form.get('id')) if user: subscription = Subscription() if subscription.cancel(user): flash('Subscription has been cancelled for {0}.' .format(user.name), 'success') else: flash('No subscription was cancelled, something went wrong.', 'error') return redirect(url_for('admin.users'))
def cancel(): if not current_user.subscription: flash(_('You do not have an active subscription.'), 'error') return redirect(url_for('user.settings')) form = CancelSubscriptionForm() if form.validate_on_submit(): subscription = Subscription() cancelled = subscription.cancel(user=current_user) if cancelled: flash( _('Sorry to see you go, your subscription has been ' 'cancelled.'), 'success') return redirect(url_for('user.settings')) return render_template('billing/cancel.html', form=form)