add admin notice if vault or messaging is enabled

This commit is contained in:
Kirill Braslavsky 2021-03-25 16:02:03 +02:00
parent 593b15487d
commit 3eb282f2a0

View file

@ -98,27 +98,82 @@ class SettingsRenderer {
*/
public function messages() : array {
$messages = array();
if ($this->paypal_vaulting_is_enabled() || $this->pay_later_messaging_is_enabled()) {
$enabled = $this->paypal_vaulting_is_enabled() ? __('PayPal vaulting', 'woo-ecurring') : __('Pay Later Messaging', 'woo-ecurring');
$disabled = $this->pay_later_messaging_is_enabled() ? __('PayPal vaulting', 'woo-ecurring') : __('Pay Later Messaging', 'woo-ecurring');
$pay_later_messages_or_vaulting_text = sprintf(
__(
'You have %1$s enabled, that\'s why %2$s is unavailable now. You cannot use both at the same time',
'woo-ecurring'
),
$enabled,
$disabled
);
$messages[] = new Message($pay_later_messages_or_vaulting_text, 'warning');
}
//phpcs:disable WordPress.Security.NonceVerification.Recommended
//phpcs:disable WordPress.Security.NonceVerification.Missing
if ( ! isset( $_GET['ppcp-onboarding-error'] ) || ! empty( $_POST ) ) {
return array();
return $messages;
}
//phpcs:enable WordPress.Security.NonceVerification.Recommended
//phpcs:enable WordPress.Security.NonceVerification.Missing
$messages = array(
new Message(
$messages[] = new Message(
__(
'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.',
'woocommerce-paypal-payments'
),
'error',
false
),
);
return $messages;
}
/**
* Check whether PayPal vaulting is enabled.
*
* @return bool
*/
private function paypal_vaulting_is_enabled(): bool
{
$saving_paypal_account_is_enabled = $this->settings->has('save_paypal_account') &&
(bool) $this->settings->get('save_paypal_account');
$vault_is_enabled = $this->settings->has('vault_enabled') &&
(bool) $this->settings->get('vault_enabled');
return $saving_paypal_account_is_enabled || $vault_is_enabled;
}
/**
* Check whether Pay Later message is enabled either for checkout, cart or product page.
*
* @return bool
*/
private function pay_later_messaging_is_enabled(): bool
{
$pay_later_message_enabled_for_checkout = $this->settings->has('message_enabled')
&& (bool) $this->settings->get('message_enabled');
$pay_later_message_enabled_for_cart = $this->settings->has('message_cart_enabled')
&& (bool) $this->settings->get('message_cart_enabled');
$pay_later_message_enabled_for_product = $this->settings->has('message_product_enabled')
&& (bool) $this->settings->get('message_product_enabled');
return $pay_later_message_enabled_for_checkout ||
$pay_later_message_enabled_for_cart ||
$pay_later_message_enabled_for_product;
}
/**
* Renders the multiselect field.
*