mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge branch 'refs/heads/trunk' into modularity-module-migration
# Conflicts: # composer.lock # modules/ppcp-axo/src/AxoModule.php # modules/ppcp-blocks/src/BlocksModule.php # modules/ppcp-compat/src/CompatModule.php # modules/ppcp-googlepay/src/GooglepayModule.php # modules/ppcp-order-tracking/src/OrderTrackingModule.php # modules/ppcp-wc-subscriptions/src/WcSubscriptionsModule.php
This commit is contained in:
commit
4d9f23e315
301 changed files with 33875 additions and 13196 deletions
|
@ -1,173 +1,195 @@
|
|||
import {setVisibleByClass} from "../../../ppcp-button/resources/js/modules/Helper/Hiding"
|
||||
import { setVisibleByClass } from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const resubscribeBtn = jQuery(PayPalCommerceGatewayWebhooksStatus.resubscribe.button);
|
||||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
const resubscribeBtn = jQuery(
|
||||
PayPalCommerceGatewayWebhooksStatus.resubscribe.button
|
||||
);
|
||||
|
||||
resubscribeBtn.click(async () => {
|
||||
resubscribeBtn.prop('disabled', true);
|
||||
resubscribeBtn.click( async () => {
|
||||
resubscribeBtn.prop( 'disabled', true );
|
||||
|
||||
const response = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.resubscribe.endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(
|
||||
{
|
||||
nonce: PayPalCommerceGatewayWebhooksStatus.resubscribe.nonce,
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
const response = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.resubscribe.endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify( {
|
||||
nonce: PayPalCommerceGatewayWebhooksStatus.resubscribe
|
||||
.nonce,
|
||||
} ),
|
||||
}
|
||||
);
|
||||
|
||||
const reportError = error => {
|
||||
const msg = PayPalCommerceGatewayWebhooksStatus.resubscribe.failureMessage + ' ' + error;
|
||||
alert(msg);
|
||||
}
|
||||
const reportError = ( error ) => {
|
||||
const msg =
|
||||
PayPalCommerceGatewayWebhooksStatus.resubscribe.failureMessage +
|
||||
' ' +
|
||||
error;
|
||||
alert( msg );
|
||||
};
|
||||
|
||||
if (!response.ok) {
|
||||
try {
|
||||
const result = await response.json();
|
||||
reportError(result.data);
|
||||
} catch (exc) {
|
||||
console.error(exc);
|
||||
reportError(response.status);
|
||||
}
|
||||
}
|
||||
if ( ! response.ok ) {
|
||||
try {
|
||||
const result = await response.json();
|
||||
reportError( result.data );
|
||||
} catch ( exc ) {
|
||||
console.error( exc );
|
||||
reportError( response.status );
|
||||
}
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
});
|
||||
window.location.reload();
|
||||
} );
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
function sleep( ms ) {
|
||||
return new Promise( ( resolve ) => setTimeout( resolve, ms ) );
|
||||
}
|
||||
|
||||
const simulateBtn = jQuery(PayPalCommerceGatewayWebhooksStatus.simulation.start.button);
|
||||
simulateBtn.click(async () => {
|
||||
simulateBtn.prop('disabled', true);
|
||||
const simulateBtn = jQuery(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.start.button
|
||||
);
|
||||
simulateBtn.click( async () => {
|
||||
simulateBtn.prop( 'disabled', true );
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.start.endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(
|
||||
{
|
||||
nonce: PayPalCommerceGatewayWebhooksStatus.simulation.start.nonce,
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
try {
|
||||
const response = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.start.endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify( {
|
||||
nonce: PayPalCommerceGatewayWebhooksStatus.simulation
|
||||
.start.nonce,
|
||||
} ),
|
||||
}
|
||||
);
|
||||
|
||||
const reportError = error => {
|
||||
const msg = PayPalCommerceGatewayWebhooksStatus.simulation.start.failureMessage + ' ' + error;
|
||||
alert(msg);
|
||||
};
|
||||
const reportError = ( error ) => {
|
||||
const msg =
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.start
|
||||
.failureMessage +
|
||||
' ' +
|
||||
error;
|
||||
alert( msg );
|
||||
};
|
||||
|
||||
if (!response.ok) {
|
||||
try {
|
||||
const result = await response.json();
|
||||
reportError(result.data);
|
||||
} catch (exc) {
|
||||
console.error(exc);
|
||||
reportError(response.status);
|
||||
}
|
||||
if ( ! response.ok ) {
|
||||
try {
|
||||
const result = await response.json();
|
||||
reportError( result.data );
|
||||
} catch ( exc ) {
|
||||
console.error( exc );
|
||||
reportError( response.status );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const showStatus = html => {
|
||||
let statusBlock = simulateBtn.siblings('.ppcp-webhooks-status-text');
|
||||
if (!statusBlock.length) {
|
||||
statusBlock = jQuery('<div class="ppcp-webhooks-status-text"></div>').insertAfter(simulateBtn);
|
||||
}
|
||||
statusBlock.html(html);
|
||||
};
|
||||
const showStatus = ( html ) => {
|
||||
let statusBlock = simulateBtn.siblings(
|
||||
'.ppcp-webhooks-status-text'
|
||||
);
|
||||
if ( ! statusBlock.length ) {
|
||||
statusBlock = jQuery(
|
||||
'<div class="ppcp-webhooks-status-text"></div>'
|
||||
).insertAfter( simulateBtn );
|
||||
}
|
||||
statusBlock.html( html );
|
||||
};
|
||||
|
||||
simulateBtn.siblings('.description').hide();
|
||||
simulateBtn.siblings( '.description' ).hide();
|
||||
|
||||
showStatus(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state.waitingMessage +
|
||||
'<span class="spinner is-active" style="float: none;"></span>'
|
||||
);
|
||||
showStatus(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state
|
||||
.waitingMessage +
|
||||
'<span class="spinner is-active" style="float: none;"></span>'
|
||||
);
|
||||
|
||||
const delay = 2000;
|
||||
const retriesBeforeErrorMessage = 15;
|
||||
const maxRetries = 30;
|
||||
const delay = 2000;
|
||||
const retriesBeforeErrorMessage = 15;
|
||||
const maxRetries = 30;
|
||||
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
await sleep(delay);
|
||||
for ( let i = 0; i < maxRetries; i++ ) {
|
||||
await sleep( delay );
|
||||
|
||||
const stateResponse = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state.endpoint,
|
||||
{
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
}
|
||||
);
|
||||
const stateResponse = await fetch(
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state
|
||||
.endpoint,
|
||||
{
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
const result = await stateResponse.json();
|
||||
try {
|
||||
const result = await stateResponse.json();
|
||||
|
||||
if (!stateResponse.ok || !result.success) {
|
||||
console.error('Simulation state query failed: ' + result.data);
|
||||
continue;
|
||||
}
|
||||
if ( ! stateResponse.ok || ! result.success ) {
|
||||
console.error(
|
||||
'Simulation state query failed: ' + result.data
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const state = result.data.state;
|
||||
if (state === PayPalCommerceGatewayWebhooksStatus.simulation.state.successState) {
|
||||
showStatus(
|
||||
'<span class="success">' +
|
||||
'✔️ ' +
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state.successMessage +
|
||||
'</span>'
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch (exc) {
|
||||
console.error(exc);
|
||||
}
|
||||
const state = result.data.state;
|
||||
if (
|
||||
state ===
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state
|
||||
.successState
|
||||
) {
|
||||
showStatus(
|
||||
'<span class="success">' +
|
||||
'✔️ ' +
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation
|
||||
.state.successMessage +
|
||||
'</span>'
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch ( exc ) {
|
||||
console.error( exc );
|
||||
}
|
||||
|
||||
if (i === retriesBeforeErrorMessage) {
|
||||
showStatus(
|
||||
'<span class="error">' +
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state.tooLongDelayMessage +
|
||||
'</span>'
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( i === retriesBeforeErrorMessage ) {
|
||||
showStatus(
|
||||
'<span class="error">' +
|
||||
PayPalCommerceGatewayWebhooksStatus.simulation.state
|
||||
.tooLongDelayMessage +
|
||||
'</span>'
|
||||
);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
simulateBtn.prop( 'disabled', false );
|
||||
}
|
||||
} );
|
||||
|
||||
} finally {
|
||||
simulateBtn.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
const sandboxCheckbox = document.querySelector( '#ppcp-sandbox_on' );
|
||||
if ( sandboxCheckbox ) {
|
||||
const setWebhooksVisibility = ( show ) => {
|
||||
[
|
||||
'#field-webhook_status_heading',
|
||||
'#field-webhooks_list',
|
||||
'#field-webhooks_resubscribe',
|
||||
'#field-webhooks_simulate',
|
||||
].forEach( ( selector ) => {
|
||||
setVisibleByClass( selector, show, 'hide' );
|
||||
} );
|
||||
};
|
||||
|
||||
const sandboxCheckbox = document.querySelector('#ppcp-sandbox_on');
|
||||
if (sandboxCheckbox) {
|
||||
const setWebhooksVisibility = (show) => {
|
||||
[
|
||||
'#field-webhook_status_heading',
|
||||
'#field-webhooks_list',
|
||||
'#field-webhooks_resubscribe',
|
||||
'#field-webhooks_simulate',
|
||||
].forEach(selector => {
|
||||
setVisibleByClass(selector, show, 'hide');
|
||||
});
|
||||
};
|
||||
|
||||
const serverSandboxState = PayPalCommerceGatewayWebhooksStatus.environment === 'sandbox';
|
||||
setWebhooksVisibility(serverSandboxState === sandboxCheckbox.checked);
|
||||
sandboxCheckbox.addEventListener('click', () => {
|
||||
setWebhooksVisibility(serverSandboxState === sandboxCheckbox.checked);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
const serverSandboxState =
|
||||
PayPalCommerceGatewayWebhooksStatus.environment === 'sandbox';
|
||||
setWebhooksVisibility( serverSandboxState === sandboxCheckbox.checked );
|
||||
sandboxCheckbox.addEventListener( 'click', () => {
|
||||
setWebhooksVisibility(
|
||||
serverSandboxState === sandboxCheckbox.checked
|
||||
);
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks;
|
||||
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue