Hide card button in previews when has acdc or separate gateway

This commit is contained in:
Alex P 2023-11-08 09:46:52 +02:00
parent 47728a78ff
commit c72a335cdd
No known key found for this signature in database
GPG key ID: 54487A734A204D71
4 changed files with 33 additions and 3 deletions

View file

@ -96,6 +96,11 @@ document.addEventListener(
renderPreview(settingsCallback, render);
}
function currentTabId() {
const params = new URLSearchParams(location.search);
return params.has('ppcp-tab') ? params.get('ppcp-tab') : params.get('section');
}
function shouldShowPayLaterButton() {
const payLaterButtonLocations = document.querySelector('[name="ppcp[pay_later_button_locations][]"]');
@ -106,6 +111,14 @@ document.addEventListener(
return payLaterButtonInput.checked && payLaterButtonLocations.selectedOptions.length > 0
}
function shouldDisableCardButton() {
if (currentTabId() === 'ppcp-card-button-gateway') {
return false;
}
return PayPalCommerceGatewaySettings.is_acdc_enabled || jQuery('#ppcp-allow_card_button_gateway').is(':checked');
}
function getPaypalScriptSettings() {
const disableFundingInput = jQuery('[name="ppcp[disable_funding][]"]');
let disabledSources = disableFundingInput.length > 0 ? disableFundingInput.val() : PayPalCommerceGatewaySettings.disabled_sources;
@ -130,6 +143,10 @@ document.addEventListener(
disabledSources = disabledSources.concat('credit')
}
if (shouldDisableCardButton()) {
disabledSources = disabledSources.concat('card');
}
if (disabledSources?.length) {
settings['disable-funding'] = disabledSources;
}

View file

@ -96,6 +96,13 @@ class SettingsPageAssets {
*/
private $is_settings_page;
/**
* Whether the ACDC gateway is enabled.
*
* @var bool
*/
private $is_acdc_enabled;
/**
* Assets constructor.
*
@ -110,6 +117,7 @@ class SettingsPageAssets {
* @param array $disabled_sources The list of disabled funding sources.
* @param array $all_funding_sources The list of all existing funding sources.
* @param bool $is_settings_page Whether it's a settings page of this plugin.
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
*/
public function __construct(
string $module_url,
@ -122,7 +130,8 @@ class SettingsPageAssets {
bool $is_pay_later_button_enabled,
array $disabled_sources,
array $all_funding_sources,
bool $is_settings_page
bool $is_settings_page,
bool $is_acdc_enabled
) {
$this->module_url = $module_url;
$this->version = $version;
@ -135,6 +144,7 @@ class SettingsPageAssets {
$this->disabled_sources = $disabled_sources;
$this->all_funding_sources = $all_funding_sources;
$this->is_settings_page = $is_settings_page;
$this->is_acdc_enabled = $is_acdc_enabled;
}
/**
@ -223,6 +233,7 @@ class SettingsPageAssets {
'environment' => $this->environment->current_environment(),
'integration_date' => PAYPAL_INTEGRATION_DATE,
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
'is_acdc_enabled' => $this->is_acdc_enabled,
'disabled_sources' => $this->disabled_sources,
'all_funding_sources' => $this->all_funding_sources,
'components' => array( 'buttons', 'funding-eligibility', 'messages' ),

View file

@ -185,7 +185,8 @@ class WCGatewayModule implements ModuleInterface {
$settings_status->is_pay_later_button_enabled(),
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
$c->get( 'wcgateway.settings.funding-sources' ),
$c->get( 'wcgateway.is-ppcp-settings-page' )
$c->get( 'wcgateway.is-ppcp-settings-page' ),
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' )
);
$assets->register_assets();
}

View file

@ -28,7 +28,8 @@ class SettingsPagesAssetsTest extends TestCase
true,
array(),
array(),
true
true,
false
);
when('is_admin')