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

View file

@ -48,15 +48,15 @@
<h3>{%trans "Your Order" %}</h3> <h3>{%trans "Your Order" %}</h3>
<hr class="top-hr"> <hr class="top-hr">
<div class="dcl-payment-order"> <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> <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> <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> <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> <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> </div>
</div> </div>
@ -69,18 +69,8 @@
{% endif %} {% endif %}
<hr class="top-hr"> <hr class="top-hr">
<form role="form" id="billing-form" method="post" action="" novalidate> <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 %} {% csrf_token %}
{% for field in form %}
{% bootstrap_field field show_label=False type='fields'%} {% bootstrap_field field show_label=False type='fields'%}
{% endfor %} {% endfor %}
</form> </form>
@ -91,9 +81,7 @@
<h3><b>{%trans "Credit Card"%}</b></h3> <h3><b>{%trans "Credit Card"%}</b></h3>
<hr class="top-hr"> <hr class="top-hr">
<p> <p>
{% blocktrans %} {% 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 %}
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> </p>
<div> <div>
{% if credit_card_data.last4 %} {% 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.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineTemplateSerializer, \ from opennebula_api.serializers import VirtualMachineTemplateSerializer, \
VMTemplateSerializer VMTemplateSerializer
from utils.forms import BillingAddressForm from utils.forms import BillingAddressForm, BillingAddressFormSignup
from utils.mailer import BaseEmail from utils.mailer import BaseEmail
from utils.stripe_utils import StripeUtils from utils.stripe_utils import StripeUtils
from utils.tasks import send_plain_email_task from utils.tasks import send_plain_email_task
@ -281,10 +281,10 @@ class IndexView(CreateView):
opennebula_vm_template_id=template_id).first() opennebula_vm_template_id=template_id).first()
template_data = VMTemplateSerializer(template).data template_data = VMTemplateSerializer(template).data
name = request.POST.get('name') # name = request.POST.get('name')
email = request.POST.get('email') # email = request.POST.get('email')
name_field = forms.CharField() # name_field = forms.CharField()
email_field = forms.EmailField() # email_field = forms.EmailField()
try: try:
cores = cores_field.clean(cores) cores = cores_field.clean(cores)
@ -313,23 +313,23 @@ class IndexView(CreateView):
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form") reverse('datacenterlight:index') + "#order_form")
try: # try:
name = name_field.clean(name) # name = name_field.clean(name)
except ValidationError as err: # except ValidationError as err:
msg = '{} {}.'.format(name, _('is not a proper name')) # msg = '{} {}.'.format(name, _('is not a proper name'))
messages.add_message(self.request, messages.ERROR, msg, # messages.add_message(self.request, messages.ERROR, msg,
extra_tags='name') # extra_tags='name')
return HttpResponseRedirect( # return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form") # reverse('datacenterlight:index') + "#order_form")
try: # try:
email = email_field.clean(email) # email = email_field.clean(email)
except ValidationError as err: # except ValidationError as err:
msg = '{} {}.'.format(email, _('is not a proper email')) # msg = '{} {}.'.format(email, _('is not a proper email'))
messages.add_message(self.request, messages.ERROR, msg, # messages.add_message(self.request, messages.ERROR, msg,
extra_tags='email') # extra_tags='email')
return HttpResponseRedirect( # return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form") # reverse('datacenterlight:index') + "#order_form")
specs = { specs = {
'cpu': cores, 'cpu': cores,
@ -338,14 +338,14 @@ class IndexView(CreateView):
'price': price 'price': price
} }
this_user = { # this_user = {
'name': name, # 'name': name,
'email': email # 'email': email
} # }
request.session['specs'] = specs request.session['specs'] = specs
request.session['template'] = template_data request.session['template'] = template_data
request.session['user'] = this_user # request.session['user'] = this_user
return HttpResponseRedirect(reverse('datacenterlight:payment')) return HttpResponseRedirect(reverse('datacenterlight:payment'))
def get_success_url(self): def get_success_url(self):
@ -408,11 +408,24 @@ class WhyDataCenterLightView(IndexView):
class PaymentOrderView(FormView): class PaymentOrderView(FormView):
template_name = 'datacenterlight/landing_payment.html' 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): def get_form_kwargs(self):
form_kwargs = super(PaymentOrderView, self).get_form_kwargs() form_kwargs = super(PaymentOrderView, self).get_form_kwargs()
billing_address_data = self.request.session.get('billing_address_data') # if user is signed in, get billing address
if self.request.user.is_authenticated():
form_kwargs.update({
'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: if billing_address_data:
form_kwargs.update({ form_kwargs.update({
'initial': { 'initial': {
@ -436,30 +449,54 @@ class PaymentOrderView(FormView):
@cache_control(no_cache=True, must_revalidate=True, no_store=True) @cache_control(no_cache=True, must_revalidate=True, no_store=True)
def get(self, request, *args, **kwargs): 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: # 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()) return self.render_to_response(self.get_context_data())
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = self.get_form() form = self.get_form()
if form.is_valid(): 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 # Get billing address data
# user = request.session.get('user')
billing_address_data = form.cleaned_data billing_address_data = form.cleaned_data
token = form.cleaned_data.get('token') token = form.cleaned_data.get('token')
user = request.session.get('user')
try: try:
CustomUser.objects.get(email=user.get('email')) CustomUser.objects.get(email=form.cleaned_data.get('email'))
except CustomUser.DoesNotExist: except CustomUser.DoesNotExist:
password = CustomUser.get_random_password() password = CustomUser.get_random_password()
# Register the user, and do not send emails # Register the user, and do not send emails
CustomUser.register(user.get('name'), CustomUser.register(form.cleaned_data.get('name'),
password, password,
user.get('email'), form.cleaned_data.get('email'),
app='dcl', app='dcl',
base_url=None, send_email=False) base_url=None, send_email=False)
# Get or create stripe customer # Get or create stripe customer
customer = StripeCustomer.get_or_create(email=user.get('email'), customer = StripeCustomer.get_or_create(
email=form.cleaned_data.get('email'),
token=token) token=token)
if not customer: if not customer:
form.add_error("__all__", "Invalid credit card") form.add_error("__all__", "Invalid credit card")

View file

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