mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
document.addEventListener(
|
|
'DOMContentLoaded',
|
|
() => {
|
|
jQuery('.ppcp-delete-payment-button').click(async (event) => {
|
|
event.preventDefault();
|
|
jQuery(this).prop('disabled', true);
|
|
const token = event.target.id;
|
|
|
|
const response = await fetch(
|
|
PayPalCommerceGatewayVaulting.delete.endpoint,
|
|
{
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
headers: {
|
|
'content-type': 'application/json'
|
|
},
|
|
body: JSON.stringify(
|
|
{
|
|
nonce: PayPalCommerceGatewayVaulting.delete.nonce,
|
|
token,
|
|
}
|
|
)
|
|
}
|
|
);
|
|
|
|
const reportError = error => {
|
|
alert(error);
|
|
}
|
|
|
|
if (!response.ok) {
|
|
try {
|
|
const result = await response.json();
|
|
reportError(result.data);
|
|
} catch (exc) {
|
|
console.error(exc);
|
|
reportError(response.status);
|
|
}
|
|
}
|
|
|
|
window.location.reload();
|
|
});
|
|
});
|