mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
✨ New Local APM product status check
This commit is contained in:
parent
5f51762025
commit
49665f680f
2 changed files with 104 additions and 0 deletions
|
@ -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' ),
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Status of local alternative payment methods.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\ProductStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatus;
|
||||
|
||||
/**
|
||||
* Class LocalApmProductStatus
|
||||
*/
|
||||
class LocalApmProductStatus extends ProductStatus {
|
||||
public const SETTINGS_KEY = 'products_local_apms_enabled';
|
||||
|
||||
public const SETTINGS_VALUE_ENABLED = 'yes';
|
||||
public const SETTINGS_VALUE_DISABLED = 'no';
|
||||
public const SETTINGS_VALUE_UNDEFINED = '';
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private Settings $settings;
|
||||
|
||||
/**
|
||||
* ApmProductStatus constructor.
|
||||
*
|
||||
* @param Settings $settings The Settings.
|
||||
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
|
||||
* @param bool $is_connected The onboarding state.
|
||||
* @param FailureRegistry $api_failure_registry The API failure registry.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
bool $is_connected,
|
||||
FailureRegistry $api_failure_registry
|
||||
) {
|
||||
parent::__construct( $is_connected, $partners_endpoint, $api_failure_registry );
|
||||
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue