Set data at the client side according to success or error
This commit is contained in:
		
					parent
					
						
							
								d0d5fb0196
							
						
					
				
			
			
				commit
				
					
						a63fac1a20
					
				
			
		
					 2 changed files with 44 additions and 6 deletions
				
			
		| 
						 | 
					@ -916,7 +916,41 @@ class OrderConfirmationView(DetailView, FormView):
 | 
				
			||||||
                        'sid': stripe_subscription_obj.id,
 | 
					                        'sid': stripe_subscription_obj.id,
 | 
				
			||||||
                        'payment_intent_secret': pi.client_secret,
 | 
					                        'payment_intent_secret': pi.client_secret,
 | 
				
			||||||
                        'STRIPE_PUBLISHABLE_KEY': settings.STRIPE_API_PUBLIC_KEY,
 | 
					                        '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)
 | 
					                    return JsonResponse(context)
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,16 +110,20 @@ $(document).ready(function() {
 | 
				
			||||||
                if (data.showSCA){
 | 
					                if (data.showSCA){
 | 
				
			||||||
                    console.log("Show SCA");
 | 
					                    console.log("Show SCA");
 | 
				
			||||||
                    var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY);
 | 
					                    var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY);
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      stripe.confirmCardPayment(data.payment_intent_secret).then(function(result) {
 | 
					                      stripe.confirmCardPayment(data.payment_intent_secret).then(function(result) {
 | 
				
			||||||
                        if (result.error) {
 | 
					                        if (result.error) {
 | 
				
			||||||
                          // Display error.message in your UI.
 | 
					                          // Display error.message in your UI.
 | 
				
			||||||
                          $("#3ds_result").text("Error!");
 | 
					                            modal_btn.attr('href', data.error.redirect).removeClass('hide');
 | 
				
			||||||
                          $("#3ds_result").addClass("text-danger");
 | 
					                            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 {
 | 
					                        } else {
 | 
				
			||||||
                          // The payment has succeeded. Display a success message.
 | 
					                          // The payment has succeeded. Display a success message.
 | 
				
			||||||
                          $("#3ds_result").text("Thank you for payment");
 | 
					                            modal_btn.attr('href', data.success.redirect).removeClass('hide');
 | 
				
			||||||
                          $("#3ds_result").addClass("text-success");
 | 
					                            fa_icon.attr('class', 'checkmark');
 | 
				
			||||||
 | 
					                            $('#createvm-modal-title').text(data.success.msg_title);
 | 
				
			||||||
 | 
					                            $('#createvm-modal-body').html(data.success.msg_body);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                      });
 | 
					                      });
 | 
				
			||||||
                    $('#3Dsecure-modal').show();
 | 
					                    $('#3Dsecure-modal').show();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue