From a63fac1a2081378ebed59b4a4d4232d081bf223f Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 18 Dec 2020 17:16:40 +0530 Subject: [PATCH] Set data at the client side according to success or error --- datacenterlight/views.py | 36 ++++++++++++++++++- .../hosting/js/virtual_machine_detail.js | 14 +++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index abf0814a..77c0444f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -916,7 +916,41 @@ class OrderConfirmationView(DetailView, FormView): 'sid': stripe_subscription_obj.id, 'payment_intent_secret': pi.client_secret, 'STRIPE_PUBLISHABLE_KEY': settings.STRIPE_API_PUBLIC_KEY, - 'showSCA': True + 'showSCA': True, + 'success': { + 'status': True, + 'redirect': ( + reverse('hosting:virtual_machines') + if request.user.is_authenticated() + else reverse('datacenterlight:index') + ), + 'msg_title': str(_('Thank you for the order.')), + 'msg_body': str( + _('Your VM will be up and running in a few moments.' + ' We will send you a confirmation email as soon as' + ' it is ready.')) + }, + 'error': { + 'status': False, + 'redirect': "{url}#{section}".format( + url=(reverse( + 'show_product', + kwargs={'product_slug': + request.session[ + 'generic_payment_details'] + ['product_slug']} + ) if 'generic_payment_details' in request.session else + reverse('datacenterlight:payment') + ), + section='payment_error' + ), + 'msg_title': str(_('Error.')), + 'msg_body': str( + _('There was a payment related error.' + ' On close of this popup, you will be redirected back to' + ' the payment page.') + ) + } } return JsonResponse(context) else: diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js index db1faaf8..dec8e680 100644 --- a/hosting/static/hosting/js/virtual_machine_detail.js +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -110,16 +110,20 @@ $(document).ready(function() { if (data.showSCA){ console.log("Show SCA"); var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY); - stripe.confirmCardPayment(data.payment_intent_secret).then(function(result) { if (result.error) { // Display error.message in your UI. - $("#3ds_result").text("Error!"); - $("#3ds_result").addClass("text-danger"); + modal_btn.attr('href', data.error.redirect).removeClass('hide'); + fa_icon.attr('class', 'fa fa-close'); + modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide'); + $('#createvm-modal-title').text(data.error.msg_title); + $('#createvm-modal-body').html(data.error.msg_body); } else { // The payment has succeeded. Display a success message. - $("#3ds_result").text("Thank you for payment"); - $("#3ds_result").addClass("text-success"); + modal_btn.attr('href', data.success.redirect).removeClass('hide'); + fa_icon.attr('class', 'checkmark'); + $('#createvm-modal-title').text(data.success.msg_title); + $('#createvm-modal-body').html(data.success.msg_body); } }); $('#3Dsecure-modal').show();