def register(request): user = None # checks if the http request is POST if request.method == 'POST': form = UserForm(request.POST) # form validation if form.is_valid(): #Uses stripe API to create a customer in stripe # update based on your billing method (subscription vs one time) # pdb.set_trace() customer = stripe.Customer.create( email=form.cleaned_data['email'], description=form.cleaned_data['name'], # card=form.cleaned_data['stripe_token'], card={ 'number': '4242424242424242', 'exp_month': 10, 'exp_year': 2018, }, plan="gold", ) # customer = stripe.Charge.create( # description = form.cleaned_data['email'], # card = form.cleand_data['stripe_token'], # amount = "5000" # currency = "usd" # ) user = User( name=form.cleaned_data['name'], email=form.cleaned_data['email'], last_4_digits=form.cleaned_data['last_4_digits'], stripe_id=customer.id, ) # set_password takes care of password hasing # ensure encrypted password user.set_password(form.cleaned_data['password']) try: user.save() except IntegrityError: form.addError(user.email + ' is already a member') else: request.session['user'] = user.pk return HttpResponseRedirect('/') else: form = UserForm() return render_to_response( 'register.html', { 'form': form, 'months': range(1, 13), 'publishable': settings.STRIPE_PUBLISHABLE, 'soon': soon(), 'user': user, 'years': range(2011, 2037), }, context_instance=RequestContext(request) )
def register(request): user = None if request.method == 'POST': form = UserForm(request.POST) print("@@@@@@@@@@@@@@@@@@@@@@@@@@@") print(request) print("@@@@@@@@@@@@@@@@@@@@@@@@@@@") print(form) if form.is_valid(): #update based on your billing method (subscription vs one time) customer = stripe.Customer.create( email=form.cleaned_data['email'], description=form.cleaned_data['name'], card=form.cleaned_data['stripe_token'], plan="gold", ) # customer = stripe.Charge.create( # description = form.cleaned_data['email'], # card = form.cleaned_data['stripe_token'], # amount="5000", # currency="usd" # ) user = User( name=form.cleaned_data['name'], email=form.cleaned_data['email'], last_4_digits=form.cleaned_data['last_4_digits'], stripe_id=customer.id, ) #ensure encrypted password user.set_password(form.cleaned_data['password']) try: user.save() except IntegrityError: form.addError(user.email + ' is already a member') else: request.session['user'] = user.pk return redirect('/') else: form = UserForm() return render( request, 'register.html', { 'form': form, 'months': range(1, 12), 'publishable': settings.STRIPE_PUBLISHABLE, 'soon': soon(), 'user': user, 'years': range(2011, 2036), }, )
def register(request): user = None if request.method == "POST": form = UserForm(request.POST) if form.is_valid(): # update based on your billing method (subscription vs one time) customer = stripe.Customer.create( email=form.cleaned_data["email"], description=form.cleaned_data["name"], card=form.cleaned_data["stripe_token"], plan="gold", ) # customer = stripe.Charge.create( # description=form.cleaned_data['email'], # card=form.cleaned_data['stripe_token'], # amount="5000", # currency="usd" # ) user = User( name=form.cleaned_data["name"], email=form.cleaned_data["email"], last_4_digits=form.cleaned_data["last_4_digits"], stripe_id=customer.id, ) # ensure encrypted password user.set_password(form.cleaned_data["password"]) try: user.save() except IntegrityError: form.addError(user.email + " is already a member") else: request.session["user"] = user.pk return HttpResponseRedirect("/") else: form = UserForm() return render_to_response( "register.html", { "form": form, "months": range(1, 13), "publishable": settings.STRIPE_PUBLISHABLE, "soon": soon(), "user": user, "years": range(2015, 2041), }, context_instance=RequestContext(request), )
def register(request): print "USERFORM = " + str(UserForm) user = None if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): # subscription billing print "YO!" print "STRIPE_PUBLISHABLE = " + str(settings.STRIPE_PUBLISHABLE) print "stripe_token = " + form.cleaned_data['stripe_token'] customer = stripe.Customer.create( email=form.cleaned_data['email'], description=form.cleaned_data['name'], card=form.cleaned_data['stripe_token'], plan="gold", ) user = User( name=form.cleaned_data['name'], email=form.cleaned_data['email'], last_4_digits=form.cleaned_data['last_4_digits'], stripe_id=customer.id, ) user.set_password(form.cleaned_data['password']) try: user.save() except IntegrityError: print "Already a member bro!" form.addError(user.email + ' is already a member') else: print "Save user payment profile" request.session['user'] = user.pk print request.session['user'] return HttpResponseRedirect('/') else: form = UserForm() return render_to_response( 'register.html', { 'form': form, 'months': range(1, 12), 'publishable': settings.STRIPE_PUBLISHABLE, 'soon': soon(), 'user': user, 'years': range(2011, 2036), }, context_instance=RequestContext(request) )
def register(request): user = None if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): # update based on billing method (subscription/one-off) # customer = stripe.Customer.create( # email=form.cleaned_data['email'], # description=form.cleaned_data['name'], # card=form.cleaned_data['stripe_token'], # plan='gold', # ) customer = stripe.Charge.create( description=form.cleaned_data['email'], card=form.cleaned_data['stripe_token'], amount="5000", currency="usd" ) user = User( name=form.cleaned_data['name'], email=form.cleaned_data['email'], last_4_digits=form.cleaned_data['last_4_digits'], stripe_id=customer.id ) # ensure encrypted password user.set_password(form.cleaned_data['password']) try: user.save() except IntegrityError: form.addError(user.email + ' is already a member') else: request.session['user'] = user.pk return HttpResponseRedirect('/') else: form = UserForm() return render_to_response( 'register.html', { 'form': form, 'months': range(1,13), 'publishable': settings.STRIPE_PUBLISHABLE, 'soon': soon(), 'user': user, 'years': range(2011, 2036), }, context_instance=RequestContext(request) )