Show SCA modal when required
This commit is contained in:
		
					parent
					
						
							
								c2e2e1828f
							
						
					
				
			
			
				commit
				
					
						70bfef4738
					
				
			
		
					 3 changed files with 45 additions and 11 deletions
				
			
		| 
						 | 
					@ -107,18 +107,36 @@ $(document).ready(function() {
 | 
				
			||||||
            success: function (data) {
 | 
					            success: function (data) {
 | 
				
			||||||
                fa_icon = $('.modal-icon > .fa');
 | 
					                fa_icon = $('.modal-icon > .fa');
 | 
				
			||||||
                modal_btn = $('#createvm-modal-done-btn');
 | 
					                modal_btn = $('#createvm-modal-done-btn');
 | 
				
			||||||
                $('#createvm-modal-title').text(data.msg_title);
 | 
					                if (data.showSCA){
 | 
				
			||||||
                $('#createvm-modal-body').html(data.msg_body);
 | 
					                    console.log("Show SCA");
 | 
				
			||||||
                if (data.redirect) {
 | 
					                    var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY);
 | 
				
			||||||
                    modal_btn.attr('href', data.redirect).removeClass('hide');
 | 
					
 | 
				
			||||||
 | 
					                      stripe.confirmCardPayment(pi_secret).then(function(result) {
 | 
				
			||||||
 | 
					                        if (result.error) {
 | 
				
			||||||
 | 
					                          // Display error.message in your UI.
 | 
				
			||||||
 | 
					                          $("#3ds_result").text("Error!");
 | 
				
			||||||
 | 
					                          $("#3ds_result").addClass("text-danger");
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                          // The payment has succeeded. Display a success message.
 | 
				
			||||||
 | 
					                          $("#3ds_result").text("Thank you for payment");
 | 
				
			||||||
 | 
					                          $("#3ds_result").addClass("text-success");
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                      });
 | 
				
			||||||
 | 
					                    $('#3Dsecure-modal').show();
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    modal_btn.attr('href', "");
 | 
					                    $('#createvm-modal-title').text(data.msg_title);
 | 
				
			||||||
                }
 | 
					                    $('#createvm-modal-body').html(data.msg_body);
 | 
				
			||||||
                if (data.status === true) {
 | 
					                    if (data.redirect) {
 | 
				
			||||||
                    fa_icon.attr('class', 'checkmark');
 | 
					                        modal_btn.attr('href', data.redirect).removeClass('hide');
 | 
				
			||||||
                } else {
 | 
					                    } else {
 | 
				
			||||||
                    fa_icon.attr('class', 'fa fa-close');
 | 
					                        modal_btn.attr('href', "");
 | 
				
			||||||
                    modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide');
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (data.status === true) {
 | 
				
			||||||
 | 
					                        fa_icon.attr('class', 'checkmark');
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        fa_icon.attr('class', 'fa fa-close');
 | 
				
			||||||
 | 
					                        modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide');
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            error: function (xmlhttprequest, textstatus, message) {
 | 
					            error: function (xmlhttprequest, textstatus, message) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1195,6 +1195,21 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
 | 
				
			||||||
            tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [],
 | 
					            tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [],
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        stripe_subscription_obj = subscription_result.get('response_object')
 | 
					        stripe_subscription_obj = subscription_result.get('response_object')
 | 
				
			||||||
 | 
					        latest_invoice = stripe.Invoice.retrieve(stripe_subscription_obj.latest_invoice)
 | 
				
			||||||
 | 
					        ret = stripe.PaymentIntent.confirm(
 | 
				
			||||||
 | 
					            latest_invoice.payment_intent
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        if ret.status == 'requires_action':
 | 
				
			||||||
 | 
					            pi = stripe.PaymentIntent.retrieve(
 | 
				
			||||||
 | 
					                latest_invoice.payment_intent
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            context = {
 | 
				
			||||||
 | 
					                'sid': stripe_subscription_obj.id,
 | 
				
			||||||
 | 
					                'payment_intent_secret': pi.client_secret,
 | 
				
			||||||
 | 
					                'STRIPE_PUBLISHABLE_KEY': settings.STRIPE_API_PUBLIC_KEY,
 | 
				
			||||||
 | 
					                'showSCA': True
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return JsonResponse(context)
 | 
				
			||||||
        # Check if the subscription was approved and is active
 | 
					        # Check if the subscription was approved and is active
 | 
				
			||||||
        if (stripe_subscription_obj is None or
 | 
					        if (stripe_subscription_obj is None or
 | 
				
			||||||
                stripe_subscription_obj.status != 'active'):
 | 
					                stripe_subscription_obj.status != 'active'):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -322,6 +322,7 @@ class StripeUtils(object):
 | 
				
			||||||
            customer=customer, items=plans, trial_end=trial_end,
 | 
					            customer=customer, items=plans, trial_end=trial_end,
 | 
				
			||||||
            coupon=coupon,
 | 
					            coupon=coupon,
 | 
				
			||||||
            default_tax_rates=tax_rates,
 | 
					            default_tax_rates=tax_rates,
 | 
				
			||||||
 | 
					            payment_behavior='allow_incomplete'
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return subscription_result
 | 
					        return subscription_result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue