Fix psalm

This commit is contained in:
dinamiko 2022-05-09 10:36:38 +02:00
parent 49bc0f255c
commit f2284d49f5
2 changed files with 16 additions and 11 deletions

View file

@ -116,8 +116,8 @@ class PayUponInvoice {
* @param Environment $environment The environment. * @param Environment $environment The environment.
* @param string $asset_version The asset version. * @param string $asset_version The asset version.
* @param State $state The onboarding state. * @param State $state The onboarding state.
* @param bool $is_ppcp_settings_page The is ppcp settings page. * @param bool $is_ppcp_settings_page The is ppcp settings page.
* @param string $current_ppcp_settings_page_id Current PayPal settings page id. * @param string $current_ppcp_settings_page_id Current PayPal settings page id.
* @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status. * @param PayUponInvoiceProductStatus $pui_product_status PUI seller product status.
*/ */
public function __construct( public function __construct(
@ -143,7 +143,7 @@ class PayUponInvoice {
$this->state = $state; $this->state = $state;
$this->is_ppcp_settings_page = $is_ppcp_settings_page; $this->is_ppcp_settings_page = $is_ppcp_settings_page;
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id; $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', 'woocommerce_settings_checkout',
function () { function () {
if ( if (
$this->current_ppcp_settings_page_id === PayUponInvoiceGateway::ID PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id
&& ! $this->pui_product_status->pui_is_active() && ! $this->pui_product_status->pui_is_active()
) { ) {
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
$gateway_enabled = $gateway_settings['enabled'] ?? ''; $gateway_enabled = $gateway_settings['enabled'] ?? '';
if($gateway_enabled === 'yes') { if ( 'yes' === $gateway_enabled ) {
$gateway_settings['enabled'] = 'no'; $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&section=ppcp-pay-upon-invoice-gateway' ); $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-pay-upon-invoice-gateway' );
wp_safe_redirect( $redirect_url); wp_safe_redirect( $redirect_url );
exit; exit;
} }
@ -347,6 +347,10 @@ class PayUponInvoice {
* @return bool * @return bool
*/ */
private function is_checkout_ready_for_pui(): 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; $billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
if ( $billing_country && 'DE' !== $billing_country ) { if ( $billing_country && 'DE' !== $billing_country ) {
return false; return false;

View file

@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct; use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/** /**
* Class DccProductStatus * Class DccProductStatus
@ -22,7 +23,7 @@ class PayUponInvoiceProductStatus {
/** /**
* Caches the status for the current load. * Caches the status for the current load.
* *
* @var string|null * @var bool|null
*/ */
private $current_status_cache; private $current_status_cache;
/** /**
@ -57,7 +58,7 @@ class PayUponInvoiceProductStatus {
* Whether the active/subscribed products support PUI. * Whether the active/subscribed products support PUI.
* *
* @return bool * @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 { public function pui_is_active() : bool {
if ( is_bool( $this->current_status_cache ) ) { if ( is_bool( $this->current_status_cache ) ) {
@ -76,7 +77,7 @@ class PayUponInvoiceProductStatus {
} }
foreach ( $seller_status->products() as $product ) { foreach ( $seller_status->products() as $product ) {
if($product->name() !== 'PAYMENT_METHODS') { if ( $product->name() !== 'PAYMENT_METHODS' ) {
continue; continue;
} }