Merge branch 'trunk' of github.com:woocommerce/woocommerce-paypal-payments into PCP-3783-fastlane-allow-merchants-to-disable-specific-card-types

This commit is contained in:
Daniel Dudzic 2024-11-12 15:03:35 +01:00
commit f3c32dbe6c
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
270 changed files with 48005 additions and 70038 deletions

View file

@ -11,20 +11,20 @@
],
"dependencies": {
"@paypal/paypal-js": "^6.0.0",
"core-js": "^3.25.0"
"core-js": "^3.39"
},
"devDependencies": {
"@babel/core": "^7.19",
"@babel/preset-env": "^7.19",
"@babel/preset-react": "^7.18.6",
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0",
"babel-loader": "^8.2",
"@babel/core": "^7.26",
"@babel/preset-env": "^7.26",
"@babel/preset-react": "^7.25",
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
"babel-loader": "^9.2",
"cross-env": "^7.0.3",
"file-loader": "^6.2.0",
"sass": "^1.42.1",
"sass-loader": "^12.1.0",
"webpack": "^5.76",
"webpack-cli": "^4.10"
"sass": "^1.80",
"sass-loader": "^16",
"webpack": "^5.96",
"webpack-cli": "^5"
},
"scripts": {
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",

View file

@ -87,6 +87,9 @@ class AxoManager {
this.cardOptions = this.getCardOptions();
this.enabledShippingLocations =
this.axoConfig.enabled_shipping_locations;
this.registerEventHandlers();
this.shippingView = new ShippingView(
@ -666,6 +669,9 @@ class AxoManager {
cardOptions: {
allowedBrands: this.cardOptions,
},
shippingAddressOptions: {
allowedLocations: this.enabledShippingLocations,
},
} );
this.fastlane.setLocale( 'en_us' );

View file

@ -68,7 +68,8 @@ return array(
$container->get( 'api.shop.currency.getter' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.url' ),
$container->get( 'axo.supported-country-card-type-matrix' )
$container->get( 'axo.supported-country-card-type-matrix' ),
$container->get( 'axo.shipping-wc-enabled-locations' )
);
},
@ -276,4 +277,46 @@ return array(
$active_plugins_list
);
},
'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ): array {
$default_zone = new \WC_Shipping_Zone( 0 );
$is_method_enabled = fn( \WC_Shipping_Method $method): bool => $method->enabled === 'yes';
$is_default_zone_enabled = ! empty(
array_filter(
$default_zone->get_shipping_methods(),
$is_method_enabled
)
);
if ( $is_default_zone_enabled ) {
return array();
}
$shipping_zones = \WC_Shipping_Zones::get_zones();
$get_zone_locations = fn( \WC_Shipping_Zone $zone): array =>
! empty( array_filter( $zone->get_shipping_methods(), $is_method_enabled ) )
? array_map(
fn( object $location): string => $location->code,
$zone->get_zone_locations()
)
: array();
$enabled_locations = array_unique(
array_merge(
...array_map(
$get_zone_locations,
array_map(
fn( $zone): \WC_Shipping_Zone =>
$zone instanceof \WC_Shipping_Zone ? $zone : new \WC_Shipping_Zone( $zone['id'] ),
$shipping_zones
)
)
)
);
return $enabled_locations;
},
);

View file

@ -92,6 +92,13 @@ class AxoManager {
* @var array
*/
private array $supported_country_card_type_matrix;
/**
* The list of WooCommerce enabled shipping locations.
*
* @var array
*/
private array $enabled_shipping_locations;
/**
* AxoManager constructor.
*
@ -105,6 +112,7 @@ class AxoManager {
* @param LoggerInterface $logger The logger.
* @param string $wcgateway_module_url The WcGateway module URL.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
*/
public function __construct(
string $module_url,
@ -116,7 +124,8 @@ class AxoManager {
CurrencyGetter $currency,
LoggerInterface $logger,
string $wcgateway_module_url,
array $supported_country_card_type_matrix
array $supported_country_card_type_matrix,
array $enabled_shipping_locations
) {
$this->module_url = $module_url;
@ -129,6 +138,7 @@ class AxoManager {
$this->logger = $logger;
$this->wcgateway_module_url = $wcgateway_module_url;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
$this->enabled_shipping_locations = $enabled_shipping_locations;
}
/**
@ -171,13 +181,13 @@ class AxoManager {
*/
private function script_data() {
return array(
'environment' => array(
'environment' => array(
'is_sandbox' => $this->environment->current_environment() === 'sandbox',
),
'widgets' => array(
'widgets' => array(
'email' => 'render',
),
'insights' => array(
'insights' => array(
'enabled' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'client_id' => ( $this->settings->has( 'client_id' ) ? $this->settings->get( 'client_id' ) : null ),
'session_id' =>
@ -193,7 +203,8 @@ class AxoManager {
),
'allowed_cards' => $this->supported_country_card_type_matrix,
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
'style_options' => array(
'enabled_shipping_locations' => $this->enabled_shipping_locations,
'style_options' => array(
'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
'errorColor' => $this->settings->has( 'axo_style_root_error_color' ) ? $this->settings->get( 'axo_style_root_error_color' ) : '',
@ -212,16 +223,16 @@ class AxoManager {
'focusBorderColor' => $this->settings->has( 'axo_style_input_focus_border_color' ) ? $this->settings->get( 'axo_style_input_focus_border_color' ) : '',
),
),
'name_on_card' => $this->settings->has( 'axo_name_on_card' ) ? $this->settings->get( 'axo_name_on_card' ) : '',
'woocommerce' => array(
'name_on_card' => $this->settings->has( 'axo_name_on_card' ) ? $this->settings->get( 'axo_name_on_card' ) : '',
'woocommerce' => array(
'states' => array(
'US' => WC()->countries->get_states( 'US' ),
'CA' => WC()->countries->get_states( 'CA' ),
),
),
'icons_directory' => esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/',
'module_url' => untrailingslashit( $this->module_url ),
'ajax' => array(
'icons_directory' => esc_url( $this->wcgateway_module_url ) . 'assets/images/axo/',
'module_url' => untrailingslashit( $this->module_url ),
'ajax' => array(
'frontend_logger' => array(
'endpoint' => \WC_AJAX::get_endpoint( FrontendLoggerEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( FrontendLoggerEndpoint::nonce() ),

View file

@ -222,8 +222,10 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
// Render submit button.
add_action(
$manager->checkout_button_renderer_hook(),
static function () use ( $c, $manager ) {
$manager->render_checkout_button();
static function () use ( $c, $manager, $module ) {
if ( $module->should_render_fastlane( $c ) ) {
$manager->render_checkout_button();
}
}
);

File diff suppressed because it is too large Load diff