woocommerce-paypal-payments/modules/ppcp-webhooks/resources/js/status-page.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-09-16 13:48:20 +03:00
document.addEventListener(
'DOMContentLoaded',
() => {
2021-09-16 17:08:43 +03:00
const resubscribeBtn = jQuery(PayPalCommerceGatewayWebhooksStatus.resubscribe.button);
2021-09-16 13:48:20 +03:00
2021-09-16 17:08:43 +03:00
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();
});
2021-09-16 13:48:20 +03:00
}
);