Merge pull request #5 from inpsyde/refactor/settings-class

Use a base gateway class with minimal config
This commit is contained in:
David Remer 2020-04-13 15:17:23 +03:00 committed by GitHub
commit 33c256c48b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 8 deletions

View file

@ -6,11 +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');
@ -24,7 +28,7 @@ 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);
},

View file

@ -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()

View 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;
}
}

View file

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
interface WcGatewayInterface
{
}

View file

@ -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;