Show SCA modal when required

This commit is contained in:
PCoder 2020-10-11 16:01:55 +05:30
parent c2e2e1828f
commit 70bfef4738
3 changed files with 45 additions and 11 deletions

View file

@ -107,6 +107,23 @@ $(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');
if (data.showSCA){
console.log("Show SCA");
var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY);
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 {
$('#createvm-modal-title').text(data.msg_title); $('#createvm-modal-title').text(data.msg_title);
$('#createvm-modal-body').html(data.msg_body); $('#createvm-modal-body').html(data.msg_body);
if (data.redirect) { if (data.redirect) {
@ -120,6 +137,7 @@ $(document).ready(function() {
fa_icon.attr('class', 'fa fa-close'); fa_icon.attr('class', 'fa fa-close');
modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide'); modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide');
} }
}
}, },
error: function (xmlhttprequest, textstatus, message) { error: function (xmlhttprequest, textstatus, message) {
fa_icon = $('.modal-icon > .fa'); fa_icon = $('.modal-icon > .fa');

View file

@ -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'):

View file

@ -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