110 lines
3.6 KiB
JavaScript
110 lines
3.6 KiB
JavaScript
|
|
/**
|
||
|
|
* Preauthorization Admin JavaScript
|
||
|
|
*
|
||
|
|
* Handles preauthorization capture and cancellation
|
||
|
|
*
|
||
|
|
* 🤖 Generated with Claude Code (https://claude.ai/code)
|
||
|
|
*/
|
||
|
|
|
||
|
|
jQuery(document).ready(function($) {
|
||
|
|
|
||
|
|
// Capture preauthorization
|
||
|
|
$(document).on('click', '.capture-preauth', function() {
|
||
|
|
if (!confirm(ebPreauth.strings.confirmCapture)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var $button = $(this);
|
||
|
|
var preauthId = $button.data('preauth-id');
|
||
|
|
var bookingId = $button.data('booking-id');
|
||
|
|
var originalText = $button.text();
|
||
|
|
|
||
|
|
$button.text('Capturing...').prop('disabled', true);
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: ebPreauth.ajaxurl,
|
||
|
|
type: 'POST',
|
||
|
|
data: {
|
||
|
|
action: 'capture_preauth',
|
||
|
|
nonce: ebPreauth.nonce,
|
||
|
|
preauth_id: preauthId,
|
||
|
|
booking_id: bookingId
|
||
|
|
},
|
||
|
|
success: function(response) {
|
||
|
|
if (response.success) {
|
||
|
|
showNotice('Preauthorization captured successfully!', 'success');
|
||
|
|
location.reload();
|
||
|
|
} else {
|
||
|
|
showNotice('Error: ' + response.data, 'error');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function() {
|
||
|
|
showNotice('An error occurred while capturing the preauthorization.', 'error');
|
||
|
|
},
|
||
|
|
complete: function() {
|
||
|
|
$button.text(originalText).prop('disabled', false);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
// Cancel preauthorization
|
||
|
|
$(document).on('click', '.cancel-preauth', function() {
|
||
|
|
if (!confirm(ebPreauth.strings.confirmCancel)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var $button = $(this);
|
||
|
|
var preauthId = $button.data('preauth-id');
|
||
|
|
var bookingId = $button.data('booking-id');
|
||
|
|
var originalText = $button.text();
|
||
|
|
|
||
|
|
$button.text('Cancelling...').prop('disabled', true);
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: ebPreauth.ajaxurl,
|
||
|
|
type: 'POST',
|
||
|
|
data: {
|
||
|
|
action: 'cancel_preauth',
|
||
|
|
nonce: ebPreauth.nonce,
|
||
|
|
preauth_id: preauthId,
|
||
|
|
booking_id: bookingId
|
||
|
|
},
|
||
|
|
success: function(response) {
|
||
|
|
if (response.success) {
|
||
|
|
showNotice('Preauthorization cancelled successfully!', 'success');
|
||
|
|
location.reload();
|
||
|
|
} else {
|
||
|
|
showNotice('Error: ' + response.data, 'error');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function() {
|
||
|
|
showNotice('An error occurred while cancelling the preauthorization.', 'error');
|
||
|
|
},
|
||
|
|
complete: function() {
|
||
|
|
$button.text(originalText).prop('disabled', false);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
// Show admin notices
|
||
|
|
function showNotice(message, type) {
|
||
|
|
var noticeClass = type === 'success' ? 'notice-success' : 'notice-error';
|
||
|
|
var $notice = $('<div class="notice ' + noticeClass + ' is-dismissible"><p>' + message + '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>');
|
||
|
|
|
||
|
|
$('.wrap h1').after($notice);
|
||
|
|
|
||
|
|
// Auto-dismiss after 5 seconds
|
||
|
|
setTimeout(function() {
|
||
|
|
$notice.fadeOut(function() {
|
||
|
|
$(this).remove();
|
||
|
|
});
|
||
|
|
}, 5000);
|
||
|
|
|
||
|
|
// Handle manual dismiss
|
||
|
|
$notice.find('.notice-dismiss').on('click', function() {
|
||
|
|
$notice.fadeOut(function() {
|
||
|
|
$(this).remove();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|