Use different js code for one-time and subscriptions

This commit is contained in:
PCoder 2021-01-01 00:09:47 +05:30
parent 2c3d00f03f
commit ba3c5ddd1d

View file

@ -92,101 +92,102 @@ $(document).ready(function() {
}); });
var create_vm_form = $('#virtual_machine_create_form'); var create_vm_form = $('#virtual_machine_create_form');
create_vm_form.submit(placeOrderPaymentIntent); if (window.isSubscription) {
create_vm_form.submit(function () {
function placeOrderPaymentIntent(e) { $('#btn-create-vm').prop('disabled', true);
e.preventDefault(); $.ajax({
var stripe = Stripe(window.stripeKey); url: create_vm_form.attr('action'),
stripe.confirmCardPayment( type: 'POST',
window.paymentIntentSecret, data: create_vm_form.serialize(),
{ init: function () {
payment_method: window.pm_id ok_btn = $('#createvm-modal-done-btn');
} close_btn = $('#createvm-modal-close-btn');
).then(function(result) { ok_btn.addClass('btn btn-success btn-ok btn-wide hide');
window.result = result; close_btn.addClass('btn btn-danger btn-ok btn-wide hide');
fa_icon = $('.modal-icon > .fa'); },
modal_btn = $('#createvm-modal-done-btn'); success: function (data) {
if (result.error) { fa_icon = $('.modal-icon > .fa');
// Display error.message in your UI. modal_btn = $('#createvm-modal-done-btn');
modal_btn.attr('href', error_url).removeClass('hide'); if (data.showSCA) {
fa_icon.attr('class', 'fa fa-close'); console.log("Show SCA");
modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide'); var stripe = Stripe(data.STRIPE_PUBLISHABLE_KEY);
$('#createvm-modal-title').text(error_title); stripe.confirmCardPayment(data.payment_intent_secret).then(function (result) {
$('#createvm-modal-body').html(result.error.message + " " + error_msg); if (result.error) {
} else { // Display error.message in your UI.
// The payment has succeeded modal_btn.attr('href', data.error.redirect).removeClass('hide');
// Display a success message fa_icon.attr('class', 'fa fa-close');
modal_btn.attr('href', success_url).removeClass('hide'); modal_btn.attr('class', '').addClass('btn btn-danger btn-ok btn-wide');
fa_icon.attr('class', 'checkmark'); $('#createvm-modal-title').text(data.error.msg_title);
$('#createvm-modal-title').text(success_title); $('#createvm-modal-body').html(data.error.msg_body);
$('#createvm-modal-body').html(success_msg); } else {
} // The payment has succeeded. Display a success message.
}); modal_btn.attr('href', data.success.redirect).removeClass('hide');
} fa_icon.attr('class', 'checkmark');
/* $('#createvm-modal-title').text(data.success.msg_title);
create_vm_form.submit(function () { $('#createvm-modal-body').html(data.success.msg_body);
$('#btn-create-vm').prop('disabled', true); }
$.ajax({ });
url: create_vm_form.attr('action'), $('#3Dsecure-modal').show();
type: 'POST', } else {
data: create_vm_form.serialize(), $('#createvm-modal-title').text(data.msg_title);
init: function(){ $('#createvm-modal-body').html(data.msg_body);
ok_btn = $('#createvm-modal-done-btn'); if (data.redirect) {
close_btn = $('#createvm-modal-close-btn'); modal_btn.attr('href', data.redirect).removeClass('hide');
ok_btn.addClass('btn btn-success btn-ok btn-wide hide'); } else {
close_btn.addClass('btn btn-danger btn-ok btn-wide hide'); modal_btn.attr('href', "");
}, }
success: function (data) { if (data.status === true) {
fa_icon = $('.modal-icon > .fa'); fa_icon.attr('class', 'checkmark');
modal_btn = $('#createvm-modal-done-btn'); } else {
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.
modal_btn.attr('href', data.error.redirect).removeClass('hide');
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');
$('#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.
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();
} else {
$('#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'); error: function (xmlhttprequest, textstatus, message) {
} 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) {
fa_icon = $('.modal-icon > .fa'); fa_icon = $('.modal-icon > .fa');
fa_icon.attr('class', 'fa fa-close'); fa_icon.attr('class', 'fa fa-close');
if (typeof(create_vm_error_message) !== 'undefined') { if (typeof (create_vm_error_message) !== 'undefined') {
$('#createvm-modal-body').text(create_vm_error_message); $('#createvm-modal-body').text(create_vm_error_message);
} }
$('#btn-create-vm').prop('disabled', false); $('#btn-create-vm').prop('disabled', false);
$('#createvm-modal-close-btn').removeClass('hide'); $('#createvm-modal-close-btn').removeClass('hide');
} }
});
return false;
}); });
return false; } else {
});*/ create_vm_form.submit(placeOrderPaymentIntent);
function placeOrderPaymentIntent(e) {
e.preventDefault();
var stripe = Stripe(window.stripeKey);
stripe.confirmCardPayment(
window.paymentIntentSecret,
{
payment_method: window.pm_id
}
).then(function(result) {
window.result = result;
fa_icon = $('.modal-icon > .fa');
modal_btn = $('#createvm-modal-done-btn');
if (result.error) {
// Display error.message in your UI.
modal_btn.attr('href', error_url).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(error_title);
$('#createvm-modal-body').html(result.error.message + " " + error_msg);
} else {
// The payment has succeeded
// Display a success message
modal_btn.attr('href', success_url).removeClass('hide');
fa_icon.attr('class', 'checkmark');
$('#createvm-modal-title').text(success_title);
$('#createvm-modal-body').html(success_msg);
}
});
}
}
$('#createvm-modal').on('hidden.bs.modal', function () { $('#createvm-modal').on('hidden.bs.modal', function () {
$(this).find('.modal-footer .btn').addClass('hide'); $(this).find('.modal-footer .btn').addClass('hide');
}); });