Refactor to create PayPal order first

This commit is contained in:
dinamiko 2022-07-13 16:11:33 +02:00
parent d248a278be
commit 09ef106a80
6 changed files with 204 additions and 51 deletions

View file

@ -1,4 +1,33 @@
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) => {
@ -12,4 +41,6 @@ window.addEventListener('load', function() {
window.open(oxxoButton.href);
}
*/
});