2021-07-15 06:51:37 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The compatibility module services.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Compat
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Compat;
|
|
|
|
|
2022-10-03 18:19:35 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
2025-02-21 13:16:26 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\GeneralSettingsMapHelper;
|
2025-03-04 18:32:54 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\PaymentMethodSettingsMapHelper;
|
2025-02-06 16:37:24 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\SettingsMap;
|
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\SettingsMapHelper;
|
2025-02-13 19:43:23 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\SettingsTabMapHelper;
|
2025-02-06 16:37:24 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\StylingSettingsMapHelper;
|
2025-02-20 13:05:33 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\Settings\SubscriptionSettingsMapHelper;
|
2025-02-06 16:37:24 +04:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
2021-10-13 15:02:10 +03:00
|
|
|
|
2021-07-27 14:34:36 -05:00
|
|
|
return array(
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.ppec.mock-gateway' => static function( $container ) {
|
2021-07-27 14:34:36 -05:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
|
|
|
$title = $settings->has( 'title' ) ? $settings->get( 'title' ) : __( 'PayPal', 'woocommerce-paypal-payments' );
|
|
|
|
$title = sprintf(
|
|
|
|
/* Translators: placeholder is the gateway name. */
|
|
|
|
__( '%s (Legacy)', 'woocommerce-paypal-payments' ),
|
|
|
|
$title
|
|
|
|
);
|
|
|
|
|
|
|
|
return new PPEC\MockGateway( $title );
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.ppec.subscriptions-handler' => static function ( ContainerInterface $container ) {
|
2023-10-18 17:03:15 +02:00
|
|
|
$ppcp_renewal_handler = $container->get( 'wc-subscriptions.renewal-handler' );
|
2021-07-16 14:00:01 -05:00
|
|
|
$gateway = $container->get( 'compat.ppec.mock-gateway' );
|
|
|
|
|
|
|
|
return new PPEC\SubscriptionsHandler( $ppcp_renewal_handler, $gateway );
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.ppec.settings_importer' => static function( ContainerInterface $container ) : PPEC\SettingsImporter {
|
2021-07-14 15:06:32 -05:00
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
|
|
|
|
|
|
|
return new PPEC\SettingsImporter( $settings );
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.plugin-script-names' => static function( ContainerInterface $container ) : array {
|
2022-08-19 18:54:32 +04:00
|
|
|
return array(
|
|
|
|
'ppcp-smart-button',
|
|
|
|
'ppcp-oxxo',
|
|
|
|
'ppcp-pay-upon-invoice',
|
|
|
|
'ppcp-vaulting-myaccount-payments',
|
|
|
|
'ppcp-gateway-settings',
|
|
|
|
'ppcp-webhooks-status-page',
|
|
|
|
'ppcp-tracking',
|
2023-05-11 14:36:41 +02:00
|
|
|
'ppcp-fraudnet',
|
2023-07-25 13:17:32 +04:00
|
|
|
'ppcp-tracking-compat',
|
2023-06-06 12:24:05 +02:00
|
|
|
'ppcp-clear-db',
|
2025-03-21 16:49:18 +01:00
|
|
|
'ppcp-admin-settings',
|
2022-08-19 18:54:32 +04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2024-06-05 20:50:39 +02:00
|
|
|
'compat.plugin-script-file-names' => static function( ContainerInterface $container ) : array {
|
|
|
|
return array(
|
|
|
|
'button.js',
|
|
|
|
'gateway-settings.js',
|
|
|
|
'status-page.js',
|
|
|
|
'order-edit-page.js',
|
|
|
|
'fraudnet.js',
|
|
|
|
'tracking-compat.js',
|
|
|
|
'ppcp-clear-db.js',
|
2025-03-21 16:49:18 +01:00
|
|
|
'ppcp-admin-settings.js',
|
2024-06-05 20:50:39 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.gzd.is_supported_plugin_version_active' => function (): bool {
|
2022-10-03 18:19:35 +04:00
|
|
|
return function_exists( 'wc_gzd_get_shipments_by_order' ); // 3.0+
|
|
|
|
},
|
|
|
|
|
2023-07-25 13:17:32 +04:00
|
|
|
'compat.wc_shipment_tracking.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return class_exists( 'WC_Shipment_Tracking' );
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.ywot.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return function_exists( 'yith_ywot_init' );
|
|
|
|
},
|
2024-07-25 14:08:45 +04:00
|
|
|
'compat.dhl.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return function_exists( 'PR_DHL' );
|
|
|
|
},
|
2023-10-17 16:30:38 +04:00
|
|
|
'compat.shipstation.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return function_exists( 'woocommerce_shipstation_init' );
|
|
|
|
},
|
2023-10-27 11:28:04 +04:00
|
|
|
'compat.wc_shipping_tax.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return class_exists( 'WC_Connect_Loader' );
|
|
|
|
},
|
2024-07-09 15:40:50 +04:00
|
|
|
'compat.nyp.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return function_exists( 'wc_nyp_init' );
|
|
|
|
},
|
2024-07-22 18:18:52 +04:00
|
|
|
'compat.wc_bookings.is_supported_plugin_version_active' => function (): bool {
|
|
|
|
return class_exists( 'WC_Bookings' );
|
|
|
|
},
|
2023-09-01 18:42:27 +04:00
|
|
|
|
|
|
|
'compat.module.url' => static function ( ContainerInterface $container ): string {
|
2022-10-03 18:19:35 +04:00
|
|
|
/**
|
|
|
|
* The path cannot be false.
|
|
|
|
*
|
|
|
|
* @psalm-suppress PossiblyFalseArgument
|
|
|
|
*/
|
|
|
|
return plugins_url(
|
|
|
|
'/modules/ppcp-compat/',
|
|
|
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2023-09-01 18:42:27 +04:00
|
|
|
'compat.assets' => function( ContainerInterface $container ) : CompatAssets {
|
2022-10-03 18:19:35 +04:00
|
|
|
return new CompatAssets(
|
|
|
|
$container->get( 'compat.module.url' ),
|
|
|
|
$container->get( 'ppcp.asset-version' ),
|
2023-07-25 13:17:32 +04:00
|
|
|
$container->get( 'compat.gzd.is_supported_plugin_version_active' ),
|
2023-09-08 19:38:14 +04:00
|
|
|
$container->get( 'compat.wc_shipment_tracking.is_supported_plugin_version_active' ),
|
2023-10-27 14:59:50 +04:00
|
|
|
$container->get( 'compat.wc_shipping_tax.is_supported_plugin_version_active' ),
|
2023-09-08 19:38:14 +04:00
|
|
|
$container->get( 'api.bearer' )
|
2022-10-03 18:19:35 +04:00
|
|
|
);
|
|
|
|
},
|
2025-02-06 16:23:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration for the new/old settings map.
|
|
|
|
*
|
|
|
|
* @returns SettingsMap[]
|
|
|
|
*/
|
|
|
|
'compat.setting.new-to-old-map' => static function( ContainerInterface $container ) : array {
|
|
|
|
$are_new_settings_enabled = $container->get( 'wcgateway.settings.admin-settings-enabled' );
|
|
|
|
if ( ! $are_new_settings_enabled ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$styling_settings_map_helper = $container->get( 'compat.settings.styling_map_helper' );
|
|
|
|
assert( $styling_settings_map_helper instanceof StylingSettingsMapHelper );
|
|
|
|
|
2025-02-13 19:43:23 +04:00
|
|
|
$settings_tab_map_helper = $container->get( 'compat.settings.settings_tab_map_helper' );
|
|
|
|
assert( $settings_tab_map_helper instanceof SettingsTabMapHelper );
|
|
|
|
|
2025-02-20 13:31:17 +04:00
|
|
|
$subscription_map_helper = $container->get( 'compat.settings.subscription_map_helper' );
|
|
|
|
assert( $subscription_map_helper instanceof SubscriptionSettingsMapHelper );
|
|
|
|
|
2025-02-21 13:16:26 +04:00
|
|
|
$general_map_helper = $container->get( 'compat.settings.general_map_helper' );
|
|
|
|
assert( $general_map_helper instanceof GeneralSettingsMapHelper );
|
|
|
|
|
2025-03-04 18:32:54 +04:00
|
|
|
$payment_methods_map_helper = $container->get( 'compat.settings.payment_methods_map_helper' );
|
|
|
|
assert( $payment_methods_map_helper instanceof PaymentMethodSettingsMapHelper );
|
|
|
|
|
2025-02-06 16:23:50 +04:00
|
|
|
return array(
|
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.general' ),
|
2025-02-21 13:16:26 +04:00
|
|
|
$general_map_helper->map()
|
2025-02-06 16:23:50 +04:00
|
|
|
),
|
2025-02-13 16:26:08 +04:00
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.settings' ),
|
2025-02-13 19:43:23 +04:00
|
|
|
$settings_tab_map_helper->map()
|
2025-02-13 16:26:08 +04:00
|
|
|
),
|
2025-02-06 16:23:50 +04:00
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.styling' ),
|
|
|
|
/**
|
|
|
|
* The `StylingSettings` class stores settings as `LocationStylingDTO` objects.
|
|
|
|
* This method creates a mapping from old setting keys to the corresponding style names.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* 'button_product_layout' => 'layout'
|
|
|
|
*
|
|
|
|
* This mapping will allow to retrieve the correct style value
|
|
|
|
* from a `LocationStylingDTO` object by dynamically accessing its properties.
|
|
|
|
*/
|
|
|
|
$styling_settings_map_helper->map()
|
|
|
|
),
|
2025-02-20 13:31:17 +04:00
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.settings' ),
|
|
|
|
$subscription_map_helper->map()
|
|
|
|
),
|
2025-02-27 18:17:37 +04:00
|
|
|
/**
|
|
|
|
* We need to pass the PaymentSettings model instance to use it in some helpers.
|
|
|
|
* Once the new settings module is permanently enabled,
|
|
|
|
* this model can be passed as a dependency to the appropriate helper classes.
|
|
|
|
* For now, we must pass it this way to avoid errors when the new settings module is disabled.
|
|
|
|
*/
|
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.payment' ),
|
|
|
|
array()
|
|
|
|
),
|
2025-03-04 18:32:54 +04:00
|
|
|
new SettingsMap(
|
|
|
|
$container->get( 'settings.data.payment' ),
|
|
|
|
$payment_methods_map_helper->map()
|
|
|
|
),
|
2025-02-06 16:23:50 +04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
'compat.settings.settings_map_helper' => static function( ContainerInterface $container ) : SettingsMapHelper {
|
|
|
|
return new SettingsMapHelper(
|
|
|
|
$container->get( 'compat.setting.new-to-old-map' ),
|
2025-02-13 19:43:23 +04:00
|
|
|
$container->get( 'compat.settings.styling_map_helper' ),
|
2025-02-21 13:16:26 +04:00
|
|
|
$container->get( 'compat.settings.settings_tab_map_helper' ),
|
2025-02-21 15:40:10 +04:00
|
|
|
$container->get( 'compat.settings.subscription_map_helper' ),
|
2025-02-28 19:47:03 +04:00
|
|
|
$container->get( 'compat.settings.general_map_helper' ),
|
2025-03-04 18:32:54 +04:00
|
|
|
$container->get( 'compat.settings.payment_methods_map_helper' ),
|
2025-02-28 19:47:03 +04:00
|
|
|
$container->get( 'wcgateway.settings.admin-settings-enabled' )
|
2025-02-06 16:23:50 +04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
'compat.settings.styling_map_helper' => static function() : StylingSettingsMapHelper {
|
|
|
|
return new StylingSettingsMapHelper();
|
|
|
|
},
|
2025-02-13 19:43:23 +04:00
|
|
|
'compat.settings.settings_tab_map_helper' => static function() : SettingsTabMapHelper {
|
|
|
|
return new SettingsTabMapHelper();
|
|
|
|
},
|
2025-02-20 13:05:33 +04:00
|
|
|
'compat.settings.subscription_map_helper' => static function( ContainerInterface $container ) : SubscriptionSettingsMapHelper {
|
|
|
|
return new SubscriptionSettingsMapHelper( $container->get( 'wc-subscriptions.helper' ) );
|
|
|
|
},
|
2025-02-21 13:16:26 +04:00
|
|
|
'compat.settings.general_map_helper' => static function() : GeneralSettingsMapHelper {
|
|
|
|
return new GeneralSettingsMapHelper();
|
|
|
|
},
|
2025-03-04 18:32:54 +04:00
|
|
|
'compat.settings.payment_methods_map_helper' => static function() : PaymentMethodSettingsMapHelper {
|
|
|
|
return new PaymentMethodSettingsMapHelper();
|
|
|
|
},
|
2021-07-27 14:34:36 -05:00
|
|
|
);
|