Merge pull request #4 from inpsyde/feature/configure-gateway-notice

Add configure gateway admin notice
This commit is contained in:
David Remer 2020-04-13 14:19:49 +03:00 committed by GitHub
commit 6aa87da598
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 1 deletions

View file

@ -6,6 +6,7 @@ namespace Inpsyde\PayPalCommerce\WcGateway;
use Dhii\Data\Container\ContainerInterface;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
@ -27,6 +28,10 @@ return [
$settingsField = $container->get('wcgateway.settings.fields');
return new Settings($gateway, $settingsField);
},
'wcgateway.notice.connect' => function (ContainerInterface $container) : ConnectAdminNotice {
$settings = $container->get('wcgateway.settings');
return new ConnectAdminNotice($settings);
},
'wcgateway.settings.fields' => function (ContainerInterface $container) : SettingsFields {
return new SettingsFields();
},

View file

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Notice;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
class ConnectAdminNotice
{
private $settings;
public function __construct(Settings $settings)
{
$this->settings = $settings;
}
public function display()
{
if (!$this->shouldDisplay()) {
return;
}
echo sprintf(
'<div class="notice notice-warning"><p>%s</p></div>',
wp_kses_post(
sprintf(
/* translators: %1$s the gateway name */
__(
'%1$s is almost ready. To get started, <a href="%2$s">connect your account</a>.',
'woocommerce-paypal-commerce-gateway'
),
$this->settings->get('title'),
// TODO: find a better way to get the url
admin_url('admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway')
)
)
);
}
protected function shouldDisplay(): bool
{
// TODO: decide on what condition to display
return !wc_string_to_bool($this->settings->get('enabled'));
}
}

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway;
use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\Exception\ModuleExceptionInterface;
use Dhii\Modular\Module\ModuleInterface;
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
@ -42,5 +42,16 @@ class WcGatewayModule implements ModuleInterface
return $disabler->handler((array) $methods);
}
);
add_action(
'admin_notices',
function () use ($container) : void {
$notice = $container->get('wcgateway.notice.connect');
/**
* @var ConnectAdminNotice $notice
*/
$notice->display();
}
);
}
}