woocommerce-paypal-payments/modules/ppcp-wc-gateway/resources/js/oxxo.js
2022-07-13 16:11:33 +02:00

46 lines
1.2 KiB
JavaScript

window.addEventListener('load', function() {
const oxxoButton = document.getElementById('ppcp-oxxo');
oxxoButton?.addEventListener('click', (event) => {
event.preventDefault();
fetch(OXXOConfig.oxxo_endpoint, {
method: 'POST',
body: JSON.stringify({
nonce: OXXOConfig.oxxo_nonce,
})
}).then((res)=>{
return res.json();
}).then((data)=>{
if (!data.success) {
alert('Could not update signup buttons: ' + JSON.stringify(data));
return;
}
window.open(
data.data.payer_action,
'_blank',
'popup'
);
document.querySelector('#place_order').click()
});
});
/*
const oxxoButton = document.getElementById('ppcp-oxxo-payer-action');
if(oxxoButton) {
oxxoButton.addEventListener('click', (event) => {
event.preventDefault();
window.open(
oxxoButton.href,
'_blank',
'popup'
);
});
window.open(oxxoButton.href);
}
*/
});