Do not display pui tab if wc store is not is germany

This commit is contained in:
dinamiko 2022-04-22 12:19:55 +02:00
parent 63c3c095bb
commit 0f93759c9c
6 changed files with 54 additions and 20 deletions

View file

@ -7,7 +7,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice; namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use RuntimeException; use RuntimeException;
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit; use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
use WP_Error; use WP_Error;
/** /**

View file

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway; namespace WooCommerce\PayPalCommerce\WcGateway;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext; use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; 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\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSourceWebsiteId; 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\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
@ -69,6 +69,7 @@ return array(
$order_endpoint = $container->get( 'api.endpoint.order' ); $order_endpoint = $container->get( 'api.endpoint.order' );
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
$logger = $container->get( 'woocommerce.logger.woocommerce' ); $logger = $container->get( 'woocommerce.logger.woocommerce' );
$api_shop_country = $container->get( 'api.shop.country' );
return new PayPalGateway( return new PayPalGateway(
$settings_renderer, $settings_renderer,
$funding_source_renderer, $funding_source_renderer,
@ -85,7 +86,8 @@ return array(
$payment_token_repository, $payment_token_repository,
$logger, $logger,
$payments_endpoint, $payments_endpoint,
$order_endpoint $order_endpoint,
$api_shop_country
); );
}, },
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway { 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
@ -177,7 +179,10 @@ return array(
return new AuthorizeOrderActionNotice(); return new AuthorizeOrderActionNotice();
}, },
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer { '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 { 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );

View file

@ -12,7 +12,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -159,6 +158,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
*/ */
private $logger; private $logger;
/**
* The api shop country.
*
* @var string
*/
protected $api_shop_country;
/** /**
* PayPalGateway constructor. * PayPalGateway constructor.
* *
@ -178,6 +184,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
* @param PaymentsEndpoint $payments_endpoint The payments endpoint. * @param PaymentsEndpoint $payments_endpoint The payments endpoint.
* @param OrderEndpoint $order_endpoint The order endpoint. * @param OrderEndpoint $order_endpoint The order endpoint.
* @param string $api_shop_country The api shop country.
*/ */
public function __construct( public function __construct(
SettingsRenderer $settings_renderer, SettingsRenderer $settings_renderer,
@ -195,7 +202,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
PaymentTokenRepository $payment_token_repository, PaymentTokenRepository $payment_token_repository,
LoggerInterface $logger, LoggerInterface $logger,
PaymentsEndpoint $payments_endpoint, PaymentsEndpoint $payments_endpoint,
OrderEndpoint $order_endpoint OrderEndpoint $order_endpoint,
string $api_shop_country
) { ) {
$this->id = self::ID; $this->id = self::ID;
@ -276,6 +284,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
$this->payments_endpoint = $payments_endpoint; $this->payments_endpoint = $payments_endpoint;
$this->order_endpoint = $order_endpoint; $this->order_endpoint = $order_endpoint;
$this->state = $state; $this->state = $state;
$this->api_shop_country = $api_shop_country;
} }
/** /**
@ -399,6 +408,10 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @return bool * @return bool
*/ */
private function is_pui_tab():bool { private function is_pui_tab():bool {
if ( 'DE' !== $this->api_shop_country ) {
return false;
}
return is_admin() && PayUponInvoiceGateway::ID === $this->page_id; return is_admin() && PayUponInvoiceGateway::ID === $this->page_id;
} }

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WC_Order; use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use RuntimeException; use RuntimeException;
use WC_Payment_Gateway; use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;

View file

@ -28,13 +28,22 @@ class SectionsRenderer {
*/ */
protected $page_id; protected $page_id;
/**
* The api shop country.
*
* @var string
*/
protected $api_shop_country;
/** /**
* SectionsRenderer constructor. * SectionsRenderer constructor.
* *
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page. * @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 ) { public function __construct( string $page_id, string $api_shop_country ) {
$this->page_id = $page_id; $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' ), WebhooksStatusPage::ID => __( 'Webhooks Status', 'woocommerce-paypal-payments' ),
); );
if ( 'DE' !== $this->api_shop_country ) {
unset( $sections[ PayUponInvoiceGateway::ID ] );
}
echo '<ul class="subsubsub">'; echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections ); $array_keys = array_keys( $sections );