2024-02-06 12:01:38 +00:00
< ? php
/**
* The Axo module services .
*
* @ package WooCommerce\PayPalCommerce\Axo
*/
declare ( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Axo ;
2024-02-14 18:17:03 +00:00
use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager ;
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway ;
2024-03-25 10:28:15 +00:00
use WooCommerce\PayPalCommerce\Axo\Helper\ApmApplies ;
2024-07-18 00:27:35 +02:00
use WooCommerce\PayPalCommerce\Axo\Helper\SettingsNoticeGenerator ;
2024-02-08 14:37:56 +00:00
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface ;
2024-05-15 14:42:40 +02:00
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway ;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway ;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings ;
2024-09-26 18:44:25 +02:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration ;
2024-02-08 14:37:56 +00:00
2024-02-06 12:01:38 +00:00
return array (
2024-03-25 10:28:15 +00:00
// If AXO can be configured.
2024-09-03 15:05:23 +04:00
'axo.eligible' => static function ( ContainerInterface $container ) : bool {
2024-03-25 10:28:15 +00:00
$apm_applies = $container -> get ( 'axo.helpers.apm-applies' );
assert ( $apm_applies instanceof ApmApplies );
2024-07-17 19:06:40 +02:00
return $apm_applies -> for_country_currency ();
2024-03-25 10:28:15 +00:00
},
2024-09-03 15:05:23 +04:00
'axo.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
2024-03-25 10:28:15 +00:00
return new ApmApplies (
$container -> get ( 'axo.supported-country-currency-matrix' ),
2024-10-03 10:10:50 +03:00
$container -> get ( 'api.shop.currency.getter' ),
2024-03-25 10:28:15 +00:00
$container -> get ( 'api.shop.country' )
);
},
2024-09-03 15:05:23 +04:00
'axo.helpers.settings-notice-generator' => static function ( ContainerInterface $container ) : SettingsNoticeGenerator {
return new SettingsNoticeGenerator ( $container -> get ( 'axo.fastlane-incompatible-plugin-names' ) );
2024-07-18 00:27:35 +02:00
},
2024-03-25 10:28:15 +00:00
// If AXO is configured and onboarded.
2024-09-03 15:05:23 +04:00
'axo.available' => static function ( ContainerInterface $container ) : bool {
2024-03-25 10:28:15 +00:00
return true ;
},
2024-09-03 15:05:23 +04:00
'axo.url' => static function ( ContainerInterface $container ) : string {
2024-02-08 14:37:56 +00:00
$path = realpath ( __FILE__ );
if ( false === $path ) {
return '' ;
}
return plugins_url (
'/modules/ppcp-axo/' ,
dirname ( $path , 3 ) . '/woocommerce-paypal-payments.php'
);
},
2024-09-03 15:05:23 +04:00
'axo.manager' => static function ( ContainerInterface $container ) : AxoManager {
2024-02-14 18:17:03 +00:00
return new AxoManager (
$container -> get ( 'axo.url' ),
$container -> get ( 'ppcp.asset-version' ),
$container -> get ( 'session.handler' ),
$container -> get ( 'wcgateway.settings' ),
$container -> get ( 'onboarding.environment' ),
$container -> get ( 'wcgateway.settings.status' ),
2024-10-03 10:10:50 +03:00
$container -> get ( 'api.shop.currency.getter' ),
2024-05-14 13:51:20 +02:00
$container -> get ( 'woocommerce.logger.woocommerce' ),
$container -> get ( 'wcgateway.url' )
2024-02-14 18:17:03 +00:00
);
},
2024-09-03 15:05:23 +04:00
'axo.gateway' => static function ( ContainerInterface $container ) : AxoGateway {
2024-02-14 18:17:03 +00:00
return new AxoGateway (
2024-04-29 14:38:43 +02:00
$container -> get ( 'wcgateway.settings.render' ),
2024-02-16 17:31:59 +00:00
$container -> get ( 'wcgateway.settings' ),
2024-09-18 15:35:46 +02:00
$container -> get ( 'wcgateway.configuration.dcc' ),
2024-02-16 17:31:59 +00:00
$container -> get ( 'wcgateway.url' ),
2024-09-10 15:06:15 +02:00
$container -> get ( 'session.handler' ),
2024-04-10 15:51:19 +01:00
$container -> get ( 'wcgateway.order-processor' ),
2024-09-13 18:52:22 +02:00
$container -> get ( 'wcgateway.credit-card-icons' ),
2024-02-19 18:17:47 +00:00
$container -> get ( 'api.endpoint.order' ),
$container -> get ( 'api.factory.purchase-unit' ),
$container -> get ( 'api.factory.shipping-preference' ),
$container -> get ( 'wcgateway.transaction-url-provider' ),
$container -> get ( 'onboarding.environment' ),
$container -> get ( 'woocommerce.logger.woocommerce' )
2024-02-16 17:31:59 +00:00
);
},
2024-03-25 10:28:15 +00:00
/**
* The matrix which countries and currency combinations can be used for AXO .
*/
2024-09-03 15:05:23 +04:00
'axo.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
2024-03-25 10:28:15 +00:00
/**
* Returns which countries and currency combinations can be used for AXO .
*/
return apply_filters (
'woocommerce_paypal_payments_axo_supported_country_currency_matrix' ,
array (
'US' => array (
2024-06-10 11:29:08 +02:00
'AUD' ,
'CAD' ,
'EUR' ,
'GBP' ,
'JPY' ,
2024-06-10 11:41:57 +02:00
'USD' ,
2024-03-25 10:28:15 +00:00
),
)
);
},
2024-09-03 15:05:23 +04:00
'axo.settings-conflict-notice' => static function ( ContainerInterface $container ) : string {
2024-07-31 14:04:48 +02:00
$settings_notice_generator = $container -> get ( 'axo.helpers.settings-notice-generator' );
assert ( $settings_notice_generator instanceof SettingsNoticeGenerator );
$settings = $container -> get ( 'wcgateway.settings' );
assert ( $settings instanceof Settings );
return $settings_notice_generator -> generate_settings_conflict_notice ( $settings );
},
2024-09-03 15:05:23 +04:00
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
2024-07-18 00:27:35 +02:00
$settings_notice_generator = $container -> get ( 'axo.helpers.settings-notice-generator' );
assert ( $settings_notice_generator instanceof SettingsNoticeGenerator );
2024-05-10 02:07:51 +02:00
2024-07-18 00:27:35 +02:00
return $settings_notice_generator -> generate_checkout_notice ();
},
2024-05-10 02:07:51 +02:00
2024-09-03 15:05:23 +04:00
'axo.incompatible-plugins-notice' => static function ( ContainerInterface $container ) : string {
2024-07-25 00:18:15 +02:00
$settings_notice_generator = $container -> get ( 'axo.helpers.settings-notice-generator' );
assert ( $settings_notice_generator instanceof SettingsNoticeGenerator );
return $settings_notice_generator -> generate_incompatible_plugins_notice ();
},
2024-09-03 15:05:23 +04:00
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
2024-09-26 18:44:25 +02:00
$dcc_configuration = $container -> get ( 'wcgateway.configuration.dcc' );
assert ( $dcc_configuration instanceof DCCGatewayConfiguration );
2024-05-15 14:42:40 +02:00
2024-09-26 18:44:25 +02:00
if ( $dcc_configuration -> use_fastlane () ) {
2024-05-15 14:42:40 +02:00
$fastlane_settings_url = admin_url (
sprintf (
'admin.php?page=wc-settings&tab=checkout§ion=%1$s&ppcp-tab=%2$s#field-axo_heading' ,
PayPalGateway :: ID ,
CreditCardGateway :: ID
)
);
$notice_content = sprintf (
/* translators: %1$s: URL to the Checkout edit page. */
__ (
'<span class="highlight">Important:</span> The <code>Cart</code> & <code>Classic Cart</code> <strong>Smart Button Locations</strong> cannot be disabled while <a href="%1$s">Fastlane</a> is active.' ,
'woocommerce-paypal-payments'
),
esc_url ( $fastlane_settings_url )
);
} else {
return '' ;
}
2024-05-16 23:59:03 +02:00
return '<div class="ppcp-notice ppcp-notice-warning"><p>' . $notice_content . '</p></div>' ;
2024-05-15 14:42:40 +02:00
},
2024-07-17 19:06:40 +02:00
2024-09-03 15:05:23 +04:00
'axo.endpoint.frontend-logger' => static function ( ContainerInterface $container ) : FrontendLoggerEndpoint {
2024-05-24 17:13:43 +02:00
return new FrontendLoggerEndpoint (
$container -> get ( 'button.request-data' ),
$container -> get ( 'woocommerce.logger.woocommerce' )
);
},
2024-09-03 15:05:23 +04:00
/**
* The list of Fastlane incompatible plugins .
*
2024-09-03 16:35:58 +04:00
* @ returns array < array { name : string , is_active : bool } >
2024-09-03 15:05:23 +04:00
*/
'axo.fastlane-incompatible-plugins' => static function () : array {
/**
* Filters the list of Fastlane incompatible plugins .
*/
return apply_filters (
'woocommerce_paypal_payments_fastlane_incompatible_plugins' ,
array (
array (
2024-09-03 16:35:58 +04:00
'name' => 'Elementor' ,
'is_active' => did_action ( 'elementor/loaded' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'CheckoutWC' ,
'is_active' => defined ( 'CFW_NAME' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'Direct Checkout for WooCommerce' ,
'is_active' => defined ( 'QLWCDC_PLUGIN_NAME' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'Multi-Step Checkout for WooCommerce' ,
'is_active' => class_exists ( 'WPMultiStepCheckout' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'Fluid Checkout for WooCommerce' ,
'is_active' => class_exists ( 'FluidCheckout' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'MultiStep Checkout for WooCommerce' ,
'is_active' => class_exists ( 'THWMSCF_Multistep_Checkout' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'WooCommerce Subscriptions' ,
'is_active' => class_exists ( 'WC_Subscriptions' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'CartFlows' ,
'is_active' => class_exists ( 'Cartflows_Loader' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'FunnelKit Funnel Builder' ,
'is_active' => class_exists ( 'WFFN_Core' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'WooCommerce One Page Checkout' ,
'is_active' => class_exists ( 'PP_One_Page_Checkout' ),
2024-09-03 15:05:23 +04:00
),
array (
2024-09-03 16:35:58 +04:00
'name' => 'All Products for Woo Subscriptions' ,
'is_active' => class_exists ( 'WCS_ATT' ),
2024-09-03 15:05:23 +04:00
),
)
);
},
'axo.fastlane-incompatible-plugin-names' => static function ( ContainerInterface $container ) : array {
$incompatible_plugins = $container -> get ( 'axo.fastlane-incompatible-plugins' );
$active_plugins_list = array_filter (
$incompatible_plugins ,
2024-09-03 15:19:38 +04:00
function ( array $plugin ) : bool {
2024-09-03 16:35:58 +04:00
return ( bool ) $plugin [ 'is_active' ];
2024-09-03 15:05:23 +04:00
}
);
if ( empty ( $active_plugins_list ) ) {
2024-09-03 15:05:58 +04:00
return array ();
2024-09-03 15:05:23 +04:00
}
return array_map (
function ( array $plugin ) : string {
return " <li> { $plugin [ 'name' ] } </li> " ;
},
$active_plugins_list
);
},
2024-02-06 12:01:38 +00:00
);