From f2284d49f510010208c974b3d32b55bc00bdea41 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 9 May 2022 10:36:38 +0200 Subject: [PATCH] Fix psalm --- .../Gateway/PayUponInvoice/PayUponInvoice.php | 20 +++++++++++-------- .../Helper/PayUponInvoiceProductStatus.php | 7 ++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php index 1146b37cd..0f2daa17a 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php @@ -116,8 +116,8 @@ class PayUponInvoice { * @param Environment $environment The environment. * @param string $asset_version The asset version. * @param State $state The onboarding state. - * @param bool $is_ppcp_settings_page The is ppcp settings page. - * @param string $current_ppcp_settings_page_id Current PayPal settings page id. + * @param bool $is_ppcp_settings_page The is ppcp settings page. + * @param string $current_ppcp_settings_page_id Current PayPal settings page id. * @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status. */ public function __construct( @@ -143,7 +143,7 @@ class PayUponInvoice { $this->state = $state; $this->is_ppcp_settings_page = $is_ppcp_settings_page; $this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id; - $this->pui_product_status = $pui_product_status; + $this->pui_product_status = $pui_product_status; } /** @@ -322,16 +322,16 @@ class PayUponInvoice { 'woocommerce_settings_checkout', function () { if ( - $this->current_ppcp_settings_page_id === PayUponInvoiceGateway::ID + PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id && ! $this->pui_product_status->pui_is_active() ) { $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); - $gateway_enabled = $gateway_settings['enabled'] ?? ''; - if($gateway_enabled === 'yes') { + $gateway_enabled = $gateway_settings['enabled'] ?? ''; + if ( 'yes' === $gateway_enabled ) { $gateway_settings['enabled'] = 'no'; - update_option('woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings); + update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings ); $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' ); - wp_safe_redirect( $redirect_url); + wp_safe_redirect( $redirect_url ); exit; } @@ -347,6 +347,10 @@ class PayUponInvoice { * @return bool */ private function is_checkout_ready_for_pui(): bool { + if ( ! $this->pui_product_status->pui_is_active() ) { + return false; + } + $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null; if ( $billing_country && 'DE' !== $billing_country ) { return false; diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php index 841c17a1a..3358605e8 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceProductStatus.php @@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; +use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; /** * Class DccProductStatus @@ -22,7 +23,7 @@ class PayUponInvoiceProductStatus { /** * Caches the status for the current load. * - * @var string|null + * @var bool|null */ private $current_status_cache; /** @@ -57,7 +58,7 @@ class PayUponInvoiceProductStatus { * Whether the active/subscribed products support PUI. * * @return bool - * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException Should a setting not be found. + * @throws NotFoundException Should a setting not be found. */ public function pui_is_active() : bool { if ( is_bool( $this->current_status_cache ) ) { @@ -76,7 +77,7 @@ class PayUponInvoiceProductStatus { } foreach ( $seller_status->products() as $product ) { - if($product->name() !== 'PAYMENT_METHODS') { + if ( $product->name() !== 'PAYMENT_METHODS' ) { continue; }