mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #5 from inpsyde/refactor/settings-class
Use a base gateway class with minimal config
This commit is contained in:
commit
33c256c48b
5 changed files with 35 additions and 8 deletions
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue