woocommerce-paypal-payments/modules.local/ppcp-wc-gateway/services.php

100 lines
4.6 KiB
PHP
Raw Normal View History

2020-04-02 08:38:00 +03:00
<?php
2020-04-02 08:38:00 +03:00
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway;
use Dhii\Data\Container\ContainerInterface;
2020-06-15 11:48:37 +03:00
use Inpsyde\PayPalCommerce\Onboarding\State;
2020-04-23 11:19:09 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
2020-04-02 08:38:00 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGatewayBase;
2020-04-13 22:30:57 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
2020-04-28 13:32:48 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
2020-06-15 11:48:37 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\FullyOnboardedSettings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\ProgressiveSettings;
2020-04-09 14:02:35 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
2020-06-15 11:48:37 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\StartSettings;
2020-04-02 08:38:00 +03:00
return [
2020-04-28 12:31:12 +03:00
'wcgateway.gateway.base' => static function (ContainerInterface $container): WcGatewayBase {
return new WcGatewayBase();
},
2020-04-28 12:31:12 +03:00
'wcgateway.gateway' => static function (ContainerInterface $container): WcGateway {
2020-04-28 13:32:48 +03:00
$orderProcessor = $container->get('wcgateway.order-processor');
2020-04-09 14:02:35 +03:00
$settingsFields = $container->get('wcgateway.settings.fields');
2020-04-28 13:32:48 +03:00
$authorizedPayments = $container->get('wcgateway.processor.authorized-payments');
2020-04-28 12:31:12 +03:00
$notice = $container->get('wcgateway.notice.authorize-order-action');
2020-06-15 11:48:37 +03:00
$onboardingRender = $container->get('onboarding.render');
return new WcGateway(
$settingsFields,
2020-04-28 13:32:48 +03:00
$orderProcessor,
$authorizedPayments,
2020-06-15 11:48:37 +03:00
$notice,
$onboardingRender
);
2020-04-02 08:38:00 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways {
2020-04-02 08:38:00 +03:00
$sessionHandler = $container->get('session.handler');
return new DisableGateways($sessionHandler);
2020-04-06 11:16:18 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.settings' => static function (ContainerInterface $container): Settings {
$gateway = $container->get('wcgateway.gateway.base');
2020-06-15 11:48:37 +03:00
return new Settings($gateway);
2020-04-09 14:02:35 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.notice.connect' => static function (ContainerInterface $container): ConnectAdminNotice {
2020-06-15 11:48:37 +03:00
$state = $container->get('onboarding.state');
$settings = $container->get('wcgateway.settings');
2020-06-15 11:48:37 +03:00
return new ConnectAdminNotice($state, $settings);
},
2020-04-13 22:30:57 +03:00
'wcgateway.notice.authorize-order-action' =>
2020-04-28 12:31:12 +03:00
static function (ContainerInterface $container): AuthorizeOrderActionNotice {
2020-04-13 22:30:57 +03:00
return new AuthorizeOrderActionNotice();
},
2020-04-28 12:31:12 +03:00
'wcgateway.settings.fields' => static function (ContainerInterface $container): SettingsFields {
2020-06-15 11:48:37 +03:00
$state = $container->get('onboarding.state');
/**
* @var State $state
*/
if ($state->currentState() === State::STATE_START) {
return new StartSettings();
}
if ($state->currentState() === State::STATE_PROGRESSIVE) {
return new ProgressiveSettings();
}
return new FullyOnboardedSettings();
2020-04-09 14:36:52 +03:00
},
2020-04-28 13:32:48 +03:00
'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor {
$sessionHandler = $container->get('session.handler');
$cartRepository = $container->get('api.repository.cart');
$orderEndpoint = $container->get('api.endpoint.order');
$paymentsEndpoint = $container->get('api.endpoint.payments');
$orderFactory = $container->get('api.factory.order');
return new OrderProcessor(
$sessionHandler,
$cartRepository,
$orderEndpoint,
$paymentsEndpoint,
$orderFactory
);
},
2020-04-28 12:31:12 +03:00
'wcgateway.processor.authorized-payments' => static function (ContainerInterface $container): AuthorizedPaymentsProcessor {
$orderEndpoint = $container->get('api.endpoint.order');
$paymentsEndpoint = $container->get('api.endpoint.payments');
return new AuthorizedPaymentsProcessor($orderEndpoint, $paymentsEndpoint);
},
2020-04-28 12:31:12 +03:00
'wcgateway.admin.order-payment-status' => static function (ContainerInterface $container): PaymentStatusOrderDetail {
2020-04-23 11:19:09 +03:00
return new PaymentStatusOrderDetail();
},
2020-04-28 12:31:12 +03:00
'wcgateway.admin.orders-payment-status-column' => static function (ContainerInterface $container): OrderTablePaymentStatusColumn {
$settings = $container->get('wcgateway.settings');
2020-04-23 11:19:09 +03:00
return new OrderTablePaymentStatusColumn($settings);
2020-04-28 12:31:12 +03:00
},
2020-04-02 08:38:00 +03:00
];