mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Hide card button in previews when has acdc or separate gateway
This commit is contained in:
parent
47728a78ff
commit
c72a335cdd
4 changed files with 33 additions and 3 deletions
|
@ -96,6 +96,11 @@ document.addEventListener(
|
||||||
renderPreview(settingsCallback, render);
|
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() {
|
function shouldShowPayLaterButton() {
|
||||||
const payLaterButtonLocations = document.querySelector('[name="ppcp[pay_later_button_locations][]"]');
|
const payLaterButtonLocations = document.querySelector('[name="ppcp[pay_later_button_locations][]"]');
|
||||||
|
|
||||||
|
@ -106,6 +111,14 @@ document.addEventListener(
|
||||||
return payLaterButtonInput.checked && payLaterButtonLocations.selectedOptions.length > 0
|
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() {
|
function getPaypalScriptSettings() {
|
||||||
const disableFundingInput = jQuery('[name="ppcp[disable_funding][]"]');
|
const disableFundingInput = jQuery('[name="ppcp[disable_funding][]"]');
|
||||||
let disabledSources = disableFundingInput.length > 0 ? disableFundingInput.val() : PayPalCommerceGatewaySettings.disabled_sources;
|
let disabledSources = disableFundingInput.length > 0 ? disableFundingInput.val() : PayPalCommerceGatewaySettings.disabled_sources;
|
||||||
|
@ -130,6 +143,10 @@ document.addEventListener(
|
||||||
disabledSources = disabledSources.concat('credit')
|
disabledSources = disabledSources.concat('credit')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldDisableCardButton()) {
|
||||||
|
disabledSources = disabledSources.concat('card');
|
||||||
|
}
|
||||||
|
|
||||||
if (disabledSources?.length) {
|
if (disabledSources?.length) {
|
||||||
settings['disable-funding'] = disabledSources;
|
settings['disable-funding'] = disabledSources;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,13 @@ class SettingsPageAssets {
|
||||||
*/
|
*/
|
||||||
private $is_settings_page;
|
private $is_settings_page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the ACDC gateway is enabled.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $is_acdc_enabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assets constructor.
|
* Assets constructor.
|
||||||
*
|
*
|
||||||
|
@ -110,6 +117,7 @@ class SettingsPageAssets {
|
||||||
* @param array $disabled_sources The list of disabled funding sources.
|
* @param array $disabled_sources The list of disabled funding sources.
|
||||||
* @param array $all_funding_sources The list of all existing 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_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(
|
public function __construct(
|
||||||
string $module_url,
|
string $module_url,
|
||||||
|
@ -122,7 +130,8 @@ class SettingsPageAssets {
|
||||||
bool $is_pay_later_button_enabled,
|
bool $is_pay_later_button_enabled,
|
||||||
array $disabled_sources,
|
array $disabled_sources,
|
||||||
array $all_funding_sources,
|
array $all_funding_sources,
|
||||||
bool $is_settings_page
|
bool $is_settings_page,
|
||||||
|
bool $is_acdc_enabled
|
||||||
) {
|
) {
|
||||||
$this->module_url = $module_url;
|
$this->module_url = $module_url;
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
|
@ -135,6 +144,7 @@ class SettingsPageAssets {
|
||||||
$this->disabled_sources = $disabled_sources;
|
$this->disabled_sources = $disabled_sources;
|
||||||
$this->all_funding_sources = $all_funding_sources;
|
$this->all_funding_sources = $all_funding_sources;
|
||||||
$this->is_settings_page = $is_settings_page;
|
$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(),
|
'environment' => $this->environment->current_environment(),
|
||||||
'integration_date' => PAYPAL_INTEGRATION_DATE,
|
'integration_date' => PAYPAL_INTEGRATION_DATE,
|
||||||
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
|
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
|
||||||
|
'is_acdc_enabled' => $this->is_acdc_enabled,
|
||||||
'disabled_sources' => $this->disabled_sources,
|
'disabled_sources' => $this->disabled_sources,
|
||||||
'all_funding_sources' => $this->all_funding_sources,
|
'all_funding_sources' => $this->all_funding_sources,
|
||||||
'components' => array( 'buttons', 'funding-eligibility', 'messages' ),
|
'components' => array( 'buttons', 'funding-eligibility', 'messages' ),
|
||||||
|
|
|
@ -185,7 +185,8 @@ class WCGatewayModule implements ModuleInterface {
|
||||||
$settings_status->is_pay_later_button_enabled(),
|
$settings_status->is_pay_later_button_enabled(),
|
||||||
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
||||||
$c->get( 'wcgateway.settings.funding-sources' ),
|
$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();
|
$assets->register_assets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ class SettingsPagesAssetsTest extends TestCase
|
||||||
true,
|
true,
|
||||||
array(),
|
array(),
|
||||||
array(),
|
array(),
|
||||||
true
|
true,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
when('is_admin')
|
when('is_admin')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue