mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
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();
|
|
});
|
|
}
|
|
);
|