2021-07-15 06:51:37 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The compatibility module.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Compat
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Compat;
|
|
|
|
|
|
|
|
use Dhii\Container\ServiceProvider;
|
|
|
|
use Dhii\Modular\Module\ModuleInterface;
|
2022-10-03 18:20:25 +04:00
|
|
|
use Exception;
|
2021-07-15 06:51:37 -05:00
|
|
|
use Interop\Container\ServiceProviderInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
2022-10-03 18:20:25 +04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-10-04 15:51:30 +04:00
|
|
|
use Vendidero\Germanized\Shipments\Shipment;
|
2022-10-03 18:20:25 +04:00
|
|
|
use WC_Order;
|
|
|
|
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
|
|
|
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
2021-07-15 06:51:37 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CompatModule
|
|
|
|
*/
|
|
|
|
class CompatModule implements ModuleInterface {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the compatibility module.
|
|
|
|
*
|
|
|
|
* @return ServiceProviderInterface
|
|
|
|
*/
|
|
|
|
public function setup(): ServiceProviderInterface {
|
|
|
|
return new ServiceProvider(
|
|
|
|
require __DIR__ . '/../services.php',
|
|
|
|
require __DIR__ . '/../extensions.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-19 19:11:36 +04:00
|
|
|
* {@inheritDoc}
|
2022-10-03 18:20:25 +04:00
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
2021-07-15 06:51:37 -05:00
|
|
|
*/
|
2021-08-30 08:10:43 +02:00
|
|
|
public function run( ContainerInterface $c ): void {
|
|
|
|
$this->initialize_ppec_compat_layer( $c );
|
2022-08-19 18:54:32 +04:00
|
|
|
$this->fix_site_ground_optimizer_compatibility( $c );
|
2022-10-03 18:20:25 +04:00
|
|
|
$this->initialize_gzd_compat_layer( $c );
|
|
|
|
|
|
|
|
$asset_loader = $c->get( 'compat.assets' );
|
|
|
|
assert( $asset_loader instanceof CompatAssets );
|
|
|
|
|
|
|
|
add_action( 'init', array( $asset_loader, 'register' ) );
|
|
|
|
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
|
2021-07-15 06:51:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the key for the module.
|
|
|
|
*
|
|
|
|
* @return string|void
|
|
|
|
*/
|
|
|
|
public function getKey() {
|
|
|
|
}
|
2021-07-27 15:08:25 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the PayPal Express Checkout compatibility layer.
|
|
|
|
*
|
2022-08-19 19:11:36 +04:00
|
|
|
* @param ContainerInterface $container The Container.
|
2021-07-27 15:08:25 -05:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-08-19 19:11:36 +04:00
|
|
|
private function initialize_ppec_compat_layer( ContainerInterface $container ): void {
|
2021-07-16 14:00:01 -05:00
|
|
|
// Process PPEC subscription renewals through PayPal Payments.
|
|
|
|
$handler = $container->get( 'compat.ppec.subscriptions-handler' );
|
|
|
|
$handler->maybe_hook();
|
2021-07-14 15:06:32 -05:00
|
|
|
|
|
|
|
// Settings.
|
|
|
|
$ppec_import = $container->get( 'compat.ppec.settings_importer' );
|
|
|
|
$ppec_import->maybe_hook();
|
2021-07-29 16:07:12 -05:00
|
|
|
|
|
|
|
// Inbox note inviting merchant to disable PayPal Express Checkout.
|
|
|
|
add_action(
|
|
|
|
'woocommerce_init',
|
|
|
|
function() {
|
2021-08-09 19:16:44 -07:00
|
|
|
if ( is_callable( array( WC(), 'is_wc_admin_active' ) ) && WC()->is_wc_admin_active() && class_exists( 'Automattic\WooCommerce\Admin\Notes\Notes' ) ) {
|
2021-07-29 16:07:12 -05:00
|
|
|
PPEC\DeactivateNote::init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-07-27 15:08:25 -05:00
|
|
|
}
|
|
|
|
|
2022-08-19 18:54:32 +04:00
|
|
|
/**
|
|
|
|
* Fixes the compatibility issue for <a href="https://wordpress.org/plugins/sg-cachepress/">SiteGround Optimizer plugin</a>.
|
|
|
|
*
|
|
|
|
* @link https://wordpress.org/plugins/sg-cachepress/
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $c The Container.
|
|
|
|
*/
|
|
|
|
protected function fix_site_ground_optimizer_compatibility( ContainerInterface $c ): void {
|
|
|
|
$ppcp_script_names = $c->get( 'compat.plugin-script-names' );
|
|
|
|
add_filter(
|
|
|
|
'sgo_js_minify_exclude',
|
|
|
|
function ( array $scripts ) use ( $ppcp_script_names ) {
|
|
|
|
return array_merge( $scripts, $ppcp_script_names );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2022-10-03 18:20:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the <a href="https://wordpress.org/plugins/woocommerce-germanized/">Germanized for WooCommerce</a>
|
|
|
|
* plugin compatibility layer.
|
|
|
|
*
|
|
|
|
* @link https://wordpress.org/plugins/woocommerce-germanized/
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $c The Container.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function initialize_gzd_compat_layer( ContainerInterface $c ): void {
|
2022-10-04 16:42:38 +04:00
|
|
|
if ( ! $c->get( 'compat.should-initialize-gzd-compat-layer' ) ) {
|
2022-10-03 18:20:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$endpoint = $c->get( 'order-tracking.endpoint.controller' );
|
|
|
|
assert( $endpoint instanceof OrderTrackingEndpoint );
|
|
|
|
|
|
|
|
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
|
|
|
assert( $logger instanceof LoggerInterface );
|
|
|
|
|
|
|
|
$status_map = $c->get( 'compat.gzd.tracking_statuses_map' );
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_gzd_shipment_after_save',
|
2022-10-04 15:51:30 +04:00
|
|
|
static function( Shipment $shipment ) use ( $endpoint, $logger, $status_map ) {
|
2022-10-07 16:53:09 +04:00
|
|
|
if ( ! apply_filters( 'woocommerce_paypal_payments_sync_gzd_tracking', true ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-07 16:47:28 +04:00
|
|
|
|
2022-10-03 19:42:49 +04:00
|
|
|
$gzd_shipment_status = $shipment->get_status();
|
2022-10-03 18:20:25 +04:00
|
|
|
if ( ! array_key_exists( $gzd_shipment_status, $status_map ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$wc_order = $shipment->get_order();
|
|
|
|
if ( ! is_a( $wc_order, WC_Order::class ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$transaction_id = $wc_order->get_transaction_id();
|
|
|
|
if ( empty( $transaction_id ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tracking_data = array(
|
|
|
|
'transaction_id' => $transaction_id,
|
2022-10-03 19:42:49 +04:00
|
|
|
'status' => (string) $status_map[ $gzd_shipment_status ],
|
2022-10-03 18:20:25 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
$provider = $shipment->get_shipping_provider();
|
|
|
|
if ( ! empty( $provider ) && $provider !== 'none' ) {
|
|
|
|
$tracking_data['carrier'] = 'DHL_DEUTSCHE_POST';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $shipment->has_tracking() ) {
|
|
|
|
$tracking_data['tracking_number'] = $shipment->get_tracking_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$tracking_information = $endpoint->get_tracking_information( $wc_order->get_id() );
|
|
|
|
! $tracking_information ? $endpoint->add_tracking_information( $tracking_data, $wc_order->get_id() ) : $endpoint->update_tracking_information( $tracking_data, $wc_order->get_id() );
|
|
|
|
} catch ( Exception $exception ) {
|
|
|
|
$logger->error( "Couldn't sync tracking information: " . $exception->getMessage() );
|
|
|
|
throw $exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-07-15 06:51:37 -05:00
|
|
|
}
|