mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
listen to ajax enable switch
This commit is contained in:
parent
d38b13b29c
commit
bf1737a22e
3 changed files with 37 additions and 0 deletions
|
@ -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'))
|
||||
|
|
|
@ -72,6 +72,10 @@ class WcGateway extends \WC_Payment_Gateway
|
|||
);
|
||||
}
|
||||
|
||||
public function needs_setup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function init_form_fields()
|
||||
{
|
||||
$this->form_fields = [
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue