billing form in settings page
This commit is contained in:
parent
49cc441fa0
commit
ce1d346bc1
5 changed files with 48 additions and 55 deletions
|
@ -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-08-29 14:38+0530\n"
|
"POT-Creation-Date: 2017-08-29 17:41+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"
|
||||||
|
@ -343,10 +343,7 @@ msgstr ""
|
||||||
msgid "Type"
|
msgid "Type"
|
||||||
msgstr "Kartentyp"
|
msgstr "Kartentyp"
|
||||||
|
|
||||||
msgid "You are not making any payment here."
|
msgid "No Cards found for your account."
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgid "Add new Card"
|
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Add your public SSH key"
|
msgid "Add your public SSH key"
|
||||||
|
|
|
@ -271,6 +271,20 @@
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-container .credit-card-details {
|
||||||
|
padding-bottom: 15px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-container .credit-card-details h5 {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.credit-card-form {
|
.credit-card-form {
|
||||||
max-width: 360px;
|
max-width: 360px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-wide {
|
||||||
|
min-width: 120px;
|
||||||
|
}
|
|
@ -17,6 +17,9 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_field field show_label=False type='fields'%}
|
{% bootstrap_field field show_label=False type='fields'%}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<div class="form-group text-right">
|
||||||
|
<button type="submit" class="btn btn-default btn-custom-delete btn-wide">Save</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-7 col-md-6 creditcard-box dcl-creditcard">
|
<div class="col-sm-7 col-md-6 creditcard-box dcl-creditcard">
|
||||||
|
@ -25,45 +28,14 @@
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
{% if credit_card_data.last4 %}
|
{% if credit_card_data.last4 %}
|
||||||
<form role="form" id="payment-form-with-creditcard" novalidate>
|
<div class="credit-card-details">
|
||||||
<h5 class="billing-head">{% trans "Credit Card" %}</h5>
|
<h5 class="billing-head">{% trans "Credit Card" %}</h5>
|
||||||
<h5 class="membership-lead">{% trans "Last" %} 4: *****{{credit_card_data.last4}}</h5>
|
<h5 class="membership-lead">{% trans "Last" %} 4: *****{{credit_card_data.last4}}</h5>
|
||||||
<h5 class="membership-lead">{% trans "Type" %}: {{credit_card_data.cc_brand}}</h5>
|
<h5 class="membership-lead">{% trans "Type" %}: {{credit_card_data.cc_brand}}</h5>
|
||||||
<input type="hidden" name="credit_card_needed" value="false"/>
|
|
||||||
</form>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-xs-12">
|
|
||||||
{% if not messages and not form.non_field_errors %}
|
|
||||||
<p class="card-warning-content card-warning-addtional-margin">
|
|
||||||
{% blocktrans %}You are not making any payment here.{% endblocktrans %}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
<div id='payment_error'>
|
|
||||||
{% for message in messages %}
|
|
||||||
{% if 'failed_payment' or 'make_charge_error' in message.tags %}
|
|
||||||
<ul class="list-unstyled"><li>
|
|
||||||
<p class="card-warning-content card-warning-error">{{ message|safe }}</p>
|
|
||||||
</li></ul>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% for error in form.non_field_errors %}
|
|
||||||
<p class="card-warning-content card-warning-error">
|
|
||||||
{{ error|escape }}
|
|
||||||
</p>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-xs-12">
|
|
||||||
<div class="col-xs-6 pull-right">
|
|
||||||
<button id="payment_button_with_creditcard" class="btn btn-success stripe-payment-btn"
|
|
||||||
type="submit">
|
|
||||||
{%trans "Submit" %}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h4>{% trans "Add new Card" %}</h4>
|
<h4>{% trans "No Cards found for your account." %}</h4>
|
||||||
|
{% comment %}
|
||||||
<form action="" id="payment-form-new" class="credit-card-form" method="POST">
|
<form action="" id="payment-form-new" class="credit-card-form" method="POST">
|
||||||
<input type="hidden" name="token"/>
|
<input type="hidden" name="token"/>
|
||||||
<div class="credit-card-goup">
|
<div class="credit-card-goup">
|
||||||
|
@ -120,6 +92,7 @@
|
||||||
<p class="payment-errors"></p>
|
<p class="payment-errors"></p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{% endcomment %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -480,22 +480,14 @@ class SettingsView(LoginRequiredMixin, FormView):
|
||||||
login_url = reverse_lazy('hosting:login')
|
login_url = reverse_lazy('hosting:login')
|
||||||
form_class = BillingAddressForm
|
form_class = BillingAddressForm
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form(self, form_class):
|
||||||
current_billing_address = self.request.user.billing_addresses.first()
|
"""
|
||||||
form_kwargs = super(SettingsView, self).get_form_kwargs()
|
Check if the user already saved contact details. If so, then show
|
||||||
if not current_billing_address:
|
the form populated with those details, to let user change them.
|
||||||
return form_kwargs
|
"""
|
||||||
|
return form_class(
|
||||||
form_kwargs.update({
|
instance=self.request.user.billing_addresses.first(),
|
||||||
'initial': {
|
**self.get_form_kwargs())
|
||||||
'cardholder_name': current_billing_address.cardholder_name,
|
|
||||||
'street_address': current_billing_address.street_address,
|
|
||||||
'city': current_billing_address.city,
|
|
||||||
'postal_code': current_billing_address.postal_code,
|
|
||||||
'country': current_billing_address.country,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return form_kwargs
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(SettingsView, self).get_context_data(**kwargs)
|
context = super(SettingsView, self).get_context_data(**kwargs)
|
||||||
|
@ -520,6 +512,22 @@ class SettingsView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
form = self.get_form()
|
||||||
|
if form.is_valid():
|
||||||
|
billing_address_data = form.cleaned_data
|
||||||
|
billing_address_data.update({
|
||||||
|
'user': self.request.user.id
|
||||||
|
})
|
||||||
|
billing_address_user_form = UserBillingAddressForm(
|
||||||
|
instance=self.request.user.billing_addresses.first(),
|
||||||
|
data=billing_address_data)
|
||||||
|
billing_address_user_form.save()
|
||||||
|
return self.render_to_response(self.get_context_data())
|
||||||
|
else:
|
||||||
|
billing_address_data = form.cleaned_data
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class PaymentVMView(LoginRequiredMixin, FormView):
|
class PaymentVMView(LoginRequiredMixin, FormView):
|
||||||
template_name = 'hosting/payment.html'
|
template_name = 'hosting/payment.html'
|
||||||
|
|
|
@ -117,6 +117,7 @@ class UserBillingAddressForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserBillingAddress
|
model = UserBillingAddress
|
||||||
|
# cardholder name not saved
|
||||||
fields = ['street_address', 'city', 'postal_code', 'country', 'user']
|
fields = ['street_address', 'city', 'postal_code', 'country', 'user']
|
||||||
labels = {
|
labels = {
|
||||||
'street_address': _('Street Building'),
|
'street_address': _('Street Building'),
|
||||||
|
|
Loading…
Reference in a new issue