PluginProbe
HyperPay Payments / 1.7
HyperPay Payments v1.7
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / assets / js / admin.js

admin.js in HyperPay Payments 1.7, at assets/js/admin.js

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 const {id,url,code_setting} = data;
3
4 // Convert TeextArea for custom css field on admin settings
5 wp.codeEditor.initialize($(`#woocommerce_${id}_custom_style`), code_setting);
6
7 /**
8 * Make Validation before submit settings via send request
9 * to prepare checkout to make sure the access token and entity id is valid
10 * @if return success response @then => resume submitting @else print error msg and preventDefault
11 *
12 * @returns {boolean} if valid or not
13 *
14 */
15 const from = $("#mainform");
16
17 from.on('submit', function () {
18
19 $('.input-error-msg').remove();
20
21 let valid = false
22
23 const accesstoken = $(this).find(`input[name='woocommerce_${id}_accesstoken']`);
24 const entityId = $(this).find(`input[name='woocommerce_${id}_entityId']`);
25
26 const dataToSend = {
27 entityId: entityId.val(),
28 };
29
30 $.ajax({
31 type: 'POST',
32 async: false,
33 headers: {
34 Authorization: `Bearer ${accesstoken.val()}`
35 },
36 url: url,
37 data: dataToSend,
38 dataType: "json",
39 success: function () {
40 valid = true
41 },
42 error: function (resultData) {
43 valid = false;
44 accesstoken.addClass('input-error').after(`<p class='input-error-msg'>${resultData.responseJSON.result.description}</p>`);
45 entityId.addClass('input-error').after(`<p class='input-error-msg'>${resultData.responseJSON.result.description}</p>`);
46 $('html, body').animate({
47 scrollTop: accesstoken.offset().top - 200
48 }, 200);
49 },
50
51 });
52 return valid;
53 })
54
55 });