Show user's credit cards dynamically in landing payment page

This commit is contained in:
PCoder 2017-10-28 23:44:06 +02:00
parent bafb4e7b68
commit 248283b369
2 changed files with 36 additions and 10 deletions

View file

@ -84,11 +84,35 @@
</div>
<div class="dcl-payment-box">
<div class="dcl-payment-section">
{% with card_list_len=cards_list|length %}
<h3><b>{%trans "Credit Card"%}</b></h3>
<hr class="top-hr">
<p>
{% if card_list_len > 0 %}
{% blocktrans %}Please select one of the previous cards that you used before or 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 %}
{% else %}
{% 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 %}
{% endif %}
</p>
<div>
{% for card in cards_list %}
<div class="credit-card-info">
<div class="col-xs-6 no-padding">
<h5 class="billing-head">{% trans "Credit Card" %}</h5>
<h5 class="membership-lead">{% trans "Last" %} 4: ***** {{card.last4}}</h5>
<h5 class="membership-lead">{% trans "Type" %}: {{card.brand}}</h5>
</div>
<div class="col-xs-6 text-right align-bottom">
<a class="btn choice-btn choice-btn-faded" href="#" data-id_card="{{card.id}}">{% trans "SELECT" %}</a>
</div>
</div>
{% endfor %}
{% if card_list_len > 0 %}
<div class="another-card-text">Use another card</div>
{% endif %}
{% include "hosting/includes/_card_input.html" %}
</div>
{% comment %}
<div>
{% if credit_card_data.last4 %}
<form role="form" id="payment-form-with-creditcard" novalidate>
@ -125,6 +149,8 @@
{% include "hosting/includes/_card_input.html" %}
{% endif %}
</div>
{% endcomment %}
{% endwith %}
</div>
</div>
</div>
@ -144,13 +170,4 @@
})();
</script>
{%endif%}
{% if credit_card_data.last4 and credit_card_data.cc_brand %}
<script type="text/javascript">
(function () {
window.hasCreditcard = true;
})();
</script>
{%endif%}
{%endblock%}

View file

@ -14,7 +14,7 @@ from django.views.decorators.cache import cache_control
from django.views.generic import FormView, CreateView, TemplateView, DetailView
from datacenterlight.tasks import create_vm_task
from hosting.models import HostingOrder
from hosting.models import HostingOrder, UserCardDetail
from hosting.forms import HostingUserLoginForm
from membership.models import CustomUser, StripeCustomer
from opennebula_api.serializers import VMTemplateSerializer
@ -347,6 +347,14 @@ class PaymentOrderView(FormView):
def get_context_data(self, **kwargs):
context = super(PaymentOrderView, self).get_context_data(**kwargs)
user = self.request.user
if hasattr(user, 'stripecustomer'):
stripe_customer = user.stripecustomer
else:
stripe_customer = None
cards_list = UserCardDetail.get_all_cards_list(
stripe_customer=stripe_customer
)
if 'billing_address_data' in self.request.session:
billing_address_data = self.request.session['billing_address_data']
else:
@ -380,6 +388,7 @@ class PaymentOrderView(FormView):
)
context.update({
'cards_list': cards_list,
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
'site_url': reverse('datacenterlight:index'),
'login_form': HostingUserLoginForm(prefix='login_form'),