def update(): current_plan = current_user.subscription.plan active_plan = Subscription.get_plan_by_id(current_plan) new_plan = Subscription.get_new_plan(request.form.keys()) plan = Subscription.get_plan_by_id(new_plan) # Guard against an invalid, missing or identical plan. is_same_plan = new_plan == active_plan['id'] if ((new_plan is not None and plan is None) or is_same_plan) and \ request.method == 'POST': return redirect(url_for('billing.update')) form = UpdateSubscriptionForm(coupon_code=current_user.subscription.coupon) if form.validate_on_submit(): subscription = Subscription() updated = subscription.update(user=current_user, coupon=request.form.get('coupon_code'), plan=plan.get('id')) if updated: flash('Your subscription has been updated.', 'success') return redirect(url_for('user.settings')) return render_template('billing/pricing.html', form=form, plans=settings.STRIPE_PLANS, active_plan=active_plan)
def pricing(): if current_user.is_authenticated and current_user.subscription: return redirect(url_for('billing.update')) form = UpdateSubscriptionForm() return render_template('billing/pricing.html', form=form, plans=settings.STRIPE_PLANS)