diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php
index 9cf68f451..2906ba9d7 100644
--- a/modules/ppcp-wc-gateway/services.php
+++ b/modules/ppcp-wc-gateway/services.php
@@ -45,7 +45,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
-use WooCommerce\PayPalCommerce\WcGateway\Notice\DccWithoutPayPalAdminNotice;
+use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -182,12 +182,23 @@ return array(
$settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings );
},
- 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
- $state = $container->get( 'onboarding.state' );
- $settings = $container->get( 'wcgateway.settings' );
- $is_payments_page = $container->get( 'wcgateway.is-wc-payments-page' );
- $is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
- return new DccWithoutPayPalAdminNotice( $state, $settings, $is_payments_page, $is_ppcp_settings_page );
+ 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
+ return new GatewayWithoutPayPalAdminNotice(
+ CreditCardGateway::ID,
+ $container->get( 'onboarding.state' ),
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'wcgateway.is-wc-payments-page' ),
+ $container->get( 'wcgateway.is-ppcp-settings-page' )
+ );
+ },
+ 'wcgateway.notice.card-button-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
+ return new GatewayWithoutPayPalAdminNotice(
+ CardButtonGateway::ID,
+ $container->get( 'onboarding.state' ),
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'wcgateway.is-wc-payments-page' ),
+ $container->get( 'wcgateway.is-ppcp-settings-page' )
+ );
},
'wcgateway.notice.authorize-order-action' =>
static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
diff --git a/modules/ppcp-wc-gateway/src/Notice/DccWithoutPayPalAdminNotice.php b/modules/ppcp-wc-gateway/src/Notice/GatewayWithoutPayPalAdminNotice.php
similarity index 57%
rename from modules/ppcp-wc-gateway/src/Notice/DccWithoutPayPalAdminNotice.php
rename to modules/ppcp-wc-gateway/src/Notice/GatewayWithoutPayPalAdminNotice.php
index 2343c9e00..171f50280 100644
--- a/modules/ppcp-wc-gateway/src/Notice/DccWithoutPayPalAdminNotice.php
+++ b/modules/ppcp-wc-gateway/src/Notice/GatewayWithoutPayPalAdminNotice.php
@@ -1,6 +1,6 @@
id = $id;
$this->state = $state;
$this->settings = $settings;
$this->is_payments_page = $is_payments_page;
@@ -76,12 +86,20 @@ class DccWithoutPayPalAdminNotice {
return null;
}
+ $gateway = $this->get_gateway();
+ if ( ! $gateway ) {
+ return null;
+ }
+
+ $name = $gateway->get_method_title();
+
$message = sprintf(
- /* translators: %1$s the gateway name. */
+ /* translators: %1$s the gateway name, %2$s URL. */
__(
- 'PayPal Card Processing cannot be used without the PayPal gateway. Enable the PayPal Gateway.',
+ '%1$s cannot be used without the PayPal gateway. Enable the PayPal gateway.',
'woocommerce-paypal-payments'
),
+ $name,
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' )
);
return new Message( $message, 'warning' );
@@ -93,9 +111,29 @@ class DccWithoutPayPalAdminNotice {
* @return bool
*/
protected function should_display(): bool {
- return State::STATE_ONBOARDED === $this->state->current_state()
- && ( $this->is_payments_page || $this->is_ppcp_settings_page )
- && ( $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) )
- && ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) );
+ if ( State::STATE_ONBOARDED !== $this->state->current_state() ||
+ ( ! $this->is_payments_page && ! $this->is_ppcp_settings_page ) ) {
+ return false;
+ }
+ if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) {
+ return false;
+ }
+
+ $gateway = $this->get_gateway();
+
+ return $gateway && wc_string_to_bool( $gateway->get_option( 'enabled' ) );
+ }
+
+ /**
+ * Returns the gateway object or null.
+ *
+ * @return WC_Payment_Gateway|null
+ */
+ protected function get_gateway(): ?WC_Payment_Gateway {
+ $gateways = WC()->payment_gateways->payment_gateways();
+ if ( ! isset( $gateways[ $this->id ] ) ) {
+ return null;
+ }
+ return $gateways[ $this->id ];
}
}
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index f0aa2ffb5..a4628b035 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -29,7 +29,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
-use WooCommerce\PayPalCommerce\WcGateway\Notice\DccWithoutPayPalAdminNotice;
+use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
@@ -164,11 +164,15 @@ class WCGatewayModule implements ModuleInterface {
$notices[] = $connect_message;
}
- $dcc_without_paypal_notice = $c->get( 'wcgateway.notice.dcc-without-paypal' );
- assert( $dcc_without_paypal_notice instanceof DccWithoutPayPalAdminNotice );
- $dcc_without_paypal_message = $dcc_without_paypal_notice->message();
- if ( $dcc_without_paypal_message ) {
- $notices[] = $dcc_without_paypal_message;
+ foreach ( array(
+ $c->get( 'wcgateway.notice.dcc-without-paypal' ),
+ $c->get( 'wcgateway.notice.card-button-without-paypal' ),
+ ) as $gateway_without_paypal_notice ) {
+ assert( $gateway_without_paypal_notice instanceof GatewayWithoutPayPalAdminNotice );
+ $message = $gateway_without_paypal_notice->message();
+ if ( $message ) {
+ $notices[] = $message;
+ }
}
$authorize_order_action = $c->get( 'wcgateway.notice.authorize-order-action' );