Add mechanism to refresh feature status.

This commit is contained in:
Pedro Silva 2023-12-12 17:30:55 +00:00
parent be28f81758
commit d2abeb5dbf
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
8 changed files with 178 additions and 5 deletions

View file

@ -353,5 +353,42 @@ document.addEventListener(
}, 'card'));
});
}
(() => {
const props = PayPalCommerceGatewaySettings.ajax.refresh_feature_status;
const $btn = jQuery(props.button);
$btn.click(async () => {
$btn.prop('disabled', true);
const response = await fetch(
props.endpoint,
{
method: 'POST',
credentials: 'same-origin',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(
{
nonce: props.nonce,
}
)
}
);
const responseData = await response.json();
if (!responseData.success) {
alert(responseData.data.message);
$btn.prop('disabled', false);
} else {
window.location.reload();
}
});
})();
}
);