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 ;
2025-07-17 16:44:25 +02:00
use WooCommerce\PayPalCommerce\Axo\Endpoint\AxoScriptAttributes ;
use WooCommerce\PayPalCommerce\Axo\Endpoint\FrontendLogger ;
2024-02-14 18:17:03 +00:00
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway ;
2025-07-18 13:56:37 +02:00
use WooCommerce\PayPalCommerce\Axo\Service\AxoApplies ;
2025-03-10 23:57:08 +01:00
use WooCommerce\PayPalCommerce\Axo\Helper\CompatibilityChecker ;
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 ;
2025-03-14 16:15:23 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\CardPaymentsConfiguration ;
2024-10-29 11:04:41 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter ;
2024-02-08 14:37:56 +00:00
2024-02-06 12:01:38 +00:00
return array (
2025-03-25 21:36:44 +01:00
// @deprecated - use `axo.eligibility.check` instead.
2024-09-03 15:05:23 +04:00
'axo.eligible' => static function ( ContainerInterface $container ) : bool {
2025-03-25 21:36:44 +01:00
$eligibility_check = $container -> get ( 'axo.eligibility.check' );
2024-03-25 10:28:15 +00:00
2025-03-25 21:36:44 +01:00
return $eligibility_check ();
2024-03-25 10:28:15 +00:00
},
2025-03-25 21:21:44 +01:00
'axo.eligibility.check' => static function ( ContainerInterface $container ) : callable {
2025-07-18 15:18:39 +02:00
$axo_applies = $container -> get ( 'axo.service.axo-applies' );
assert ( $axo_applies instanceof AxoApplies );
2024-03-25 10:28:15 +00:00
2025-08-22 17:00:32 +02:00
return static function () use ( $axo_applies ) : bool {
2025-07-18 15:18:39 +02:00
return $axo_applies -> for_country_currency () && $axo_applies -> for_merchant ();
2025-03-25 21:21:44 +01:00
};
},
2025-08-22 17:00:32 +02:00
'axo.service.axo-applies' => static function ( ContainerInterface $container ) : AxoApplies {
2025-07-18 13:56:37 +02:00
return new AxoApplies (
2024-03-25 10:28:15 +00:00
$container -> get ( 'axo.supported-country-currency-matrix' ),
2024-10-03 10:10:50 +03:00
$container -> get ( 'api.shop.currency.getter' ),
2025-07-18 13:56:37 +02:00
$container -> get ( 'api.shop.country' ),
$container -> get ( 'wcgateway.configuration.card-configuration' ),
$container -> get ( 'wc-subscriptions.helper' )
2024-03-25 10:28:15 +00:00
);
},
2025-08-22 17:00:32 +02:00
'axo.helpers.compatibility-checker' => static function ( ContainerInterface $container ) : CompatibilityChecker {
2025-03-14 11:13:44 +01:00
return new CompatibilityChecker (
$container -> get ( 'axo.fastlane-incompatible-plugin-names' ),
2025-03-14 12:17:15 +01:00
$container -> get ( 'wcgateway.configuration.card-configuration' )
2025-03-14 11:13:44 +01:00
);
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-12-12 16:03:32 +01:00
$settings = $container -> get ( 'wcgateway.settings' );
assert ( $settings instanceof Settings );
return $settings -> has ( 'axo_enabled' ) && $settings -> get ( 'axo_enabled' );
2024-03-25 10:28:15 +00:00
},
2024-09-03 15:05:23 +04:00
'axo.url' => static function ( ContainerInterface $container ) : string {
2025-07-04 19:27:13 +04:00
return plugins_url ( '/modules/ppcp-axo/' , $container -> get ( 'ppcp.path-to-plugin-main-file' ) );
2024-02-08 14:37:56 +00:00
},
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' ),
2025-02-17 18:48:38 +01:00
$container -> get ( 'settings.environment' ),
2024-10-29 11:04:41 +01:00
$container -> get ( 'axo.insights' ),
2024-02-14 18:17:03 +00:00
$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' ),
2024-10-17 23:56:03 +02:00
$container -> get ( 'wcgateway.url' ),
2024-11-27 12:18:28 +01:00
$container -> get ( 'axo.supported-country-card-type-matrix' )
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' ),
2025-03-14 12:17:15 +01:00
$container -> get ( 'wcgateway.configuration.card-configuration' ),
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' ),
2025-02-17 18:48:38 +01:00
$container -> get ( 'settings.environment' ),
2025-07-07 01:58:35 +02:00
$container -> get ( 'woocommerce.logger.woocommerce' ),
$container -> get ( 'wcgateway.builder.experience-context' ),
$container -> get ( 'settings.data.settings' )
2024-02-16 17:31:59 +00:00
);
},
2024-10-29 11:04:41 +01:00
// Data needed for the PayPal Insights.
'axo.insights' => static function ( ContainerInterface $container ) : array {
$settings = $container -> get ( 'wcgateway.settings' );
assert ( $settings instanceof Settings );
$currency = $container -> get ( 'api.shop.currency.getter' );
assert ( $currency instanceof CurrencyGetter );
2024-11-18 20:01:00 +01:00
$session_id = '' ;
if ( isset ( WC () -> session ) && method_exists ( WC () -> session , 'get_customer_unique_id' ) ) {
$session_id = substr (
md5 ( WC () -> session -> get_customer_unique_id () ),
0 ,
16
);
}
2024-10-29 11:04:41 +01:00
return array (
'enabled' => defined ( 'WP_DEBUG' ) && WP_DEBUG ,
'client_id' => ( $settings -> has ( 'client_id' ) ? $settings -> get ( 'client_id' ) : null ),
2024-11-18 20:01:00 +01:00
'session_id' => $session_id ,
2024-10-29 11:04:41 +01:00
'amount' => array (
'currency_code' => $currency -> get (),
),
'payment_method_selected_map' => $container -> get ( 'axo.payment_method_selected_map' ),
'wp_debug' => defined ( 'WP_DEBUG' ) && WP_DEBUG ,
);
},
// The mapping of payment methods to the PayPal Insights 'payment_method_selected' types.
'axo.payment_method_selected_map' => static function ( ContainerInterface $container ) : array {
return array (
'ppcp-axo-gateway' => 'card' ,
'ppcp-credit-card-gateway' => 'card' ,
'ppcp-gateway' => 'paypal' ,
'ppcp-googlepay' => 'google_pay' ,
'ppcp-applepay' => 'apple_pay' ,
'ppcp-multibanco' => 'other' ,
'ppcp-trustly' => 'other' ,
'ppcp-p24' => 'other' ,
'ppcp-mybank' => 'other' ,
'ppcp-ideal' => 'other' ,
'ppcp-eps' => 'other' ,
'ppcp-blik' => 'other' ,
'ppcp-bancontact' => 'other' ,
'ppcp-card-button-gateway' => 'card' ,
);
},
2024-03-25 10:28:15 +00:00
/**
* The matrix which countries and currency combinations can be used for AXO .
*/
2025-08-22 17:00:32 +02:00
'axo.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
2025-04-16 12:01:23 +02:00
$matrix = array (
'US' => array (
'AUD' ,
'CAD' ,
'EUR' ,
'GBP' ,
'JPY' ,
'USD' ,
),
);
2025-04-17 14:00:51 +02:00
if ( $container -> get ( 'axo.uk.enabled' ) ) {
$matrix [ 'GB' ] = array ( 'GBP' );
2025-04-16 12:01:23 +02:00
}
2025-08-12 17:03:19 +02:00
if ( $container -> get ( 'axo.au.enabled' ) ) {
$matrix [ 'AU' ] = array ( 'AUD' );
}
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' ,
2025-04-16 12:01:23 +02:00
$matrix
2024-03-25 10:28:15 +00:00
);
},
2024-10-16 12:51:26 +02:00
/**
* The matrix which countries and card type combinations can be used for AXO .
*/
2025-08-22 17:00:32 +02:00
'axo.supported-country-card-type-matrix' => static function ( ContainerInterface $container ) : array {
2025-04-16 12:01:23 +02:00
$matrix = array (
'US' => array (
'VISA' ,
'MASTERCARD' ,
'AMEX' ,
'DISCOVER' ,
),
'CA' => array (
'VISA' ,
'MASTERCARD' ,
'AMEX' ,
'DISCOVER' ,
),
);
2025-04-17 14:00:51 +02:00
if ( $container -> get ( 'axo.uk.enabled' ) ) {
2025-04-16 12:01:23 +02:00
$matrix [ 'GB' ] = array (
'VISA' ,
'MASTERCARD' ,
'AMEX' ,
'DISCOVER' ,
);
}
2025-08-12 17:03:19 +02:00
if ( $container -> get ( 'axo.au.enabled' ) ) {
$matrix [ 'AU' ] = array (
'VISA' ,
'MASTERCARD' ,
'AMEX' ,
);
}
2024-10-16 12:51:26 +02:00
/**
* Returns which countries and card type combinations can be used for AXO .
*/
return apply_filters (
'woocommerce_paypal_payments_axo_supported_country_card_type_matrix' ,
2025-04-16 12:01:23 +02:00
$matrix
2024-10-16 12:51:26 +02:00
);
},
2025-08-22 17:00:32 +02:00
'axo.settings-conflict-notice' => static function ( ContainerInterface $container ) : string {
2025-03-10 23:57:08 +01:00
$compatibility_checker = $container -> get ( 'axo.helpers.compatibility-checker' );
assert ( $compatibility_checker instanceof CompatibilityChecker );
2024-07-31 14:04:48 +02:00
2025-03-14 11:42:41 +01:00
return $compatibility_checker -> generate_settings_conflict_notice ();
2024-07-31 14:04:48 +02:00
},
2025-08-22 17:00:32 +02:00
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
2025-03-10 23:57:08 +01:00
$compatibility_checker = $container -> get ( 'axo.helpers.compatibility-checker' );
assert ( $compatibility_checker instanceof CompatibilityChecker );
2024-05-10 02:07:51 +02:00
2025-03-10 23:57:08 +01:00
return $compatibility_checker -> generate_checkout_notice ();
2024-07-18 00:27:35 +02:00
},
2024-05-10 02:07:51 +02:00
2025-08-22 17:00:32 +02:00
'axo.checkout-config-notice.raw' => static function ( ContainerInterface $container ) : string {
2025-03-10 23:57:08 +01:00
$compatibility_checker = $container -> get ( 'axo.helpers.compatibility-checker' );
assert ( $compatibility_checker instanceof CompatibilityChecker );
2025-02-25 16:27:33 +01:00
2025-03-10 23:57:08 +01:00
return $compatibility_checker -> generate_checkout_notice ( true );
2025-02-25 16:27:33 +01:00
},
2025-08-22 17:00:32 +02:00
'axo.incompatible-plugins-notice' => static function ( ContainerInterface $container ) : string {
2025-03-10 23:57:08 +01:00
$settings_notice_generator = $container -> get ( 'axo.helpers.compatibility-checker' );
assert ( $settings_notice_generator instanceof CompatibilityChecker );
2024-07-25 00:18:15 +02:00
return $settings_notice_generator -> generate_incompatible_plugins_notice ();
},
2025-08-22 17:00:32 +02:00
'axo.incompatible-plugins-notice.raw' => static function ( ContainerInterface $container ) : string {
2025-03-14 11:13:44 +01:00
$settings_notice_generator = $container -> get ( 'axo.helpers.compatibility-checker' );
assert ( $settings_notice_generator instanceof CompatibilityChecker );
2025-02-25 16:27:33 +01:00
return $settings_notice_generator -> generate_incompatible_plugins_notice ( true );
},
2025-08-22 17:00:32 +02:00
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
2025-03-14 12:17:15 +01:00
$dcc_configuration = $container -> get ( 'wcgateway.configuration.card-configuration' );
2025-03-14 16:15:23 +01:00
assert ( $dcc_configuration instanceof CardPaymentsConfiguration );
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
2025-07-17 16:44:25 +02:00
'axo.endpoint.frontend-logger' => static function ( ContainerInterface $container ) : FrontendLogger {
return new FrontendLogger (
2024-05-24 17:13:43 +02:00
$container -> get ( 'button.request-data' ),
$container -> get ( 'woocommerce.logger.woocommerce' )
);
},
2024-09-03 15:05:23 +04:00
2025-07-17 16:44:25 +02:00
'axo.endpoint.script-attributes' => static function ( ContainerInterface $container ) : AxoScriptAttributes {
return new AxoScriptAttributes (
2024-05-24 17:13:43 +02:00
$container -> get ( 'button.request-data' ),
2025-07-17 17:36:06 +02:00
$container -> get ( 'woocommerce.logger.woocommerce' ),
2025-07-18 13:56:37 +02:00
$container -> get ( 'api.sdk-client-token' ),
$container -> get ( 'axo.eligible' )
2024-05-24 17:13:43 +02:00
);
},
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
*/
2025-08-22 17:00:32 +02:00
'axo.fastlane-incompatible-plugins' => static function () : array {
2024-09-03 15:05:23 +04:00
/**
* 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
),
)
);
},
2025-08-22 17:00:32 +02:00
'axo.fastlane-incompatible-plugin-names' => static function ( ContainerInterface $container ) : array {
2024-09-03 15:05:23 +04:00
$incompatible_plugins = $container -> get ( 'axo.fastlane-incompatible-plugins' );
$active_plugins_list = array_filter (
$incompatible_plugins ,
2025-08-22 17:00:32 +02: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-10-17 23:56:03 +02:00
2024-11-27 12:18:28 +01:00
'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ) {
2024-10-17 23:56:03 +02:00
$default_zone = new \WC_Shipping_Zone ( 0 );
2024-11-27 12:18:28 +01:00
if ( ! empty ( $default_zone -> get_shipping_methods ( true ) ) ) {
2024-10-17 23:56:03 +02:00
return array ();
}
$shipping_zones = \WC_Shipping_Zones :: get_zones ();
2025-08-22 17:00:32 +02:00
$get_zone_locations = fn ( \WC_Shipping_Zone $zone ) : array =>
2024-11-27 12:18:28 +01:00
! empty ( $zone -> get_shipping_methods ( true ) )
2024-10-17 23:56:03 +02:00
? array_map (
2025-08-22 17:00:32 +02:00
fn ( object $location ) : string => $location -> code ,
2024-10-18 10:44:02 +02:00
$zone -> get_zone_locations ()
)
: array ();
2024-10-17 23:56:03 +02:00
2024-11-27 12:18:28 +01:00
return array_unique (
2024-10-17 23:56:03 +02:00
array_merge (
... array_map (
$get_zone_locations ,
array_map (
2025-08-22 17:00:32 +02:00
fn ( $zone ) : \WC_Shipping_Zone =>
2024-10-18 10:44:02 +02:00
$zone instanceof \WC_Shipping_Zone ? $zone : new \WC_Shipping_Zone ( $zone [ 'id' ] ),
2024-10-17 23:56:03 +02:00
$shipping_zones
)
)
)
);
},
2025-04-17 14:00:51 +02:00
'axo.uk.enabled' => static function ( ContainerInterface $container ) : bool {
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
/**
* Filter to determine if Fastlane UK with 3 D Secure should be enabled .
*
* @ param bool $enabled Whether Fastlane UK is enabled .
*/
return apply_filters (
'woocommerce.feature-flags.woocommerce_paypal_payments.axo_uk_enabled' ,
getenv ( 'PCP_AXO_UK_ENABLED' ) !== '0'
);
// phpcs:enable WordPress.NamingConventions.ValidHookName.UseUnderscores
},
2025-08-12 17:03:19 +02:00
'axo.au.enabled' => static function ( ContainerInterface $container ) : bool {
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
/**
2025-08-12 20:09:56 +02:00
* Filter to determine if Fastlane AU should be enabled .
2025-08-12 17:03:19 +02:00
*
2025-08-12 20:09:56 +02:00
* @ param bool $enabled Whether Fastlane AU is enabled .
2025-08-12 17:03:19 +02:00
*/
return apply_filters (
'woocommerce.feature-flags.woocommerce_paypal_payments.axo_au_enabled' ,
getenv ( 'PCP_AXO_AU_ENABLED' ) !== '0'
);
// phpcs:enable WordPress.NamingConventions.ValidHookName.UseUnderscores
},
2024-02-06 12:01:38 +00:00
);