Check supported currencies in notice method

This commit is contained in:
carmenmaymo 2023-06-14 12:36:55 +02:00
parent d3249b140a
commit 013ffb5213
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
2 changed files with 26 additions and 11 deletions

View file

@ -209,10 +209,11 @@ return array(
$settings = $container->get( 'wcgateway.settings' );
return new ConnectAdminNotice( $state, $settings );
},
'wcgateway.notice.currency-unsupported' => static function (ContainerInterface $container): UnsupportedCurrencyAdminNotice {
$state = $container->get('onboarding.state');
$settings = $container->get('wcgateway.settings');
return new UnsupportedCurrencyAdminNotice($state, $settings);
'wcgateway.notice.currency-unsupported' => static function ( ContainerInterface $container ): UnsupportedCurrencyAdminNotice {
$state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' );
$supported_currencies = $container->get( 'api.supported-currencies' );
return new UnsupportedCurrencyAdminNotice( $state, $settings, $supported_currencies );
},
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
return new GatewayWithoutPayPalAdminNotice(

View file

@ -32,16 +32,24 @@ class UnsupportedCurrencyAdminNotice {
* @var ContainerInterface
*/
private $settings;
/**
* The supported currencies.
*
* @var array
*/
private $supported_currencies;
/**
* ConnectAdminNotice constructor.
*
* @param State $state The state.
* @param ContainerInterface $settings The settings.
* @param array $supported_currencies The supported currencies.
*/
public function __construct( State $state, ContainerInterface $settings ) {
public function __construct( State $state, ContainerInterface $settings, array $supported_currencies ) {
$this->state = $state;
$this->settings = $settings;
$this->supported_currencies = $supported_currencies;
}
/**
@ -60,7 +68,7 @@ class UnsupportedCurrencyAdminNotice {
'Attention: Your current WooCommerce store currency is not supported by PayPal. Please update your store currency to one that is supported by PayPal to ensure smooth transactions. Visit the <a href="%1$s">PayPal currency support page</a> for more information on supported currencies.',
'woocommerce-paypal-payments'
),
"https://developer.paypal.com/api/rest/reference/currency-codes/"
'https://developer.paypal.com/api/rest/reference/currency-codes/'
);
return new Message( $message, 'warning' );
}
@ -74,8 +82,14 @@ class UnsupportedCurrencyAdminNotice {
return $this->state->current_state() === State::STATE_ONBOARDED && ! $this->currency_supported();
}
private function currency_supported()
{
//TODO - get the currency from the settings
/**
* Whether the currency is supported by PayPal.
*
* @return bool
*/
private function currency_supported(): bool {
$currency = get_woocommerce_currency();
$supported_currencies = $this->supported_currencies;
return in_array( $currency, $supported_currencies, true );
}
}