🏨 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>
348 lines
12 KiB
JavaScript
348 lines
12 KiB
JavaScript
/**
|
|
* 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);
|
|
}
|
|
}
|
|
});
|
|
}); |