def change_plan(request): form = PlanForm(request.POST) try: current_plan = request.user.customer.current_subscription.plan except CurrentSubscription.DoesNotExist: current_plan = None if form.is_valid(): try: request.user.customer.subscribe(form.cleaned_data["plan"]) data = { "form": PlanForm(initial={ "plan": current_plan }), "plan": current_plan, "name": settings.PAYMENTS_PLANS[current_plan]["name"] } except stripe.StripeError, e: if current_plan: name = settings.PAYMENTS_PLANS[current_plan]["name"] else: name = "" data = { "form": PlanForm(initial={ "plan": current_plan }), "plan": current_plan, "name": name, "error": e.message }
def change_plan(request): form = PlanForm(request.POST) if form.is_valid(): try: request.user.customer.purchase(form.cleaned_data["plan"]) data = { "form": PlanForm(initial={ "plan": request.user.customer.plan }), "plan": request.user.customer.plan, "name": settings.PAYMENTS_PLANS[request.user.customer.plan]["name"] } except stripe.StripeError, e: if request.user.customer.plan: name = settings.PAYMENTS_PLANS[request.user.customer.plan]["name"] else: name = "" data = { "form": PlanForm(initial={ "plan": request.user.customer.plan }), "plan": request.user.customer.plan, "name": name, "error": e.message }
def change_plan_form(context): context.update({ "form": PlanForm(initial={ "plan": context["request"].user.customer.current_subscription.plan }) }) return context
def change_plan(request): form = PlanForm(request.POST) if form.is_valid(): try: request.user.customer.purchase(form.cleaned_data["plan"]) data = { "form": PlanForm(initial={"plan": request.user.customer.plan}), "plan": request.user.customer.plan, "name": settings.PAYMENTS_PLANS[request.user.customer.plan]["name"] } except stripe.StripeError, e: if request.user.customer.plan: name = settings.PAYMENTS_PLANS[ request.user.customer.plan]["name"] else: name = "" data = { "form": PlanForm(initial={"plan": request.user.customer.plan}), "plan": request.user.customer.plan, "name": name, "error": e.message }
def subscribe_form(context): context.update({"form": PlanForm()}) return context