File: /home/luxbsolr/cardsord.store/wp-content/plugins/shopay-for-woocommerce/assets/js/admin.js
/**
* Admin JavaScript for Rendis Payments Gateway
*/
jQuery(function($) {
// Handle adding new store
$('#cpg-add-store').on('click', function() {
const storeTemplate = $('#cpg-store-template').html();
const storeCount = $('.cpg-store-fields').length;
const newStore = storeTemplate.replace(/{index}/g, storeCount);
$('#cpg-stores-container').append(newStore);
});
// Handle removing store (using event delegation for dynamically added elements)
$(document).on('click', '.cpg-remove-store', function() {
$(this).closest('.cpg-store-fields').remove();
// Reindex the remaining stores to ensure proper form submission
$('.cpg-store-fields').each(function(index) {
$(this).find('input').each(function() {
const name = $(this).attr('name');
const newName = name.replace(/\[stores\]\[\d+\]/, '[stores][' + index + ']');
$(this).attr('name', newName);
});
});
});
// License validation flow
$('#cpg-validate-license').on('click', function() {
const $btn = $(this);
const license = $('#cpg-license-key').val();
const nonce = cpg_params?.validate_nonce;
const ajaxUrl = cpg_params?.ajax_url;
if (!ajaxUrl || !nonce) {
alert('Missing AJAX configuration.');
return;
}
$btn.prop('disabled', true).text('Validating...');
$('#cpg-license-status').removeClass('license-valid license-invalid').text('');
$.post(ajaxUrl, {
action: 'cpg_validate_license',
nonce,
license_key: license
}).done(function(resp){
if (resp && resp.success) {
$('#cpg-license-status').addClass('license-valid').text('License valid');
// Show modal
const $modal = $('#cpg-license-modal');
if ($modal.length) {
$modal.fadeIn(150);
}
} else {
const message = resp && resp.data ? resp.data : 'Invalid license key';
$('#cpg-license-status').addClass('license-invalid').text(message);
}
}).fail(function(){
$('#cpg-license-status').addClass('license-invalid').text('Validation failed');
}).always(function(){
$btn.prop('disabled', false).text('Validate License');
});
});
// Modal close handlers
$(document).on('click', '.cpg-modal-close, .cpg-modal-backdrop', function(){
$('#cpg-license-modal').fadeOut(150);
});
});