From 0f93759c9c0cb6037e9f0f3bf07c83c0f52a471c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 22 Apr 2022 12:19:55 +0200 Subject: [PATCH] Do not display pui tab if wc store is not is germany --- .../Endpoint/PayUponInvoiceOrderEndpoint.php | 3 ++- modules/ppcp-wc-gateway/services.php | 11 ++++++++--- .../src/Gateway/PayPalGateway.php | 17 +++++++++++++++-- .../Gateway/PayUponInvoice/PayUponInvoice.php | 15 ++++++++------- .../PayUponInvoice/PayUponInvoiceGateway.php | 11 ++++++----- .../src/Settings/SectionsRenderer.php | 17 +++++++++++++++-- 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php index c6784530a..44da8ce85 100644 --- a/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/PayUponInvoiceOrderEndpoint.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice; +namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint; use Psr\Log\LoggerInterface; use RuntimeException; @@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory; +use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet; use WP_Error; /** diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index df6c13ac9..8255510e6 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway; use Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; @@ -32,7 +33,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceOrderEndpoint; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway; @@ -69,6 +69,7 @@ return array( $order_endpoint = $container->get( 'api.endpoint.order' ); $environment = $container->get( 'onboarding.environment' ); $logger = $container->get( 'woocommerce.logger.woocommerce' ); + $api_shop_country = $container->get( 'api.shop.country' ); return new PayPalGateway( $settings_renderer, $funding_source_renderer, @@ -85,7 +86,8 @@ return array( $payment_token_repository, $logger, $payments_endpoint, - $order_endpoint + $order_endpoint, + $api_shop_country ); }, 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway { @@ -177,7 +179,10 @@ return array( return new AuthorizeOrderActionNotice(); }, 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer { - return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ) ); + return new SectionsRenderer( + $container->get( 'wcgateway.current-ppcp-settings-page-id' ), + $container->get( 'api.shop.country' ) + ); }, 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus { $settings = $container->get( 'wcgateway.settings' ); diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index fe28aeafc..ccae4d6ed 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -12,7 +12,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint; -use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Session\SessionHandler; @@ -159,6 +158,13 @@ class PayPalGateway extends \WC_Payment_Gateway { */ private $logger; + /** + * The api shop country. + * + * @var string + */ + protected $api_shop_country; + /** * PayPalGateway constructor. * @@ -178,6 +184,7 @@ class PayPalGateway extends \WC_Payment_Gateway { * @param LoggerInterface $logger The logger. * @param PaymentsEndpoint $payments_endpoint The payments endpoint. * @param OrderEndpoint $order_endpoint The order endpoint. + * @param string $api_shop_country The api shop country. */ public function __construct( SettingsRenderer $settings_renderer, @@ -195,7 +202,8 @@ class PayPalGateway extends \WC_Payment_Gateway { PaymentTokenRepository $payment_token_repository, LoggerInterface $logger, PaymentsEndpoint $payments_endpoint, - OrderEndpoint $order_endpoint + OrderEndpoint $order_endpoint, + string $api_shop_country ) { $this->id = self::ID; @@ -276,6 +284,7 @@ class PayPalGateway extends \WC_Payment_Gateway { $this->payments_endpoint = $payments_endpoint; $this->order_endpoint = $order_endpoint; $this->state = $state; + $this->api_shop_country = $api_shop_country; } /** @@ -399,6 +408,10 @@ class PayPalGateway extends \WC_Payment_Gateway { * @return bool */ private function is_pui_tab():bool { + if ( 'DE' !== $this->api_shop_country ) { + return false; + } + return is_admin() && PayUponInvoiceGateway::ID === $this->page_id; } diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php index 7f5275827..7cb86acf9 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php @@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice; use Psr\Log\LoggerInterface; use WC_Order; +use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; @@ -74,13 +75,13 @@ class PayUponInvoice { /** * PayUponInvoice constructor. * - * @param string $module_url The module URL. - * @param FraudNet $fraud_net The FraudNet entity. - * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint. - * @param LoggerInterface $logger The logger. - * @param Settings $settings The settings. - * @param Environment $environment The environment. - * @param string $asset_version The asset version. + * @param string $module_url The module URL. + * @param FraudNet $fraud_net The FraudNet entity. + * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint. + * @param LoggerInterface $logger The logger. + * @param Settings $settings The settings. + * @param Environment $environment The environment. + * @param string $asset_version The asset version. */ public function __construct( string $module_url, diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index 926e45dcc..8acc0a358 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice; use Psr\Log\LoggerInterface; use RuntimeException; use WC_Payment_Gateway; +use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\Onboarding\Environment; @@ -64,11 +65,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { /** * PayUponInvoiceGateway constructor. * - * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint. - * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory. - * @param PaymentSourceFactory $payment_source_factory The payment source factory. - * @param Environment $environment The environment. - * @param LoggerInterface $logger The logger. + * @param PayUponInvoiceOrderEndpoint $order_endpoint The order endpoint. + * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory. + * @param PaymentSourceFactory $payment_source_factory The payment source factory. + * @param Environment $environment The environment. + * @param LoggerInterface $logger The logger. */ public function __construct( PayUponInvoiceOrderEndpoint $order_endpoint, diff --git a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php index 72d70a7f0..049038e48 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/SectionsRenderer.php @@ -28,13 +28,22 @@ class SectionsRenderer { */ protected $page_id; + /** + * The api shop country. + * + * @var string + */ + protected $api_shop_country; + /** * 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. */ - public function __construct( string $page_id ) { - $this->page_id = $page_id; + public function __construct( string $page_id, string $api_shop_country ) { + $this->page_id = $page_id; + $this->api_shop_country = $api_shop_country; } /** @@ -61,6 +70,10 @@ class SectionsRenderer { WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ), ); + if ( 'DE' !== $this->api_shop_country ) { + unset( $sections[ PayUponInvoiceGateway::ID ] ); + } + echo '