2021-09-22 10:05:00 +02:00
|
|
|
document.addEventListener(
|
|
|
|
'DOMContentLoaded',
|
|
|
|
() => {
|
2021-09-22 15:49:24 +02:00
|
|
|
jQuery('.ppcp-delete-payment-button').click(async (event) => {
|
|
|
|
event.preventDefault();
|
2021-09-23 15:19:44 +02:00
|
|
|
jQuery(this).prop('disabled', true);
|
|
|
|
const token = event.target.id;
|
2021-09-22 15:49:24 +02:00
|
|
|
|
2021-09-23 15:19:44 +02:00
|
|
|
const response = await fetch(
|
|
|
|
PayPalCommerceGatewayVaulting.delete.endpoint,
|
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
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();
|
2021-09-22 15:49:24 +02:00
|
|
|
});
|
2021-09-22 10:05:00 +02:00
|
|
|
});
|