jQuery(document).ready(function ($) { const { id, url, code_setting } = hyperpay_data; const currencies_ids = $(`#woocommerce_${id}_currencies_ids_field`); const currencies_option = currencies_ids.data("currencies"); const currencies_list = currencies_ids.data("currencies_list"); const add_currencies_button = $(`
Add currency
`) const currencies_group = $( `
` ) const genInputs = (key = null, index = 0) => { let options = '' currencies_list.forEach(i => { options += `` }) return $( `
Leave it blank and save to remove
`) } Object.keys(currencies_ids.data("currencies")).forEach((key,index) => { currencies_group.find('#currencies_container').append(genInputs(key, index)) }) currencies_group.append(add_currencies_button) currencies_ids.parent().append(currencies_group) add_currencies_button.on('click', function () { let index = $("#currencies_container").children().length $('#currencies_container').append(genInputs(null,index)) }) // Convert TextArea for custom css field on admin settings wp.codeEditor.initialize($(`#woocommerce_${id}_custom_style`), code_setting); /** * Make Validation before submit settings via send request * to prepare checkout to make sure the access token and entity id is valid * @if return success response @then => resume submitting @else print error msg and preventDefault * * @returns {boolean} if valid or not * */ const from = $("#mainform"); from.on('submit', function (event) { $('.input-error-msg').remove(); let valid = false const accesstoken = $(this).find(`input[name='woocommerce_${id}_accesstoken']`); const entityId = $(this).find(`input[name='woocommerce_${id}_entityId']`); const dataToSend = { entityId: entityId.val(), }; $.ajax({ type: 'POST', async: false, headers: { Authorization: `Bearer ${accesstoken.val()}` }, url: url, data: dataToSend, dataType: "json", success: function () { valid = true }, error: function (resultData) { valid = false; accesstoken.addClass('input-error').after(`

${resultData.responseJSON.result.description}

`); entityId.addClass('input-error').after(`

${resultData.responseJSON.result.description}

`); $('html, body').animate({ scrollTop: accesstoken.offset().top - 200 }, 200); }, }); return valid; }) });