Merge pull request #77 from tmslav/develop

https://redmine.ungleich.ch/issues/2290
This commit is contained in:
tmslav 2016-05-21 00:04:41 +02:00
commit 3beb220f90
2 changed files with 13 additions and 6 deletions

View file

@ -1,5 +1,5 @@
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render,render_to_response
from django.core.urlresolvers import reverse_lazy, reverse from django.core.urlresolvers import reverse_lazy, reverse
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
@ -7,6 +7,7 @@ from django.views.generic import View, CreateView, FormView, ListView, DetailVie
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth import authenticate, login from django.contrib.auth import authenticate, login
from django.conf import settings from django.conf import settings
from django.contrib import messages
from membership.models import CustomUser, StripeCustomer from membership.models import CustomUser, StripeCustomer
from utils.stripe_utils import StripeUtils from utils.stripe_utils import StripeUtils
@ -133,7 +134,6 @@ class SignupView(CreateView):
return next_url return next_url
def form_valid(self, form): def form_valid(self, form):
name = form.cleaned_data.get('name') name = form.cleaned_data.get('name')
email = form.cleaned_data.get('email') email = form.cleaned_data.get('email')
password = form.cleaned_data.get('password') password = form.cleaned_data.get('password')
@ -204,6 +204,10 @@ class PaymentVMView(LoginRequiredMixin, FormView):
# Get or create stripe customer # Get or create stripe customer
customer = StripeCustomer.get_or_create(email=self.request.user.email, customer = StripeCustomer.get_or_create(email=self.request.user.email,
token=token) token=token)
if not customer:
form.add_error("__all__","Invalid credit card")
return self.render_to_response(self.get_context_data(form=form))
# Create Virtual Machine Plan # Create Virtual Machine Plan
plan = VirtualMachinePlan.create(plan_data, request.user) plan = VirtualMachinePlan.create(plan_data, request.user)

View file

@ -143,12 +143,15 @@ class StripeCustomer(models.Model):
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
stripe_data = stripe_utils.create_customer(token, email) stripe_data = stripe_utils.create_customer(token, email)
stripe_cus_id = stripe_data.get('response_object').get('id') if stripe_data.get('response_object'):
stripe_cus_id = stripe_data.get('response_object').get('id')
stripe_customer = StripeCustomer.objects.\ stripe_customer = StripeCustomer.objects.\
create(user=user, stripe_id=stripe_cus_id) create(user=user, stripe_id=stripe_cus_id)
return stripe_customer return stripe_customer
else:
return None
class CreditCards(models.Model): class CreditCards(models.Model):