mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add resubscribe webhooks button
This commit is contained in:
parent
1720c12ef3
commit
d908445e5e
6 changed files with 159 additions and 2 deletions
|
@ -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();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue