Prevent enabling Standard Card Button when ACDC is enabled

This commit is contained in:
George Burduli 2024-07-10 09:23:04 +04:00
parent 36a13f6500
commit 49faab654a
No known key found for this signature in database
GPG key ID: 572A97DFDA3D2E5C
3 changed files with 44 additions and 9 deletions

View file

@ -125,10 +125,6 @@ document.addEventListener(
}
function shouldDisableCardButton() {
if (currentTabId() === 'ppcp-card-button-gateway') {
return false;
}
return PayPalCommerceGatewaySettings.is_acdc_enabled || jQuery('#ppcp-allow_card_button_gateway').is(':checked');
}
@ -157,6 +153,11 @@ document.addEventListener(
}
if (shouldDisableCardButton()) {
const standardCardButtonInput = document.querySelector('#woocommerce_ppcp-card-button-gateway_enabled');
if (standardCardButtonInput) {
standardCardButtonInput.disabled = true;
}
disabledSources = disabledSources.concat('card');
}

View file

@ -22,6 +22,7 @@ class GatewayWithoutPayPalAdminNotice {
private const NOTICE_OK = '';
private const NOTICE_DISABLED_GATEWAY = 'disabled_gateway';
private const NOTICE_DISABLED_LOCATION = 'disabled_location';
private const NOTICE_DISABLED_CARD_BUTTON = 'disabled_card';
/**
* The gateway ID.
@ -114,6 +115,15 @@ class GatewayWithoutPayPalAdminNotice {
'woocommerce-paypal-payments'
);
break;
case self::NOTICE_DISABLED_CARD_BUTTON:
/* translators: %1$s Standard Card Button section URL, %2$s Advanced Card Processing section URL. */
$text = __(
'The <a href="%1$s">Standard Card Button</a> cannot be used while <a href="%2$s">Advanced Card Processing</a> is enabled.',
'woocommerce-paypal-payments'
);
$url1 = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-card-button-gateway' );
$url2 = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway' );
break;
default:
return null;
}
@ -125,11 +135,20 @@ class GatewayWithoutPayPalAdminNotice {
$name = $gateway->get_method_title();
$message = sprintf(
$text,
$name,
admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' )
);
if ( $notice_type === self::NOTICE_DISABLED_CARD_BUTTON ) {
$message = sprintf(
$text,
$url1,
$url2
);
} else {
$message = sprintf(
$text,
$name,
admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' )
);
}
return new Message( $message, 'warning' );
}
@ -160,6 +179,13 @@ class GatewayWithoutPayPalAdminNotice {
return self::NOTICE_DISABLED_LOCATION;
}
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ?? false;
$is_card_button_allowed = $this->settings->has( 'allow_card_button_gateway' ) && $this->settings->get( 'allow_card_button_gateway' );
if ( $is_dcc_enabled && $is_card_button_allowed ) {
return self::NOTICE_DISABLED_CARD_BUTTON;
}
return self::NOTICE_OK;
}

View file

@ -528,6 +528,14 @@ class WCGatewayModule implements ModuleInterface {
return $methods;
}
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
$standard_card_button = get_option( 'woocommerce_ppcp-card-button-gateway_settings' );
if ( $is_dcc_enabled && isset( $standard_card_button['enabled'] ) ) {
$standard_card_button['enabled'] = 'no';
update_option( 'woocommerce_ppcp-card-button-gateway_settings', $standard_card_button );
}
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
assert( $dcc_applies instanceof DccApplies );