diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index b356090b6..157d3de31 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -211,9 +211,32 @@ return array( 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer { return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ), - $container->get( 'api.shop.country' ) + $container->get( 'wcgateway.settings.sections' ) ); }, + 'wcgateway.settings.sections' => static function ( ContainerInterface $container ): array { + $sections = array( + PayPalGateway::ID => __( 'PayPal Checkout', 'woocommerce-paypal-payments' ), + CreditCardGateway::ID => __( 'PayPal Card Processing', 'woocommerce-paypal-payments' ), + CardButtonGateway::ID => __( 'PayPal Card Button', 'woocommerce-paypal-payments' ), + OXXOGateway::ID => __( 'OXXO', 'woocommerce-paypal-payments' ), + PayUponInvoiceGateway::ID => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ), + WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ), + ); + + // Remove for all not registered in WC gateways that cannot render anything in this case. + $gateways = WC()->payment_gateways->payment_gateways(); + foreach ( array_diff( + array_keys( $sections ), + array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID ) + ) as $id ) { + if ( ! isset( $gateways[ $id ] ) ) { + unset( $sections[ $id ] ); + } + } + + return $sections; + }, 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus { $settings = $container->get( 'wcgateway.settings' ); return new SettingsStatus( $settings ); diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php index 2fd880e01..275574e97 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php @@ -9,11 +9,7 @@ declare( strict_types=1 ); namespace WooCommerce\PayPalCommerce\WcGateway\Settings; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway; use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage; /** @@ -31,21 +27,21 @@ class SectionsRenderer { protected $page_id; /** - * The api shop country. + * Key - page/gateway ID, value - displayed text. * - * @var string + * @var array */ - protected $api_shop_country; + protected $sections; /** * SectionsRenderer constructor. * - * @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page. - * @param string $api_shop_country The api shop country. + * @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page. + * @param array $sections Key - page/gateway ID, value - displayed text. */ - public function __construct( string $page_id, string $api_shop_country ) { - $this->page_id = $page_id; - $this->api_shop_country = $api_shop_country; + public function __construct( string $page_id, array $sections ) { + $this->page_id = $page_id; + $this->sections = $sections; } /** @@ -65,27 +61,17 @@ class SectionsRenderer { return; } - $sections = array( - PayPalGateway::ID => __( 'PayPal Checkout', 'woocommerce-paypal-payments' ), - CreditCardGateway::ID => __( 'PayPal Card Processing', 'woocommerce-paypal-payments' ), - CardButtonGateway::ID => __( 'PayPal Card Button', 'woocommerce-paypal-payments' ), - OXXOGateway::ID => __( 'OXXO', 'woocommerce-paypal-payments' ), - PayUponInvoiceGateway::ID => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ), - WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ), - ); - - if ( 'DE' !== $this->api_shop_country ) { - unset( $sections[ PayUponInvoiceGateway::ID ] ); - } - echo '