Hotel Raxa - Advanced Booking System Implementation
🏨 Hotel Booking Enhancements: - Implemented Eagle Booking Advanced Pricing add-on - Added Booking.com-style rate management system - Created professional calendar interface for pricing - Integrated deals and discounts functionality 💰 Advanced Pricing Features: - Dynamic pricing models (per room, per person, per adult) - Base rates, adult rates, and child rates management - Length of stay discounts and early bird deals - Mobile rates and secret deals implementation - Seasonal promotions and flash sales 📅 Availability Management: - Real-time availability tracking - Stop sell and restriction controls - Closed to arrival/departure functionality - Minimum/maximum stay requirements - Automatic sold-out management 💳 Payment Integration: - Maintained Redsys payment gateway integration - Seamless integration with existing Eagle Booking - No modifications to core Eagle Booking plugin 🛠️ Technical Implementation: - Custom database tables for advanced pricing - WordPress hooks and filters integration - AJAX-powered admin interface - Data migration from existing Eagle Booking - Professional calendar view for revenue management 📊 Admin Interface: - Booking.com-style management dashboard - Visual rate and availability calendar - Bulk operations for date ranges - Statistics and analytics dashboard - Modal dialogs for quick editing 🔧 Code Quality: - WordPress coding standards compliance - Secure database operations with prepared statements - Proper input validation and sanitization - Error handling and logging - Responsive admin interface 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
* Payment Requests Admin JavaScript
|
||||
*
|
||||
* Handles the admin interface for payment requests
|
||||
*
|
||||
* 🤖 Generated with Claude Code (https://claude.ai/code)
|
||||
*/
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
|
||||
// Send payment request form
|
||||
$('#payment-request-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!confirm(ebPaymentRequests.strings.confirmSend)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $form = $(this);
|
||||
var $button = $form.find('button[type="submit"]');
|
||||
var originalText = $button.text();
|
||||
|
||||
// Show loading state
|
||||
$button.text('Sending...').prop('disabled', true);
|
||||
|
||||
var formData = {
|
||||
action: 'send_payment_request',
|
||||
nonce: ebPaymentRequests.nonce,
|
||||
booking_id: $('#booking_id').val(),
|
||||
customer_email: $('#customer_email').val(),
|
||||
amount: $('#amount').val(),
|
||||
description: $('#description').val(),
|
||||
expires_in: $('#expires_in').val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: ebPaymentRequests.ajaxurl,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('Payment request sent successfully!', 'success');
|
||||
$form[0].reset();
|
||||
// Reload the page to show updated table
|
||||
location.reload();
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred while sending the payment request.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Auto payment settings form
|
||||
$('#auto-payment-settings').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $form = $(this);
|
||||
var $button = $form.find('button[type="submit"]');
|
||||
var originalText = $button.text();
|
||||
|
||||
$button.text('Saving...').prop('disabled', true);
|
||||
|
||||
var formData = {
|
||||
action: 'save_auto_payment_settings',
|
||||
nonce: ebPaymentRequests.nonce,
|
||||
auto_requests_enabled: $('#auto_requests_enabled').is(':checked') ? 1 : 0,
|
||||
auto_percentage: $('#auto_percentage').val(),
|
||||
days_before: $('#days_before').val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: ebPaymentRequests.ajaxurl,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('Settings saved successfully!', 'success');
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred while saving settings.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Load booking details
|
||||
$('#load-booking').on('click', function() {
|
||||
var bookingId = $('#booking_id').val();
|
||||
|
||||
if (!bookingId) {
|
||||
alert('Please enter a booking ID first.');
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $(this);
|
||||
var originalText = $button.text();
|
||||
|
||||
$button.text('Loading...').prop('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: ebPaymentRequests.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'load_booking_details',
|
||||
nonce: ebPaymentRequests.nonce,
|
||||
booking_id: bookingId
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
var booking = response.data;
|
||||
$('#customer_email').val(booking.email);
|
||||
$('#amount').val(booking.total_price);
|
||||
$('#description').val('Payment for Hotel Raxa booking #' + bookingId);
|
||||
|
||||
showNotice('Booking details loaded successfully!', 'success');
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred while loading booking details.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Copy payment link functionality
|
||||
$(document).on('click', '.copy-link, .copy-payment-link', function() {
|
||||
var link = $(this).data('link');
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(link).then(function() {
|
||||
showNotice(ebPaymentRequests.strings.linkCopied, 'success');
|
||||
}).catch(function() {
|
||||
fallbackCopyTextToClipboard(link);
|
||||
});
|
||||
} else {
|
||||
fallbackCopyTextToClipboard(link);
|
||||
}
|
||||
});
|
||||
|
||||
// Fallback copy function for older browsers
|
||||
function fallbackCopyTextToClipboard(text) {
|
||||
var textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
|
||||
// Avoid scrolling to bottom
|
||||
textArea.style.top = "0";
|
||||
textArea.style.left = "0";
|
||||
textArea.style.position = "fixed";
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
var successful = document.execCommand('copy');
|
||||
if (successful) {
|
||||
showNotice(ebPaymentRequests.strings.linkCopied, 'success');
|
||||
} else {
|
||||
showNotice(ebPaymentRequests.strings.copyFailed, 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
showNotice(ebPaymentRequests.strings.copyFailed, 'error');
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
// Resend payment request
|
||||
$(document).on('click', '.resend-request', function() {
|
||||
var requestId = $(this).data('request-id');
|
||||
|
||||
if (!confirm('Are you sure you want to resend this payment request?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $(this);
|
||||
var originalText = $button.text();
|
||||
|
||||
$button.text('Sending...').prop('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: ebPaymentRequests.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'resend_payment_request',
|
||||
nonce: ebPaymentRequests.nonce,
|
||||
request_id: requestId
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('Payment request resent successfully!', 'success');
|
||||
location.reload();
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred while resending the payment request.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Send new payment request from booking metabox
|
||||
$(document).on('click', '#send-new-payment-request', function() {
|
||||
var bookingId = $(this).data('booking-id');
|
||||
|
||||
// Create modal or redirect to payment requests page with booking ID pre-filled
|
||||
var paymentRequestsUrl = 'admin.php?page=eb-payment-requests&booking_id=' + bookingId;
|
||||
window.open(paymentRequestsUrl, '_blank');
|
||||
});
|
||||
|
||||
// Auto-fill booking ID from URL parameter
|
||||
if (window.location.search.includes('booking_id=')) {
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var bookingId = urlParams.get('booking_id');
|
||||
if (bookingId) {
|
||||
$('#booking_id').val(bookingId).trigger('change');
|
||||
$('#load-booking').click();
|
||||
}
|
||||
}
|
||||
|
||||
// Real-time form validation
|
||||
$('#payment-request-form input[required]').on('blur', function() {
|
||||
var $input = $(this);
|
||||
var value = $input.val().trim();
|
||||
|
||||
if (!value) {
|
||||
$input.css('border-color', '#dc3545');
|
||||
$input.next('.validation-message').remove();
|
||||
$input.after('<span class="validation-message" style="color: #dc3545; font-size: 12px;">This field is required</span>');
|
||||
} else {
|
||||
$input.css('border-color', '');
|
||||
$input.next('.validation-message').remove();
|
||||
}
|
||||
});
|
||||
|
||||
// Email validation
|
||||
$('#customer_email').on('blur', function() {
|
||||
var $input = $(this);
|
||||
var email = $input.val().trim();
|
||||
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
if (email && !emailRegex.test(email)) {
|
||||
$input.css('border-color', '#dc3545');
|
||||
$input.next('.validation-message').remove();
|
||||
$input.after('<span class="validation-message" style="color: #dc3545; font-size: 12px;">Please enter a valid email address</span>');
|
||||
} else if (email) {
|
||||
$input.css('border-color', '#28a745');
|
||||
$input.next('.validation-message').remove();
|
||||
}
|
||||
});
|
||||
|
||||
// Amount validation
|
||||
$('#amount').on('blur', function() {
|
||||
var $input = $(this);
|
||||
var amount = parseFloat($input.val());
|
||||
|
||||
if (amount && (amount <= 0 || amount > 10000)) {
|
||||
$input.css('border-color', '#dc3545');
|
||||
$input.next('.validation-message').remove();
|
||||
$input.after('<span class="validation-message" style="color: #dc3545; font-size: 12px;">Amount must be between 0.01 and 10,000 EUR</span>');
|
||||
} else if (amount) {
|
||||
$input.css('border-color', '#28a745');
|
||||
$input.next('.validation-message').remove();
|
||||
}
|
||||
});
|
||||
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize tooltips (if using WordPress admin tooltips)
|
||||
if ($.fn.tooltip) {
|
||||
$('[data-tooltip]').tooltip();
|
||||
}
|
||||
|
||||
// Auto-refresh payment requests table every 30 seconds
|
||||
if ($('.wp-list-table').length && window.location.href.includes('eb-payment-requests')) {
|
||||
setInterval(function() {
|
||||
// Only refresh if no forms are currently being submitted
|
||||
if (!$('button:disabled').length) {
|
||||
location.reload();
|
||||
}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
// Handle percentage input validation
|
||||
$('#auto_percentage').on('input', function() {
|
||||
var value = parseInt($(this).val());
|
||||
if (value < 1) $(this).val(1);
|
||||
if (value > 100) $(this).val(100);
|
||||
});
|
||||
|
||||
// Handle days before input validation
|
||||
$('#days_before').on('input', function() {
|
||||
var value = parseInt($(this).val());
|
||||
if (value < 1) $(this).val(1);
|
||||
if (value > 365) $(this).val(365);
|
||||
});
|
||||
|
||||
// Auto-calculate 50% of amount when loading booking
|
||||
$(document).on('change', '#amount', function() {
|
||||
var total = parseFloat($(this).val());
|
||||
if (total > 0) {
|
||||
var fiftyPercent = (total * 0.5).toFixed(2);
|
||||
var $description = $('#description');
|
||||
if (!$description.val()) {
|
||||
$description.val('50% payment for Hotel Raxa booking - €' + fiftyPercent);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* 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();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Payment Scheduler Admin JavaScript
|
||||
*
|
||||
* Handles the admin interface for the automated payment scheduler
|
||||
*
|
||||
* 🤖 Generated with Claude Code (https://claude.ai/code)
|
||||
*/
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
|
||||
// Save scheduler settings
|
||||
$('#scheduler-settings-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $form = $(this);
|
||||
var $button = $form.find('button[type="submit"]');
|
||||
var originalText = $button.text();
|
||||
|
||||
$button.text('Saving...').prop('disabled', true);
|
||||
|
||||
var formData = {
|
||||
action: 'save_scheduler_settings',
|
||||
nonce: ebScheduler.nonce,
|
||||
days_before: $('#days_before').val(),
|
||||
percentage: $('#percentage').val(),
|
||||
expiry_hours: $('#expiry_hours').val(),
|
||||
admin_notifications: $('#admin_notifications').is(':checked') ? 'yes' : 'no'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: ebScheduler.ajaxurl,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('Settings saved successfully!', 'success');
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred while saving settings.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Manual payment check
|
||||
$('#manual-payment-check').on('click', function() {
|
||||
if (!confirm(ebScheduler.strings.confirmManualRun)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $(this);
|
||||
var originalText = $button.text();
|
||||
|
||||
$button.text(ebScheduler.strings.processing).prop('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: ebScheduler.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'manual_payment_check',
|
||||
nonce: ebScheduler.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
var results = response.data;
|
||||
var message = 'Manual check completed!\n\n' +
|
||||
'Processed: ' + results.processed + ' bookings\n' +
|
||||
'Sent: ' + results.sent + ' payment requests\n' +
|
||||
'Skipped: ' + results.skipped + ' bookings\n' +
|
||||
'Errors: ' + results.errors;
|
||||
|
||||
showNotice(message.replace(/\n/g, '<br>'), 'success');
|
||||
|
||||
// Reload page after 3 seconds to show updated activity
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
}, 3000);
|
||||
} else {
|
||||
showNotice('Error: ' + response.data, 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('An error occurred during the manual check.', 'error');
|
||||
},
|
||||
complete: function() {
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Form validation
|
||||
$('#days_before').on('input', function() {
|
||||
var value = parseInt($(this).val());
|
||||
if (value < 1) $(this).val(1);
|
||||
if (value > 365) $(this).val(365);
|
||||
});
|
||||
|
||||
$('#percentage').on('input', function() {
|
||||
var value = parseInt($(this).val());
|
||||
if (value < 1) $(this).val(1);
|
||||
if (value > 100) $(this).val(100);
|
||||
});
|
||||
|
||||
// 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 8 seconds
|
||||
setTimeout(function() {
|
||||
$notice.fadeOut(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 8000);
|
||||
|
||||
// Handle manual dismiss
|
||||
$notice.find('.notice-dismiss').on('click', function() {
|
||||
$notice.fadeOut(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Real-time activity updates (every 60 seconds if on the page)
|
||||
if (window.location.href.includes('eb-payment-scheduler')) {
|
||||
setInterval(function() {
|
||||
// Only refresh if no forms are currently being submitted
|
||||
if (!$('button:disabled').length) {
|
||||
$('.activity-log').load(location.href + ' .activity-log > *');
|
||||
}
|
||||
}, 60000);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user