billing address form fixed

This commit is contained in:
Arvind Tiwari 2017-09-08 23:46:29 +05:30
parent daba6ae2fb
commit de1895d2a0
5 changed files with 113 additions and 103 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-07 19:54+0530\n"
"POT-Creation-Date: 2017-09-08 20:44+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -262,7 +262,7 @@ msgid ""
msgstr ""
msgid "Log in"
msgstr ""
msgstr "Anmelden"
msgid ""
"Already signed up?<br>By logging in you can retrieve saved billing "
@ -270,16 +270,16 @@ msgid ""
msgstr ""
msgid "LOGIN"
msgstr ""
msgstr "ANMELDEN"
msgid "Don't have an account yet?"
msgstr ""
msgstr "Besitzt du kein Benutzerkonto?"
msgid "You can sign up by filling in the information below."
msgstr ""
msgid "Forgot password?"
msgstr ""
msgstr "Passwort vergessen?"
msgid "Your Order"
msgstr "Deine Bestellung"
@ -306,38 +306,22 @@ msgid "Month"
msgstr "Monat"
msgid "Sign up"
msgstr ""
msgstr "Registrieren"
#, fuzzy
#| msgid "Billing Address"
msgid "Billing Address"
msgstr "Rechnungsadresse"
#, fuzzy
#| msgid "Billing Address"
msgid "Email Address"
msgstr "Rechnungsadresse"
msgstr "E-Mail-Adresse"
msgid "Credit Card"
msgstr "Kreditkarte"
#, fuzzy
#| msgid ""
#| "\n"
#| " Please fill in your credit card "
#| "information below. We are using <a\n"
#| " href=\"https://stripe.com\" target="
#| "\"_blank\">Stripe</a> for payment and do not store\n"
#| " your information in our database.\n"
#| " "
msgid ""
"\n"
" Please fill in your credit card information below. "
"We are using <a href=\"https://stripe.com\" target=\"_blank\">Stripe</a> for "
"payment and do not store your information in our database.\n"
" "
"Please fill in your credit card information below. We are using <a href="
"\"https://stripe.com\" target=\"_blank\">Stripe</a> for payment and do not "
"store your information in our database."
msgstr ""
"\n"
"Bitte füll Deine Kreditkarteninformationen unten aus. Wir nutzen <a href="
"\"https://stripe.com\" target=\"_blank\">Stripe</a> für die Bezahlung und "
"speichern keine Informationen in unserer Datenbank."
@ -364,10 +348,6 @@ msgstr ""
msgid "Card Type"
msgstr "Kartentyp"
#, fuzzy
#| msgid ""
#| "You are not making any payment yet. After submitting your card "
#| "information, you will be taken to the Confirm Order Page."
msgid ""
"You are not making any payment yet. After placing your order, you will be "
"taken to the Submit Payment Page."

View file

@ -48,15 +48,15 @@
<h3>{%trans "Your Order" %}</h3>
<hr class="top-hr">
<div class="dcl-payment-order">
<p>{% trans "Cores"%} <strong class="pull-right">{{vm.cores}}1</strong></p>
<p>{% trans "Cores"%} <strong class="pull-right">{{vm.cores}}</strong></p>
<hr>
<p>{% trans "Memory"%} <strong class="pull-right">{{vm.memory}}2 GB</strong></p>
<p>{% trans "Memory"%} <strong class="pull-right">{{vm.memory}} GB</strong></p>
<hr>
<p>{% trans "Disk space"%} <strong class="pull-right">{{vm.disk_size}}2 GB</strong></p>
<p>{% trans "Disk space"%} <strong class="pull-right">{{vm.disk_size}} GB</strong></p>
<hr>
<p>{% trans "Configuration"%} <strong class="pull-right">{{request.session.template.name}}CentOS 7</strong></p>
<p>{% trans "Configuration"%} <strong class="pull-right">{{request.session.template.name}}</strong></p>
<hr>
<p class="last-p"><strong>{%trans "Total" %}</strong>&nbsp;&nbsp;<small>({%trans "including VAT" %})</small> <strong class="pull-right">{{request.session.specs.price}}15 CHF/{% trans "Month" %}</strong></p>
<p class="last-p"><strong>{%trans "Total" %}</strong>&nbsp;&nbsp;<small>({%trans "including VAT" %})</small> <strong class="pull-right">{{request.session.specs.price}} CHF/{% trans "Month" %}</strong></p>
</div>
</div>
</div>
@ -69,18 +69,8 @@
{% endif %}
<hr class="top-hr">
<form role="form" id="billing-form" method="post" action="" novalidate>
{% if not request.user.is_authenticated %}
<div class="form-group">
<label class="sr-only" for="id_signup_name">{% trans "Name" %}</label>
<input type="text" id="id_signup_name" class="form-control" name="signup_name" placeholder="{% trans 'Name' %}">
</div>
<div class="form-group">
<label class="sr-only" for="id_signup_email">{% trans "Email Address" %}</label>
<input type="email" id="id_signup_email" class="form-control" name="signup_email" placeholder="{% trans 'Email Address' %}">
</div>
{% endif %}
{% for field in form %}
{% csrf_token %}
{% for field in form %}
{% bootstrap_field field show_label=False type='fields'%}
{% endfor %}
</form>
@ -91,9 +81,7 @@
<h3><b>{%trans "Credit Card"%}</b></h3>
<hr class="top-hr">
<p>
{% blocktrans %}
Please fill in your credit card information below. We are using <a href="https://stripe.com" target="_blank">Stripe</a> for payment and do not store your information in our database.
{% endblocktrans %}
{% blocktrans %}Please fill in your credit card information below. We are using <a href="https://stripe.com" target="_blank">Stripe</a> for payment and do not store your information in our database.{% endblocktrans %}
</p>
<div>
{% if credit_card_data.last4 %}

View file

@ -17,7 +17,7 @@ from membership.models import CustomUser, StripeCustomer
from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineTemplateSerializer, \
VMTemplateSerializer
from utils.forms import BillingAddressForm
from utils.forms import BillingAddressForm, BillingAddressFormSignup
from utils.mailer import BaseEmail
from utils.stripe_utils import StripeUtils
from utils.tasks import send_plain_email_task
@ -281,10 +281,10 @@ class IndexView(CreateView):
opennebula_vm_template_id=template_id).first()
template_data = VMTemplateSerializer(template).data
name = request.POST.get('name')
email = request.POST.get('email')
name_field = forms.CharField()
email_field = forms.EmailField()
# name = request.POST.get('name')
# email = request.POST.get('email')
# name_field = forms.CharField()
# email_field = forms.EmailField()
try:
cores = cores_field.clean(cores)
@ -313,23 +313,23 @@ class IndexView(CreateView):
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
try:
name = name_field.clean(name)
except ValidationError as err:
msg = '{} {}.'.format(name, _('is not a proper name'))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='name')
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
# try:
# name = name_field.clean(name)
# except ValidationError as err:
# msg = '{} {}.'.format(name, _('is not a proper name'))
# messages.add_message(self.request, messages.ERROR, msg,
# extra_tags='name')
# return HttpResponseRedirect(
# reverse('datacenterlight:index') + "#order_form")
try:
email = email_field.clean(email)
except ValidationError as err:
msg = '{} {}.'.format(email, _('is not a proper email'))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='email')
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
# try:
# email = email_field.clean(email)
# except ValidationError as err:
# msg = '{} {}.'.format(email, _('is not a proper email'))
# messages.add_message(self.request, messages.ERROR, msg,
# extra_tags='email')
# return HttpResponseRedirect(
# reverse('datacenterlight:index') + "#order_form")
specs = {
'cpu': cores,
@ -338,14 +338,14 @@ class IndexView(CreateView):
'price': price
}
this_user = {
'name': name,
'email': email
}
# this_user = {
# 'name': name,
# 'email': email
# }
request.session['specs'] = specs
request.session['template'] = template_data
request.session['user'] = this_user
# request.session['user'] = this_user
return HttpResponseRedirect(reverse('datacenterlight:payment'))
def get_success_url(self):
@ -408,21 +408,34 @@ class WhyDataCenterLightView(IndexView):
class PaymentOrderView(FormView):
template_name = 'datacenterlight/landing_payment.html'
form_class = BillingAddressForm
def get_form_class(self):
if self.request.user.is_authenticated():
return BillingAddressForm
else:
return BillingAddressFormSignup
def get_form_kwargs(self):
form_kwargs = super(PaymentOrderView, self).get_form_kwargs()
billing_address_data = self.request.session.get('billing_address_data')
if billing_address_data:
# if user is signed in, get billing address
if self.request.user.is_authenticated():
form_kwargs.update({
'initial': {
'cardholder_name': billing_address_data['cardholder_name'],
'street_address': billing_address_data['street_address'],
'city': billing_address_data['city'],
'postal_code': billing_address_data['postal_code'],
'country': billing_address_data['country'],
}
'instance': self.request.user.billing_addresses.first()
})
else:
# if billing address in session, get data
billing_address_data = self.request.session.get(
'billing_address_data')
if billing_address_data:
form_kwargs.update({
'initial': {
'cardholder_name': billing_address_data['cardholder_name'],
'street_address': billing_address_data['street_address'],
'city': billing_address_data['city'],
'postal_code': billing_address_data['postal_code'],
'country': billing_address_data['country'],
}
})
return form_kwargs
def get_context_data(self, **kwargs):
@ -436,31 +449,55 @@ class PaymentOrderView(FormView):
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
def get(self, request, *args, **kwargs):
# user is no longer added to session in the index page
# if 'specs' not in request.session or 'user' not in request.session:
# return HttpResponseRedirect(reverse('datacenterlight:index'))
if 'specs' not in request.session:
return HttpResponseRedirect(reverse('datacenterlight:index'))
return self.render_to_response(self.get_context_data())
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
# name = request.POST.get('name')
# email = request.POST.get('email')
# name_field = forms.CharField()
# email_field = forms.EmailField()
# try:
# name = name_field.clean(name)
# except ValidationError as err:
# msg = '{} {}.'.format(name, _('is not a proper name'))
# messages.add_message(self.request, messages.ERROR, msg,
# extra_tags='name')
# return HttpResponseRedirect(
# reverse('datacenterlight:payment'))
# try:
# email = email_field.clean(email)
# except ValidationError as err:
# msg = '{} {}.'.format(email, _('is not a proper email'))
# messages.add_message(self.request, messages.ERROR, msg,
# extra_tags='email')
# return HttpResponseRedirect(
# reverse('datacenterlight:payment'))
# Get billing address data
# user = request.session.get('user')
billing_address_data = form.cleaned_data
token = form.cleaned_data.get('token')
user = request.session.get('user')
try:
CustomUser.objects.get(email=user.get('email'))
CustomUser.objects.get(email=form.cleaned_data.get('email'))
except CustomUser.DoesNotExist:
password = CustomUser.get_random_password()
# Register the user, and do not send emails
CustomUser.register(user.get('name'),
CustomUser.register(form.cleaned_data.get('name'),
password,
user.get('email'),
form.cleaned_data.get('email'),
app='dcl',
base_url=None, send_email=False)
# Get or create stripe customer
customer = StripeCustomer.get_or_create(email=user.get('email'),
token=token)
customer = StripeCustomer.get_or_create(
email=form.cleaned_data.get('email'),
token=token)
if not customer:
form.add_error("__all__", "Invalid credit card")
return self.render_to_response(

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-07 19:54+0530\n"
"POT-Creation-Date: 2017-09-08 20:44+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -365,12 +365,6 @@ msgstr ""
msgid "Type"
msgstr "Kartentyp"
msgid "REMOVE CARD"
msgstr "KARTE ENTFERNEN"
msgid "EDIT CARD"
msgstr "BEARBEITEN"
msgid "No Credit Cards Added"
msgstr "Es wurde keine Kreditkarte hinzugefügt"
@ -378,9 +372,8 @@ msgid ""
"We are using <a href=\"https://stripe.com\">Stripe</a> for payment and do "
"not store your information in our database."
msgstr ""
"Wir nutzen <a href="
"\"https://stripe.com\" target=\"_blank\">Stripe</a> für die Bezahlung und "
"speichern keine Informationen in unserer Datenbank."
"Wir nutzen <a href=\"https://stripe.com\" target=\"_blank\">Stripe</a> für "
"die Bezahlung und speichern keine Informationen in unserer Datenbank."
msgid "Add your public SSH key"
msgstr "Füge deinen öffentlichen SSH-Key hinzu"
@ -502,7 +495,7 @@ msgid "View Detail"
msgstr "Details anzeigen"
msgid "login"
msgstr "Einloggen"
msgstr "Anmelden"
msgid ""
"Thank you for signing up. We have sent an email to you. Please follow the "
@ -539,6 +532,12 @@ msgid ""
"contact Data Center Light Support."
msgstr "Kontaktiere den Data Center Light Support."
#~ msgid "REMOVE CARD"
#~ msgstr "KARTE ENTFERNEN"
#~ msgid "EDIT CARD"
#~ msgstr "BEARBEITEN"
#~ msgid "Add a new Card."
#~ msgstr "Neue Kreditkarte hinzufügen."

View file

@ -113,6 +113,12 @@ class BillingAddressForm(forms.ModelForm):
}
class BillingAddressFormSignup(BillingAddressForm):
name = forms.CharField(label=_('Name'))
email = forms.EmailField(label=_('Email Address'))
field_order = ['name', 'email']
class UserBillingAddressForm(forms.ModelForm):
user = forms.ModelChoiceField(queryset=CustomUser.objects.all(),
widget=forms.HiddenInput())