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-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 ;
2024-05-10 02:07:51 +02:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector ;
2024-05-15 14:42:40 +02:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings ;
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.
'axo.eligible' => static function ( ContainerInterface $container ) : bool {
$apm_applies = $container -> get ( 'axo.helpers.apm-applies' );
assert ( $apm_applies instanceof ApmApplies );
2024-04-11 12:03:31 +01:00
return $apm_applies -> for_country_currency () && $apm_applies -> for_settings ();
2024-03-25 10:28:15 +00:00
},
'axo.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
return new ApmApplies (
$container -> get ( 'axo.supported-country-currency-matrix' ),
$container -> get ( 'api.shop.currency' ),
$container -> get ( 'api.shop.country' )
);
},
// If AXO is configured and onboarded.
'axo.available' => static function ( ContainerInterface $container ) : bool {
return true ;
},
2024-04-11 18:07:20 +01: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-04-11 18:07:20 +01: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' ),
$container -> get ( 'api.shop.currency' ),
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-04-11 18:07:20 +01: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' ),
$container -> get ( 'wcgateway.url' ),
2024-04-10 15:51:19 +01:00
$container -> get ( 'wcgateway.order-processor' ),
2024-02-19 18:17:47 +00:00
$container -> get ( 'axo.card_icons' ),
2024-05-06 15:22:49 +02:00
$container -> get ( 'axo.card_icons.axo' ),
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-04-11 18:07:20 +01:00
'axo.card_icons' => static function ( ContainerInterface $container ) : array {
2024-02-16 17:31:59 +00:00
return array (
2024-02-19 14:48:02 +00:00
array (
'title' => 'Visa' ,
'file' => 'visa-dark.svg' ,
),
array (
'title' => 'MasterCard' ,
'file' => 'mastercard-dark.svg' ,
),
array (
'title' => 'American Express' ,
'file' => 'amex.svg' ,
),
array (
'title' => 'Discover' ,
'file' => 'discover.svg' ,
),
2024-02-14 18:17:03 +00:00
);
},
2024-05-06 15:22:49 +02:00
'axo.card_icons.axo' => static function ( ContainerInterface $container ) : array {
return array (
array (
2024-05-10 00:55:28 +02:00
'title' => 'Visa' ,
'file' => 'visa-light.svg' ,
),
array (
'title' => 'MasterCard' ,
'file' => 'mastercard-light.svg' ,
),
array (
'title' => 'Amex' ,
'file' => 'amex-light.svg' ,
2024-05-06 15:22:49 +02:00
),
array (
'title' => 'Discover' ,
'file' => 'discover-light.svg' ,
),
array (
2024-05-10 00:55:28 +02:00
'title' => 'Diners Club' ,
'file' => 'dinersclub-light.svg' ,
2024-05-06 15:22:49 +02:00
),
array (
2024-05-10 00:55:28 +02:00
'title' => 'JCB' ,
'file' => 'jcb-light.svg' ,
2024-05-06 15:22:49 +02:00
),
array (
'title' => 'UnionPay' ,
'file' => 'unionpay-light.svg' ,
),
);
},
2024-03-25 10:28:15 +00:00
/**
* The matrix which countries and currency combinations can be used for AXO .
*/
'axo.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
/**
* 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 (
'USD' ,
),
)
);
},
2024-05-10 02:07:51 +02:00
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
2024-05-13 17:22:33 +02:00
$checkout_page_link = esc_url ( get_edit_post_link ( wc_get_page_id ( 'checkout' ) ) ? ? '' );
$block_checkout_docs_link = __ (
'https://woocommerce.com/document/cart-checkout-blocks-status/#reverting-to-the-cart-and-checkout-shortcodes' ,
'woocommerce-paypal-payments'
);
2024-05-10 02:07:51 +02:00
if ( CartCheckoutDetector :: has_elementor_checkout () ) {
$notice_content = sprintf (
2024-05-13 17:22:33 +02:00
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
2024-05-10 02:07:51 +02:00
__ (
2024-05-13 17:22:33 +02:00
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store currently uses the <code>Elementor Checkout widget</code>. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.' ,
2024-05-10 02:07:51 +02:00
'woocommerce-paypal-payments'
),
2024-05-13 17:22:33 +02:00
esc_url ( $checkout_page_link ),
esc_url ( $block_checkout_docs_link )
2024-05-10 02:07:51 +02:00
);
} elseif ( CartCheckoutDetector :: has_block_checkout () ) {
$notice_content = sprintf (
2024-05-13 17:22:33 +02:00
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
__ (
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store currently uses the WooCommerce <code>Checkout</code> block. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.' ,
'woocommerce-paypal-payments'
),
esc_url ( $checkout_page_link ),
esc_url ( $block_checkout_docs_link )
);
} elseif ( ! CartCheckoutDetector :: has_classic_checkout () ) {
$notice_content = sprintf (
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
2024-05-10 02:07:51 +02:00
__ (
2024-05-13 17:22:33 +02:00
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store does not seem to be properly configured or uses an incompatible <code>third-party Checkout</code> solution. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.' ,
2024-05-10 02:07:51 +02:00
'woocommerce-paypal-payments'
),
2024-05-13 17:22:33 +02:00
esc_url ( $checkout_page_link ),
esc_url ( $block_checkout_docs_link )
2024-05-10 02:07:51 +02:00
);
} else {
return '' ;
}
2024-05-16 23:59:03 +02:00
return '<div class="ppcp-notice ppcp-notice-error"><p>' . $notice_content . '</p></div>' ;
2024-05-10 02:07:51 +02:00
},
2024-05-15 14:42:40 +02:00
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
$settings = $container -> get ( 'wcgateway.settings' );
assert ( $settings instanceof Settings );
if ( $settings -> has ( 'axo_enabled' ) && $settings -> get ( 'axo_enabled' ) ) {
$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-05-27 13:04:14 +02: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-02-06 12:01:38 +00:00
);