Replace CurrencySupport class with a service

This commit is contained in:
Alex P 2021-11-30 14:55:31 +02:00
parent 521cbf4e26
commit c43a4999aa
3 changed files with 8 additions and 63 deletions

View file

@ -40,7 +40,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
@ -321,12 +320,6 @@ return array(
$container->get( 'api.shop.country' )
);
},
'api.helpers.currency-support' => static function ( ContainerInterface $container ) : CurrencySupport {
return new CurrencySupport(
$container->get( 'api.supported-currencies' ),
$container->get( 'api.shop.currency' )
);
},
'api.shop.currency' => static function ( ContainerInterface $container ) : string {
return get_woocommerce_currency();
@ -342,6 +335,13 @@ return array(
true
);
},
'api.shop.is-currency-supported' => static function ( ContainerInterface $container ) : bool {
return in_array(
$container->get( 'api.shop.currency' ),
$container->get( 'api.supported-currencies' ),
true
);
},
/**
* Currencies supported by PayPal.

View file

@ -1,50 +0,0 @@
<?php
/**
* Checks if the current installation uses supported currency.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Helper
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
/**
* Class CurrencySupport
*/
class CurrencySupport {
/**
* Currencies supported by PayPal.
*
* @var string[]
*/
private $supported_currencies;
/**
* 3-letter currency code of the shop.
*
* @var string
*/
private $currency;
/**
* CurrencySupport constructor.
*
* @param string[] $supported_currencies Currencies supported by PayPal.
* @param string $currency 3-letter currency code of the shop.
*/
public function __construct( array $supported_currencies, string $currency ) {
$this->supported_currencies = $supported_currencies;
$this->currency = $currency;
}
/**
* Returns whether the currency is supported.
*
* @return bool
*/
public function supports_currency(): bool {
return in_array( $this->currency, $this->supported_currencies, true );
}
}

View file

@ -14,10 +14,8 @@ use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
@ -57,9 +55,6 @@ class StatusReportModule implements ModuleInterface {
/* @var Bearer $bearer The bearer. */
$bearer = $c->get( 'api.bearer' );
$currency_support = $c->get( 'api.helpers.currency-support' );
assert( $currency_support instanceof CurrencySupport );
/* @var DccApplies $dcc_applies The ddc applies. */
$dcc_applies = $c->get( 'api.helpers.dccapplies' );
@ -97,7 +92,7 @@ class StatusReportModule implements ModuleInterface {
'exported_label' => 'WooCommerce currency supported',
'description' => esc_html__( 'Whether PayPal supports the default store currency or not.', 'woocommerce-paypal-payments' ),
'value' => $this->bool_to_html(
$currency_support->supports_currency()
$c->get( 'api.shop.is-currency-supported' )
),
),
array(