Add resubscribe webhooks button

This commit is contained in:
Alex P 2021-09-16 17:08:43 +03:00
parent 1720c12ef3
commit d908445e5e
6 changed files with 159 additions and 2 deletions

View file

@ -1,6 +1,42 @@
document.addEventListener(
'DOMContentLoaded',
() => {
const resubscribeBtn = jQuery(PayPalCommerceGatewayWebhooksStatus.resubscribe.button);
resubscribeBtn.click(async () => {
resubscribeBtn.prop('disabled', true);
const response = await fetch(
PayPalCommerceGatewayWebhooksStatus.resubscribe.endpoint,
{
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(
{
nonce: PayPalCommerceGatewayWebhooksStatus.resubscribe.nonce,
}
)
}
);
const reportError = error => {
const msg = PayPalCommerceGatewayWebhooksStatus.resubscribe.failureMessage + ' ' + error;
alert(msg);
}
if (!response.ok) {
try {
const result = await response.json();
reportError(result.data);
} catch (exc) {
console.error(exc);
reportError(response.status);
}
}
window.location.reload();
});
}
);