Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if form.is_valid():
- try:
- customer = stripe.Customer.create(
- email=form.cleaned_data['email'],
- card=form.cleaned_data['stripe_id'], # this is currently the card token/id
- plan='REG_MONTHLY_',
- )
- if customer:
- user = form.save() # save here to create the user and get its instance
- # now we replace the card id with the actual user id for later
- user.stripe_id = customer.id
- user.subscription_end = arrow.now().replace(weeks=+4).datetime # add 4 weeks from now
- user.save()
- # check we saved correctly and can login
- user = auth.authenticate(email=request.POST.get('email'),
- password=request.POST.get('password1'))
- if user:
- auth.login(request, user)
- messages.success(request, "You have successfully registered")
- return redirect(reverse('profile'))
- else:
- messages.error(request, "unable to log you in at this time!")
- except stripe.error.CardError, e:
- form.add_error(request, "Your card was declined!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement