mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #4 from inpsyde/feature/configure-gateway-notice
Add configure gateway admin notice
This commit is contained in:
commit
6aa87da598
3 changed files with 61 additions and 1 deletions
|
@ -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();
|
||||
},
|
||||
|
|
|
@ -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§ion=ppcp-gateway')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function shouldDisplay(): bool
|
||||
{
|
||||
// TODO: decide on what condition to display
|
||||
return !wc_string_to_bool($this->settings->get('enabled'));
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue