From 49665f680f41bfab10fb67d03b1c1fa378416fce Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 30 Jan 2025 18:37:01 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20New=20Local=20APM=20product=20statu?=
=?UTF-8?q?s=20check?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../services.php | 9 ++
.../src/LocalApmProductStatus.php | 95 +++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 modules/ppcp-local-alternative-payment-methods/src/LocalApmProductStatus.php
diff --git a/modules/ppcp-local-alternative-payment-methods/services.php b/modules/ppcp-local-alternative-payment-methods/services.php
index c0a66c11e..5408288c0 100644
--- a/modules/ppcp-local-alternative-payment-methods/services.php
+++ b/modules/ppcp-local-alternative-payment-methods/services.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
+use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\LocalApmProductStatus;
return array(
'ppcp-local-apms.url' => static function ( ContainerInterface $container ): string {
@@ -67,6 +68,14 @@ return array(
),
);
},
+ 'ppcp-local-apms.product-status' => static function ( ContainerInterface $container ): LocalApmProductStatus {
+ return new LocalApmProductStatus(
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'api.endpoint.partners' ),
+ $container->get( 'settings.flag.is-connected' ),
+ $container->get( 'api.helper.failure-registry' )
+ );
+ },
'ppcp-local-apms.bancontact.wc-gateway' => static function ( ContainerInterface $container ): BancontactGateway {
return new BancontactGateway(
$container->get( 'api.endpoint.orders' ),
diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalApmProductStatus.php b/modules/ppcp-local-alternative-payment-methods/src/LocalApmProductStatus.php
new file mode 100644
index 000000000..2a89146be
--- /dev/null
+++ b/modules/ppcp-local-alternative-payment-methods/src/LocalApmProductStatus.php
@@ -0,0 +1,95 @@
+settings = $settings;
+ }
+
+ /** {@inheritDoc} */
+ protected function check_local_state() : ?bool {
+ if ( $this->settings->has( self::SETTINGS_KEY ) && ( $this->settings->get( self::SETTINGS_KEY ) ) ) {
+ return wc_string_to_bool( $this->settings->get( self::SETTINGS_KEY ) );
+ }
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ protected function check_active_state( SellerStatus $seller_status ) : bool {
+ $has_capability = false;
+
+ foreach ( $seller_status->products() as $product ) {
+ if ( $product->name() === 'PAYMENT_METHODS' ) {
+ $has_capability = true;
+ break;
+ }
+ }
+
+ if ( $has_capability ) {
+ $this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
+ } else {
+ $this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_DISABLED );
+ }
+ $this->settings->persist();
+
+ return $has_capability;
+ }
+
+ /** {@inheritDoc} */
+ protected function clear_state( Settings $settings = null ) : void {
+ if ( null === $settings ) {
+ $settings = $this->settings;
+ }
+
+ if ( $settings->has( self::SETTINGS_KEY ) ) {
+ $settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_UNDEFINED );
+ $settings->persist();
+ }
+ }
+}