mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'master' of github.com:inpsyde/woocommerce-paypal-commerce-gateway
This commit is contained in:
commit
292e48942e
7 changed files with 96 additions and 9 deletions
|
@ -6,10 +6,15 @@ 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\Gateway\WcGatewayBase;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||
|
||||
return [
|
||||
'wcgateway.gateway.base' => function (ContainerInterface $container) : WcGatewayBase {
|
||||
return new WcGatewayBase();
|
||||
},
|
||||
'wcgateway.gateway' => function (ContainerInterface $container) : WcGateway {
|
||||
$sessionHandler = $container->get('session.handler');
|
||||
$cartRepository = $container->get('api.cart-repository');
|
||||
|
@ -23,10 +28,14 @@ return [
|
|||
return new DisableGateways($sessionHandler);
|
||||
},
|
||||
'wcgateway.settings' => function (ContainerInterface $container) : Settings {
|
||||
$gateway = $container->get('wcgateway.gateway');
|
||||
$gateway = $container->get('wcgateway.gateway.base');
|
||||
$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();
|
||||
},
|
||||
|
|
|
@ -13,11 +13,8 @@ use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
|||
|
||||
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
class WcGateway extends \WC_Payment_Gateway
|
||||
class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||
{
|
||||
|
||||
const ID = 'ppcp-gateway';
|
||||
|
||||
private $isSandbox = true;
|
||||
private $sessionHandler;
|
||||
private $endpoint;
|
||||
|
@ -38,7 +35,6 @@ class WcGateway extends \WC_Payment_Gateway
|
|||
$this->endpoint = $endpoint;
|
||||
$this->orderFactory = $orderFactory;
|
||||
$this->settingsFields = $settingsFields;
|
||||
$this->id = self::ID;
|
||||
|
||||
$this->method_title = __('PayPal Payments', 'woocommerce-paypal-gateway');
|
||||
$this->method_description = __(
|
||||
|
@ -59,6 +55,8 @@ class WcGateway extends \WC_Payment_Gateway
|
|||
'process_admin_options',
|
||||
]
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function init_form_fields()
|
||||
|
|
16
modules.local/ppcp-wc-gateway/src/Gateway/WcGatewayBase.php
Normal file
16
modules.local/ppcp-wc-gateway/src/Gateway/WcGatewayBase.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use WC_Payment_Gateway;
|
||||
|
||||
class WcGatewayBase extends WC_Payment_Gateway implements WcGatewayInterface
|
||||
{
|
||||
const ID = 'ppcp-gateway';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = self::ID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
interface WcGatewayInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -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'));
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGatewayInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Settings implements ContainerInterface
|
||||
|
@ -13,7 +13,7 @@ class Settings implements ContainerInterface
|
|||
private $gateway;
|
||||
private $formFields;
|
||||
|
||||
public function __construct(WcGateway $gateway, SettingsFields $formFields)
|
||||
public function __construct(WcGatewayInterface $gateway, SettingsFields $formFields)
|
||||
{
|
||||
$this->gateway = $gateway;
|
||||
$this->formFields = $formFields;
|
||||
|
|
|
@ -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