Add unsupported currency admin notice

This commit is contained in:
carmenmaymo 2023-06-14 12:15:20 +02:00
parent af5d33dc78
commit d3249b140a
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
3 changed files with 95 additions and 0 deletions

View file

@ -57,6 +57,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\UnsupportedCurrencyAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -208,6 +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.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
return new GatewayWithoutPayPalAdminNotice(
CreditCardGateway::ID,

View file

@ -0,0 +1,81 @@
<?php
/**
* Registers the admin message to "connect your account" if necessary.
*
* @package WooCommerce\PayPalCommerce\WcGateway\Notice
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
/**
* Class ConnectAdminNotice
*/
class UnsupportedCurrencyAdminNotice {
/**
* The state.
*
* @var State
*/
private $state;
/**
* The settings.
*
* @var ContainerInterface
*/
private $settings;
/**
* ConnectAdminNotice constructor.
*
* @param State $state The state.
* @param ContainerInterface $settings The settings.
*/
public function __construct( State $state, ContainerInterface $settings ) {
$this->state = $state;
$this->settings = $settings;
}
/**
* Returns the message.
*
* @return Message|null
*/
public function unsupported_currency_message() {
if ( ! $this->should_display() ) {
return null;
}
$message = sprintf(
/* translators: %1$s the gateway name. */
__(
'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/"
);
return new Message( $message, 'warning' );
}
/**
* Whether the message should display.
*
* @return bool
*/
protected function should_display(): bool {
return $this->state->current_state() === State::STATE_ONBOARDED && ! $this->currency_supported();
}
private function currency_supported()
{
//TODO - get the currency from the settings
}
}

View file

@ -39,6 +39,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\UnsupportedCurrencyAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\HeaderRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
@ -197,6 +198,13 @@ class WCGatewayModule implements ModuleInterface {
$notices[] = $connect_message;
}
$notice = $c->get( 'wcgateway.notice.currency-unsupported' );
assert( $notice instanceof UnsupportedCurrencyAdminNotice );
$unsupported_currency_message = $notice->unsupported_currency_message();
if ( $unsupported_currency_message ) {
$notices[] = $unsupported_currency_message;
}
foreach ( array(
$c->get( 'wcgateway.notice.dcc-without-paypal' ),
$c->get( 'wcgateway.notice.card-button-without-paypal' ),