Added error hash in url, added payment error handler to hosting/views

This commit is contained in:
Siarhei Puhach 2017-08-07 17:02:47 +03:00
parent 4cd3d6a4aa
commit a71ccbc566
3 changed files with 37 additions and 35 deletions

View file

@ -441,7 +441,7 @@ class OrderConfirmationView(DetailView):
if not card_details.get('response_object') and not card_details.get('paid'): if not card_details.get('response_object') and not card_details.get('paid'):
msg = card_details.get('error') msg = card_details.get('error')
messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment') messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment')
return HttpResponseRedirect(reverse('datacenterlight:payment')) return HttpResponseRedirect(reverse('datacenterlight:payment') + '#dcl_payment_error')
context = { context = {
'site_url': reverse('datacenterlight:index'), 'site_url': reverse('datacenterlight:index'),
@ -472,7 +472,7 @@ class OrderConfirmationView(DetailView):
if not charge_response.get('response_object') and not charge_response.get('paid'): if not charge_response.get('response_object') and not charge_response.get('paid'):
msg = charge_response.get('error') msg = charge_response.get('error')
messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error') messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error')
return HttpResponseRedirect(reverse('datacenterlight:payment')) return HttpResponseRedirect(reverse('datacenterlight:payment') + '#dcl_payment_error')
charge = charge_response.get('response_object') charge = charge_response.get('response_object')

View file

@ -85,13 +85,29 @@
</form> </form>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<p class="card-warning-content card-warning-addtional-margin"> {% if not messages and not form.non_field_errors %}
{% blocktrans %} <p class="card-warning-content card-warning-addtional-margin">
You are not making any payment yet. After submitting your card {% blocktrans %}
information, you will be taken to the Confirm Order Page. You are not making any payment yet. After submitting your card
{% endblocktrans %} information, you will be taken to the Confirm Order Page.
</p> {% endblocktrans %}
</div> </p>
{% endif %}
<div id='hosting_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-12">
<div class="col-xs-6 pull-right"> <div class="col-xs-6 pull-right">
<button id="payment_button_with_creditcard" class="btn btn-success stripe-payment-btn" <button id="payment_button_with_creditcard" class="btn btn-success stripe-payment-btn"
@ -129,7 +145,7 @@
<div id="card-errors" role="alert"></div> <div id="card-errors" role="alert"></div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
{% if not messages and not form.errors %} {% if not messages and not form.non_field_errors %}
<p class="card-warning-content"> <p class="card-warning-content">
{% blocktrans %} {% blocktrans %}
You are not making any payment yet. After submitting your card You are not making any payment yet. After submitting your card
@ -137,22 +153,20 @@
{% endblocktrans %} {% endblocktrans %}
</p> </p>
{% endif %} {% endif %}
<div> <div id='dcl_payment_error'>
{% for message in messages %} {% for message in messages %}
{% if 'failed_payment' in message.tags %} {% if 'failed_payment' or 'make_charge_error' in message.tags %}
<ul class="list-unstyled"><li> <ul class="list-unstyled"><li>
<p class="card-warning-content card-warning-error">{{ message|safe }}</p> <p class="card-warning-content card-warning-error">{{ message|safe }}</p>
</li></ul> </li></ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if form.errors %} {% for error in form.non_field_errors %}
{% for error in form.non_field_errors %} <p class="card-warning-content card-warning-error">
<p class="card-warning-content card-warning-error"> {{ error|escape }}
{{ error|escape }} </p>
</p> {% endfor %}
{% endfor %}
{% endif %}
</div> </div>
</div> </div>
<div class="col-xs-12"> <div class="col-xs-12">
@ -168,15 +182,6 @@
<p class="payment-errors"></p> <p class="payment-errors"></p>
</div> </div>
</div> </div>
{% if paymentError %}
<div class="row">
<div class="col-xs-12">
<p>
{% bootstrap_alert paymentError alert_type='danger' %}
</p>
</div>
</div>
{% endif %}
</form> </form>
{% endif %} {% endif %}

View file

@ -557,15 +557,12 @@ class PaymentVMView(LoginRequiredMixin, FormView):
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
charge_response = stripe_utils.make_charge(amount=final_price, charge_response = stripe_utils.make_charge(amount=final_price,
customer=customer.stripe_id) customer=customer.stripe_id)
charge = charge_response.get('response_object')
# Check if the payment was approved # Check if the payment was approved
if not charge: if not charge_response.get('response_object') and not charge_response.get('paid'):
context.update({ msg = charge_response.get('error')
'paymentError': charge_response.get('error'), messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error')
'form': form return HttpResponseRedirect(reverse('hosting:payment') + '#hosting_payment_error')
})
return render(request, self.template_name, context)
charge = charge_response.get('response_object') charge = charge_response.get('response_object')