mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add void button
This commit is contained in:
parent
be6b8a39ec
commit
22945c4df5
7 changed files with 513 additions and 23 deletions
53
modules/ppcp-wc-gateway/resources/js/void-button.js
Normal file
53
modules/ppcp-wc-gateway/resources/js/void-button.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
import {
|
||||
hide,
|
||||
show,
|
||||
} from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
|
||||
|
||||
document.addEventListener( 'DOMContentLoaded', function () {
|
||||
const refundButton = document.querySelector( 'button.refund-items' );
|
||||
if ( ! refundButton ) {
|
||||
return;
|
||||
}
|
||||
|
||||
refundButton.insertAdjacentHTML(
|
||||
'afterend',
|
||||
`<button class="button" type="button" id="pcpVoid">${ PcpVoidButton.button_text }</button>`
|
||||
);
|
||||
|
||||
hide( refundButton );
|
||||
|
||||
const voidButton = document.querySelector( '#pcpVoid' );
|
||||
|
||||
voidButton.addEventListener( 'click', async () => {
|
||||
if ( ! window.confirm( PcpVoidButton.popup_text ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
voidButton.setAttribute( 'disabled', 'disabled' );
|
||||
|
||||
const res = await fetch( PcpVoidButton.ajax.void.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify( {
|
||||
nonce: PcpVoidButton.ajax.void.nonce,
|
||||
wc_order_id: PcpVoidButton.wc_order_id,
|
||||
} ),
|
||||
} );
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if ( ! data.success ) {
|
||||
hide( voidButton );
|
||||
show( refundButton );
|
||||
|
||||
alert( PcpVoidButton.error_text );
|
||||
|
||||
throw Error( data.data.message );
|
||||
}
|
||||
|
||||
location.reload();
|
||||
} );
|
||||
} );
|
Loading…
Add table
Add a link
Reference in a new issue