woocommerce-paypal-payments/modules/ppcp-vaulting/resources/js/myaccount-payments.js
Alex P 23cb96e6f9 Explicitly send cookies in fetch
Not sent by default in old browsers
2022-09-09 16:28:58 +03:00

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();
});
});