mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
cleanup, connect gateway with settings
This commit is contained in:
parent
4676a8b5dd
commit
68708607f4
4 changed files with 11 additions and 39 deletions
|
@ -9,38 +9,29 @@ use Inpsyde\PayPalCommerce\Onboarding\State;
|
|||
use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\ResetGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGatewayBase;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\FullyOnboardedSettings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\ProgressiveSettings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\StartSettings;
|
||||
|
||||
return [
|
||||
'wcgateway.gateway.base' => static function (ContainerInterface $container): WcGatewayBase {
|
||||
return new WcGatewayBase();
|
||||
},
|
||||
'wcgateway.gateway' => static function (ContainerInterface $container): WcGateway {
|
||||
$orderProcessor = $container->get('wcgateway.order-processor');
|
||||
$settingsRenderer = $container->get('wcgateway.settings.render');
|
||||
$authorizedPayments = $container->get('wcgateway.processor.authorized-payments');
|
||||
$notice = $container->get('wcgateway.notice.authorize-order-action');
|
||||
$onboardingRender = $container->get('onboarding.render');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
|
||||
return new WcGateway(
|
||||
$settingsRenderer,
|
||||
$orderProcessor,
|
||||
$authorizedPayments,
|
||||
$notice,
|
||||
$onboardingRender
|
||||
$settings
|
||||
);
|
||||
},
|
||||
'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways {
|
||||
|
@ -48,8 +39,7 @@ return [
|
|||
return new DisableGateways($sessionHandler);
|
||||
},
|
||||
'wcgateway.settings' => static function (ContainerInterface $container): Settings {
|
||||
$gateway = $container->get('wcgateway.gateway.base');
|
||||
return new Settings($gateway);
|
||||
return new Settings();
|
||||
},
|
||||
'wcgateway.notice.connect' => static function (ContainerInterface $container): ConnectAdminNotice {
|
||||
$state = $container->get('onboarding.state');
|
||||
|
|
|
@ -17,6 +17,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
|||
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
|
@ -31,21 +32,21 @@ class WcGateway extends WcGatewayBase
|
|||
private $authorizedPayments;
|
||||
private $notice;
|
||||
private $orderProcessor;
|
||||
private $onboardingRenderer;
|
||||
private $config;
|
||||
|
||||
public function __construct(
|
||||
SettingsRenderer $settingsRenderer,
|
||||
OrderProcessor $orderProcessor,
|
||||
AuthorizedPaymentsProcessor $authorizedPayments,
|
||||
AuthorizeOrderActionNotice $notice,
|
||||
OnboardingRenderer $onboardingRenderer
|
||||
ContainerInterface $config
|
||||
) {
|
||||
|
||||
$this->orderProcessor = $orderProcessor;
|
||||
$this->authorizedPayments = $authorizedPayments;
|
||||
$this->notice = $notice;
|
||||
$this->settingsRenderer = $settingsRenderer;
|
||||
$this->onboardingRenderer = $onboardingRenderer;
|
||||
$this->config = $config;
|
||||
|
||||
$this->method_title = __('PayPal Payments', 'woocommerce-paypal-gateway');
|
||||
$this->method_description = __(
|
||||
|
@ -55,8 +56,8 @@ class WcGateway extends WcGatewayBase
|
|||
|
||||
parent::__construct();
|
||||
|
||||
$this->title = $this->get_option('title');
|
||||
$this->description = $this->get_option('description');
|
||||
$this->title = $this->config->has('title') ? $this->config->get('title') : $this->method_title;
|
||||
$this->description = $this->config->has('description') ? $this->config->get('description') : $this->method_description;
|
||||
|
||||
$this->init_form_fields();
|
||||
$this->init_settings();
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
||||
|
||||
use WC_Payment_Gateway;
|
||||
|
||||
class WcGatewayBase extends WC_Payment_Gateway implements WcGatewayInterface
|
||||
{
|
||||
public const ID = 'ppcp-gateway';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = self::ID;
|
||||
}
|
||||
}
|
|
@ -35,16 +35,14 @@ class SettingsListener
|
|||
return;
|
||||
}
|
||||
|
||||
$settings = [
|
||||
'enabled' => isset($_POST['woocommerce_ppcp-gateway_enabled'])
|
||||
&& absint($_POST['woocommerce_ppcp-gateway_enabled']) === 1,
|
||||
];
|
||||
//phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
/**
|
||||
* Sanitization is done at a later stage.
|
||||
*/
|
||||
$rawData = (isset($_POST['ppcp'])) ? (array) wp_unslash($_POST['ppcp']) : [];
|
||||
$settings = $this->retrieveSettingsFromRawData($rawData);
|
||||
$settings['enabled'] = isset($_POST['woocommerce_ppcp-gateway_enabled'])
|
||||
&& absint($_POST['woocommerce_ppcp-gateway_enabled']) === 1;
|
||||
foreach ($settings as $id => $value) {
|
||||
$this->settings->set($id, $value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue