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) {
|
||||
fa_icon = $('.modal-icon > .fa');
|
||||
modal_btn = $('#createvm-modal-done-btn');
|
||||
$('#createvm-modal-title').text(data.msg_title);
|
||||
$('#createvm-modal-body').html(data.msg_body);
|
||||
if (data.redirect) {
|
||||
modal_btn.attr('href', data.redirect).removeClass('hide');
|
||||
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 {
|
||||
modal_btn.attr('href', "");
|
||||
}
|
||||
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');
|
||||
$('#createvm-modal-title').text(data.msg_title);
|
||||
$('#createvm-modal-body').html(data.msg_body);
|
||||
if (data.redirect) {
|
||||
modal_btn.attr('href', data.redirect).removeClass('hide');
|
||||
} else {
|
||||
modal_btn.attr('href', "");
|
||||
}
|
||||
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) {
|
||||
|
|
|
@ -1195,6 +1195,21 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
|
|||
tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [],
|
||||
)
|
||||
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
|
||||
if (stripe_subscription_obj is None or
|
||||
stripe_subscription_obj.status != 'active'):
|
||||
|
|
|
@ -322,6 +322,7 @@ class StripeUtils(object):
|
|||
customer=customer, items=plans, trial_end=trial_end,
|
||||
coupon=coupon,
|
||||
default_tax_rates=tax_rates,
|
||||
payment_behavior='allow_incomplete'
|
||||
)
|
||||
return subscription_result
|
||||
|
||||
|
|
Loading…
Reference in a new issue