woocommerce-paypal-payments/modules/ppcp-order-tracking/src/OrderTrackingModule.php

81 lines
2.5 KiB
PHP
Raw Normal View History

2022-08-11 14:22:16 +04:00
<?php
/**
* The order tracking module.
*
* @package WooCommerce\PayPalCommerce\OrderTracking
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\OrderTracking;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
2022-08-11 17:37:09 +04:00
use Exception;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
2022-08-11 17:37:09 +04:00
use Psr\Log\LoggerInterface;
2022-08-11 14:22:16 +04:00
use WC_Order;
use WooCommerce\PayPalCommerce\OrderTracking\Assets\OrderEditPageAssets;
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2022-08-16 16:49:16 +04:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
2022-08-11 14:22:16 +04:00
/**
* Class OrderTrackingModule
*/
class OrderTrackingModule implements ModuleInterface {
2023-07-25 13:17:32 +04:00
public const PPCP_TRACKING_INFO_META_NAME = '_ppcp_paypal_tracking_info_meta_name';
2022-08-11 17:37:09 +04:00
/**
* {@inheritDoc}
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* {@inheritDoc}
*
* @param ContainerInterface $c A services container instance.
* @throws NotFoundException
2022-08-11 17:37:09 +04:00
*/
public function run( ContainerInterface $c ): void {
2023-07-25 13:17:32 +04:00
$tracking_enabled = $c->get( 'order-tracking.is-module-enabled' );
2022-08-11 17:37:09 +04:00
2023-07-31 18:08:00 +04:00
$endpoint = $c->get( 'order-tracking.endpoint.controller' );
assert( $endpoint instanceof OrderTrackingEndpoint );
add_action( 'wc_ajax_' . OrderTrackingEndpoint::ENDPOINT, array( $endpoint, 'handle_request' ) );
2022-08-11 17:37:09 +04:00
if ( ! $tracking_enabled ) {
return;
}
$asset_loader = $c->get( 'order-tracking.assets' );
assert( $asset_loader instanceof OrderEditPageAssets );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
2022-08-17 19:06:20 +04:00
assert( $logger instanceof LoggerInterface );
2022-08-11 17:37:09 +04:00
2023-07-25 13:17:32 +04:00
add_action( 'init', array( $asset_loader, 'register' ) );
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
2022-08-11 17:37:09 +04:00
$meta_box_renderer = $c->get( 'order-tracking.meta-box.renderer' );
add_action(
'add_meta_boxes',
2023-07-25 13:17:32 +04:00
static function() use ( $meta_box_renderer ) {
add_meta_box( 'ppcp_order-tracking', __( 'PayPal Shipment Tracking', 'woocommerce-paypal-payments' ), array( $meta_box_renderer, 'render' ), 'shop_order', 'normal' );
2022-08-11 17:37:09 +04:00
},
10,
2
);
}
2022-08-11 14:22:16 +04:00
}