fix(ui): Add confirmation box in cancel mmqr payment
This commit is contained in:
@@ -441,36 +441,58 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#cancel-btn').on('click', function(e) {
|
$('#cancel-btn').on('click', function(e) {
|
||||||
document.getElementById('fullpage-loading').style.display = 'flex';
|
e.preventDefault(); // Prevent any default button action
|
||||||
|
|
||||||
setTimeout(function() {
|
swal({
|
||||||
document.getElementById('fullpage-loading').style.display = 'none';
|
title: "Are you sure?",
|
||||||
}, 5000);
|
text: "Do you really want to cancel this transaction?",
|
||||||
const postData = {
|
type: "warning",
|
||||||
sale_id: "<%= @sale_data.sale_id %>"
|
showCancelButton: true,
|
||||||
};
|
confirmButtonColor: "#DD6B55",
|
||||||
|
confirmButtonText: "Yes, cancel it!",
|
||||||
|
cancelButtonText: "No, keep it.",
|
||||||
|
closeOnConfirm: false,
|
||||||
|
showLoaderOnConfirm: true,
|
||||||
|
},
|
||||||
|
function(isConfirm){
|
||||||
|
if (isConfirm) {
|
||||||
|
// User clicked "Yes", so we proceed with the cancellation.
|
||||||
|
const postData = {
|
||||||
|
sale_id: "<%= @sale_data.sale_id %>"
|
||||||
|
};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/foodcourt/qrpay/cancel',
|
url: '/foodcourt/qrpay/cancel',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
|
||||||
},
|
},
|
||||||
data: JSON.stringify(postData),
|
data: JSON.stringify(postData),
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data.status) {
|
if (data.status) {
|
||||||
customer_display_view(null, "reload");
|
swal({
|
||||||
}
|
title: "Cancelled!",
|
||||||
},
|
text: "The transaction has been successfully cancelled. You will be redirected shortly.",
|
||||||
error: function(xhr, status, error) {
|
type: "success",
|
||||||
console.log("Error:", error);
|
timer: 2000, // The alert will close automatically after 2 seconds
|
||||||
|
showConfirmButton: false
|
||||||
|
});
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = "/";
|
||||||
|
}, 1500); // 1.5-second delay before redirecting
|
||||||
|
|
||||||
|
} else {
|
||||||
|
swal("Error", "Could not cancel the transaction. Please try again.", "error");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.log("Error:", error);
|
||||||
|
swal("AJAX Error", "An unexpected error occurred. Please check the console.", "error");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = "/";
|
|
||||||
}, 1500);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user