diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php b/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php index 2cbc9c93b..d5b328a98 100644 --- a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php +++ b/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php @@ -24,6 +24,9 @@ class DisableGateways public function handler(array $methods): array { + if (! isset($methods[WcGateway::ID])) { + return $methods; + } if ( ! $this->settings->has('merchant_email') || ! is_email($this->settings->get('merchant_email')) diff --git a/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php b/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php index 918a8a003..74720f4df 100644 --- a/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php +++ b/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php @@ -72,6 +72,10 @@ class WcGateway extends \WC_Payment_Gateway ); } + public function needs_setup() { + return true; + } + public function init_form_fields() { $this->form_fields = [ diff --git a/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php b/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php index ab7f1b808..ab78440f5 100644 --- a/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php +++ b/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php @@ -14,6 +14,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways; use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway; use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice; use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice; +use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings; use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use Interop\Container\ServiceProviderInterface; use Psr\Container\ContainerInterface; @@ -54,6 +55,35 @@ class WcGatewayModule implements ModuleInterface return $notices; } ); + + add_action( + 'wp_ajax_woocommerce_toggle_gateway_enabled', + function() use ($container) { + if ( + ! current_user_can( 'manage_woocommerce' ) + || ! check_ajax_referer( + 'woocommerce-toggle-payment-gateway-enabled', + 'security' + ) + || ! isset( $_POST['gateway_id'] ) + ) { + return; + } + + /** + * @var Settings $settings + */ + $settings = $container->get('wcgateway.settings'); + $enabled = $settings->has('enabled') ? $settings->get('enabled') : false; + if (! $enabled) { + return; + } + $settings->set('enabled', false); + $settings->persist(); + }, + 9 + ); + } private function registerPaymentGateWay(ContainerInterface $container)