Hide webhook elements when sandbox state is not matching the server

This commit is contained in:
Alex P 2023-03-10 10:39:13 +02:00
parent 8188faeec4
commit 9adcfe4b7d
No known key found for this signature in database
GPG key ID: 54487A734A204D71
3 changed files with 41 additions and 6 deletions

View file

@ -1,3 +1,5 @@
import {setVisibleByClass} from "../../../ppcp-button/resources/js/modules/Helper/Hiding"
document.addEventListener(
'DOMContentLoaded',
() => {
@ -147,5 +149,25 @@ document.addEventListener(
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 serverSandboxState = PayPalCommerceGatewayWebhooksStatus.environment === 'sandbox';
setWebhooksVisibility(serverSandboxState === sandboxCheckbox.checked);
sandboxCheckbox.addEventListener('click', () => {
setWebhooksVisibility(serverSandboxState === sandboxCheckbox.checked);
});
}
}
);

View file

@ -167,7 +167,8 @@ return array(
'webhook.status.assets' => function( ContainerInterface $container ) : WebhooksStatusPageAssets {
return new WebhooksStatusPageAssets(
$container->get( 'webhook.module-url' ),
$container->get( 'ppcp.asset-version' )
$container->get( 'ppcp.asset-version' ),
$container->get( 'onboarding.environment' )
);
},

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Webhooks\Status\Assets;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulateEndpoint;
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulationStateEndpoint;
@ -33,18 +34,28 @@ class WebhooksStatusPageAssets {
*/
private $version;
/**
* The environment object.
*
* @var Environment
*/
private $environment;
/**
* WebhooksStatusPageAssets constructor.
*
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param string $module_url The URL to the module.
* @param string $version The assets version.
* @param Environment $environment The environment object.
*/
public function __construct(
string $module_url,
string $version
string $version,
Environment $environment
) {
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
$this->module_url = untrailingslashit( $module_url );
$this->version = $version;
$this->environment = $environment;
}
/**
@ -103,6 +114,7 @@ class WebhooksStatusPageAssets {
'tooLongDelayMessage' => __( 'Looks like the webhook cannot be received. Check that your website is accessible from the internet.', 'woocommerce-paypal-payments' ),
),
),
'environment' => $this->environment->current_environment(),
);
}