only change Modules in run that are to early for translations and use plugins_loaded again

This commit is contained in:
Daniel Hüsken 2024-11-25 15:39:38 +01:00
parent 622913f384
commit 4dcabc5e67
No known key found for this signature in database
GPG key ID: 9F732DA37FA709E8
16 changed files with 353 additions and 290 deletions

View file

@ -46,12 +46,6 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
return true;
}
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
if ( ! $dcc_configuration->is_enabled() ) {
return true;
}
/**
* Param types removed to avoid third-party issues.
*
@ -59,7 +53,10 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
*/
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
function( $components ) {
function( $components ) use ( $c ) {
if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
return $components;
}
if ( in_array( 'hosted-fields', $components, true ) ) {
$key = array_search( 'hosted-fields', $components, true );
if ( $key !== false ) {
@ -80,7 +77,10 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MissingClosureParamType
*/
function( $default_fields, $id ) {
function( $default_fields, $id ) use ( $c ) {
if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
return $default_fields;
}
if ( CreditCardGateway::ID === $id && apply_filters( 'woocommerce_paypal_payments_enable_cardholder_name_field', false ) ) {
$default_fields['card-name-field'] = '<p class="form-row form-row-wide">
<label for="ppcp-credit-card-gateway-card-name">' . esc_attr__( 'Cardholder Name', 'woocommerce-paypal-payments' ) . '</label>
@ -113,6 +113,9 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
add_filter(
'ppcp_create_order_request_body_data',
function( array $data, string $payment_method ) use ( $c ): array {
if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
return $data;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( $payment_method !== CreditCardGateway::ID ) {
return $data;

View file

@ -51,14 +51,24 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
*/
public function run( ContainerInterface $c ): bool {
add_action(
'woocommerce_init',
function() use ( $c ) {
$this->initialize_ppec_compat_layer( $c );
$this->initialize_tracking_compat_layer( $c );
}
);
add_action(
'init',
function() use ( $c ) {
$asset_loader = $c->get( 'compat.assets' );
assert( $asset_loader instanceof CompatAssets );
add_action( 'init', array( $asset_loader, 'register' ) );
$asset_loader->register();
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
}
);
$this->migrate_pay_later_settings( $c );
$this->migrate_smart_button_settings( $c );
@ -72,11 +82,9 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
$this->initialize_nyp_compat_layer();
}
$logger = $c->get( 'woocommerce.logger.woocommerce' );
$is_wc_bookings_active = $c->get( 'compat.wc_bookings.is_supported_plugin_version_active' );
if ( $is_wc_bookings_active ) {
$this->initialize_wc_bookings_compat_layer( $logger );
$this->initialize_wc_bookings_compat_layer( $c );
}
return true;
@ -427,13 +435,13 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
/**
* Sets up the compatibility layer for WooCommerce Bookings plugin.
*
* @param LoggerInterface $logger The logger.
* @param ContainerInterface $container The logger.
* @return void
*/
protected function initialize_wc_bookings_compat_layer( LoggerInterface $logger ): void {
protected function initialize_wc_bookings_compat_layer( ContainerInterface $container ): void {
add_action(
'woocommerce_paypal_payments_shipping_callback_woocommerce_order_created',
static function ( WC_Order $wc_order, WC_Cart $wc_cart ) use ( $logger ): void {
static function ( WC_Order $wc_order, WC_Cart $wc_cart ) use ( $container ): void {
try {
$cart_contents = $wc_cart->get_cart();
foreach ( $cart_contents as $cart_item ) {
@ -474,7 +482,7 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
}
}
} catch ( Exception $exception ) {
$logger->warning( 'Failed to create booking for WooCommerce Bookings plugin: ' . $exception->getMessage() );
$container->get( 'woocommerce.logger.woocommerce' )->warning( 'Failed to create booking for WooCommerce Bookings plugin: ' . $exception->getMessage() );
}
},
10,

View file

@ -44,12 +44,6 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): bool {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
if ( ! self::should_add_local_apm_gateways( $settings ) ) {
return true;
}
add_filter(
'woocommerce_payment_gateways',
@ -59,6 +53,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function ( $methods ) use ( $c ) {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return $methods;
}
$onboarding_state = $c->get( 'onboarding.state' );
if ( $onboarding_state->current_state() === State::STATE_START ) {
return $methods;
@ -85,6 +82,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function ( $methods ) use ( $c ) {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return $methods;
}
if ( ! is_array( $methods ) ) {
return $methods;
}
@ -115,6 +115,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return;
}
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
foreach ( $payment_methods as $key => $value ) {
$payment_method_registry->register( $c->get( 'ppcp-local-apms.' . $key . '.payment-method' ) );
@ -125,6 +128,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_filter(
'woocommerce_paypal_payments_localized_script_data',
function ( array $data ) use ( $c ) {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return $data;
}
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
$default_disable_funding = $data['url_params']['disable-funding'] ?? '';
@ -143,6 +149,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function( $order_id ) use ( $c ) {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return;
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return;
@ -175,6 +184,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_action(
'woocommerce_paypal_payments_payment_capture_completed_webhook_handler',
function( WC_Order $wc_order, string $order_id ) use ( $c ) {
if ( ! self::should_add_local_apm_gateways( $c ) ) {
return;
}
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
if (
! $this->is_local_apm( $wc_order->get_payment_method(), $payment_methods )
@ -214,10 +226,12 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
/**
* Check if the local APMs should be added to the available payment gateways.
*
* @param Settings $settings PayPal gateway settings.
* @param ContainerInterface $container Container
* @return bool
*/
private function should_add_local_apm_gateways( Settings $settings ): bool {
private function should_add_local_apm_gateways( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
return $settings->has( 'enabled' )
&& $settings->get( 'enabled' ) === true
&& $settings->has( 'allow_local_apm_gateways' )

View file

@ -44,19 +44,13 @@ class OnboardingModule implements ServiceModule, ExtendingModule, ExecutableModu
*/
public function run( ContainerInterface $c ): bool {
$asset_loader = $c->get( 'onboarding.assets' );
/**
* The OnboardingAssets.
*
* @var OnboardingAssets $asset_loader
*/
add_action(
'admin_enqueue_scripts',
array(
$asset_loader,
'register',
)
);
function() use ( $c ) {
$asset_loader = $c->get( 'onboarding.assets' );
assert( $asset_loader instanceof OnboardingAssets );
$asset_loader->register();
add_action(
'woocommerce_settings_checkout',
array(
@ -64,6 +58,8 @@ class OnboardingModule implements ServiceModule, ExtendingModule, ExecutableModu
'enqueue',
)
);
}
);
add_filter(
'woocommerce_form_field',

View file

@ -55,23 +55,21 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
* @throws NotFoundException
*/
public function run( ContainerInterface $c ): bool {
$endpoint = $c->get( 'order-tracking.endpoint.controller' );
assert( $endpoint instanceof OrderTrackingEndpoint );
add_action( 'wc_ajax_' . OrderTrackingEndpoint::ENDPOINT, array( $endpoint, 'handle_request' ) );
add_action(
'wc_ajax_' . OrderTrackingEndpoint::ENDPOINT,
function() use ( $c ) {
$c->get( 'order-tracking.endpoint.controller' )->handle_request();
}
);
$asset_loader = $c->get( 'order-tracking.assets' );
assert( $asset_loader instanceof OrderEditPageAssets );
$logger = $c->get( 'woocommerce.logger.woocommerce' );
assert( $logger instanceof LoggerInterface );
$bearer = $c->get( 'api.bearer' );
add_action(
'init',
function() use ( $asset_loader, $bearer ) {
if ( ! $this->is_tracking_enabled( $bearer ) ) {
function() use ( $asset_loader, $c ) {
if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@ -80,8 +78,8 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
);
add_action(
'init',
function() use ( $asset_loader, $bearer ) {
if ( ! $this->is_tracking_enabled( $bearer ) ) {
function() use ( $asset_loader, $c ) {
if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@ -89,9 +87,6 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
}
);
$meta_box_renderer = $c->get( 'order-tracking.meta-box.renderer' );
assert( $meta_box_renderer instanceof MetaBoxRenderer );
add_action(
'add_meta_boxes',
/**
@ -103,8 +98,8 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
*
* @psalm-suppress MissingClosureParamType
*/
function( string $post_type, $post_or_order_object ) use ( $meta_box_renderer, $bearer ) {
if ( ! $this->is_tracking_enabled( $bearer ) ) {
function( string $post_type, $post_or_order_object ) use ( $c ) {
if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@ -135,6 +130,9 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
? wc_get_page_screen_id( 'shop-order' )
: 'shop_order';
$meta_box_renderer = $c->get( 'order-tracking.meta-box.renderer' );
assert( $meta_box_renderer instanceof MetaBoxRenderer );
add_meta_box(
'ppcp_order-tracking',
__( 'PayPal Package Tracking', 'woocommerce-paypal-payments' ),

View file

@ -71,12 +71,12 @@ class PayLaterBlockModule implements ServiceModule, ExtendingModule, ExecutableM
return true;
}
add_action(
'init',
function () use ( $c ): void {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
add_action(
'init',
function () use ( $c, $settings ): void {
$script_handle = 'ppcp-paylater-block';
wp_register_script(
$script_handle,

View file

@ -56,17 +56,20 @@ class PayLaterConfiguratorModule implements ServiceModule, ExtendingModule, Exec
* {@inheritDoc}
*/
public function run( ContainerInterface $c ) : bool {
$is_available = $c->get( 'paylater-configurator.is-available' );
add_action(
'init',
static function () use ( $c ) {
$is_available = $c->get( 'paylater-configurator.is-available' );
if ( ! $is_available ) {
return true;
return;
}
$current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
$is_wc_settings_page = $c->get( 'wcgateway.is-wc-settings-page' );
$messaging_locations = $c->get( 'paylater-configurator.messaging-locations' );
$this->add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id );
self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id );
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
@ -90,12 +93,9 @@ class PayLaterConfiguratorModule implements ServiceModule, ExtendingModule, Exec
);
if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) {
return true;
return;
}
add_action(
'init',
static function () use ( $c, $settings ) {
wp_enqueue_script(
'ppcp-paylater-configurator-lib',
'https://www.paypalobjects.com/merchant-library/merchant-configurator.js',
@ -165,7 +165,7 @@ class PayLaterConfiguratorModule implements ServiceModule, ExtendingModule, Exec
*
* @return void
*/
private function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void {
private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void {
// The message must be registered on any WC-Settings page, except for the Pay Later page.
if ( ! $is_settings_page || Settings::PAY_LATER_TAB_ID === $current_page_id ) {
return;

View file

@ -99,12 +99,11 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
return true;
}
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
add_action(
'init',
function () use ( $c, $settings ): void {
function () use ( $c ): void {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
$config_factory = $c->get( 'paylater-configurator.factory.config' );
assert( $config_factory instanceof ConfigFactory );
@ -186,12 +185,18 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
2
);
add_action(
'init',
function () use ( $c ): void {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
/**
* Cannot return false for this path.
*
* @psalm-suppress PossiblyFalseArgument
*/
if ( function_exists( 'register_block_type' ) ) {
register_block_type(
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CartPayLaterMessagesBlock',
array(
@ -205,14 +210,12 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
},
)
);
}
/**
* Cannot return false for this path.
*
* @psalm-suppress PossiblyFalseArgument
*/
if ( function_exists( 'register_block_type' ) ) {
register_block_type(
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
array(
@ -227,6 +230,7 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
)
);
}
);
// This is a fallback for the default Cart block that haven't been saved with the inserted Pay Later messaging block.
add_filter(
@ -271,7 +275,7 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
if ( self::is_under_cart_totals_placement_enabled() ) {
add_action(
'enqueue_block_editor_assets',
function () use ( $c, $settings ): void {
function () use ( $c ): void {
$handle = 'ppcp-checkout-paylater-block-editor-inserter';
$path = $c->get( 'paylater-wc-blocks.url' ) . 'assets/js/cart-paylater-block-inserter.js';

View file

@ -599,11 +599,11 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
}
);
$endpoint = $c->get( 'paypal-subscriptions.deactivate-plan-endpoint' );
assert( $endpoint instanceof DeactivatePlanEndpoint );
add_action(
'wc_ajax_' . DeactivatePlanEndpoint::ENDPOINT,
array( $endpoint, 'handle_request' )
function() use ( $c ) {
$c->get( 'paypal-subscriptions.deactivate-plan-endpoint' )->handle_request();
}
);
add_action(

View file

@ -63,33 +63,26 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
return true;
}
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update',
function() use ( $c ) {
$billing_agreements_endpoint = $c->get( 'api.endpoint.billing-agreements' );
assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );
add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update',
function() use ( $settings, $billing_agreements_endpoint ) {
$reference_transaction_enabled = $billing_agreements_endpoint->reference_transaction_enabled();
if ( $reference_transaction_enabled !== true ) {
$settings->set( 'vault_enabled', false );
$settings->persist();
$c->get( 'wcgateway.settings' )->set( 'vault_enabled', false );
$c->get( 'wcgateway.settings' )->persist();
}
}
);
if (
( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) )
&& ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) )
) {
return true;
}
add_filter(
'woocommerce_paypal_payments_localized_script_data',
function( array $localized_script_data ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return $localized_script_data;
}
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscriptions_helper instanceof SubscriptionHelper );
if ( ! is_user_logged_in() && ! $subscriptions_helper->cart_contains_subscription() ) {
@ -109,12 +102,11 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
// Adds attributes needed to save payment method.
add_filter(
'ppcp_create_order_request_body_data',
function( array $data, string $payment_method, array $request_data ) use ( $settings ): array {
if ( $payment_method === CreditCardGateway::ID ) {
if ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) ) {
function( array $data, string $payment_method, array $request_data ) use ( $c ): array {
if ( ! self::vault_enabled( $c ) ) {
return $data;
}
if ( $payment_method === CreditCardGateway::ID ) {
$save_payment_method = $request_data['save_payment_method'] ?? false;
if ( $save_payment_method ) {
$data['payment_source'] = array(
@ -141,10 +133,6 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
}
if ( $payment_method === PayPalGateway::ID ) {
if ( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) ) {
return $data;
}
$funding_source = $request_data['funding_source'] ?? null;
if ( $funding_source && $funding_source === 'venmo' ) {
@ -197,6 +185,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_paypal_payments_after_order_processor',
function( WC_Order $wc_order, Order $order ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return;
}
$payment_source = $order->payment_source();
assert( $payment_source instanceof PaymentSource );
@ -259,13 +250,30 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
2
);
add_filter( 'woocommerce_paypal_payments_disable_add_payment_method', '__return_false' );
add_filter( 'woocommerce_paypal_payments_should_render_card_custom_fields', '__return_false' );
add_filter(
'woocommerce_paypal_payments_disable_add_payment_method',
function ( $value ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return $value;
}
return fasle;
}
);
add_filter(
'woocommerce_paypal_payments_should_render_card_custom_fields',
function ( $value ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return $value;
}
return false;
}
);
add_action(
'wp_enqueue_scripts',
function() use ( $c ) {
if ( ! is_user_logged_in() || ! ( $this->is_add_payment_method_page() || $this->is_subscription_change_payment_method_page() ) ) {
if ( ! is_user_logged_in() || ! ( $this->is_add_payment_method_page() || $this->is_subscription_change_payment_method_page() ) || ! self::vault_enabled( $c ) ) {
return;
}
@ -355,8 +363,8 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_add_payment_method_form_bottom',
function () {
if ( ! is_user_logged_in() || ! is_add_payment_method_page() ) {
function () use ( $c ) {
if ( ! is_user_logged_in() || ! is_add_payment_method_page() || ! self::vault_enabled( $c ) ) {
return;
}
@ -367,6 +375,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreateSetupToken::ENDPOINT,
static function () use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return;
}
$endpoint = $c->get( 'save-payment-methods.endpoint.create-setup-token' );
assert( $endpoint instanceof CreateSetupToken );
@ -377,6 +388,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreatePaymentToken::ENDPOINT,
static function () use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return;
}
$endpoint = $c->get( 'save-payment-methods.endpoint.create-payment-token' );
assert( $endpoint instanceof CreatePaymentToken );
@ -387,6 +401,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreatePaymentTokenForGuest::ENDPOINT,
static function () use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return;
}
$endpoint = $c->get( 'save-payment-methods.endpoint.create-payment-token-for-guest' );
assert( $endpoint instanceof CreatePaymentTokenForGuest );
@ -397,6 +414,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_paypal_payments_before_delete_payment_token',
function( string $token_id ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return;
}
try {
$endpoint = $c->get( 'api.endpoint.payment-tokens' );
assert( $endpoint instanceof PaymentTokensEndpoint );
@ -419,13 +439,11 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_supports',
function( array $supports ) use ( $c ): array {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof ContainerInterface );
if ( $settings->has( 'vault_enabled_dcc' ) && $settings->get( 'vault_enabled_dcc' ) ) {
if ( ! self::vault_enabled( $c ) ) {
return $supports;
}
$supports[] = 'tokenization';
$supports[] = 'add_payment_method';
}
return $supports;
}
@ -433,7 +451,10 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_filter(
'woocommerce_paypal_payments_save_payment_methods_eligible',
function() {
function( $value ) use ( $c ) {
if ( ! self::vault_enabled( $c ) ) {
return $value;
}
return true;
}
);
@ -481,4 +502,24 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
return $localized_script_data;
}
/**
* Checks whether the vault functionality is enabled based on configuration settings.
*
* @param ContainerInterface $container The dependency injection container from which settings can be retrieved.
*
* @return bool Returns true if either 'vault_enabled' or 'vault_enabled_dcc' settings are enabled; otherwise, false.
*/
private static function vault_enabled( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
if (
( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) )
&& ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) )
) {
return false;
}
return true;
}
}

View file

@ -43,9 +43,13 @@ class UninstallModule implements ServiceModule, ExtendingModule, ExecutableModul
* {@inheritDoc}
*/
public function run( ContainerInterface $container ): bool {
add_action(
'init',
static function () use ( $container ) {
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
if ( Settings::CONNECTION_TAB_ID === $page_id ) {
$this->registerClearDatabaseAssets( $container->get( 'uninstall.clear-db-assets' ) );
$container->get( 'uninstall.clear-db-assets' )->register();
add_action( 'admin_enqueue_scripts', array( $container->get( 'uninstall.clear-db-assets' ), 'enqueue' ) );
}
$request_data = $container->get( 'button.request-data' );
@ -55,21 +59,13 @@ class UninstallModule implements ServiceModule, ExtendingModule, ExecutableModul
$scheduled_action_names = $container->get( 'uninstall.ppcp-all-scheduled-action-names' );
$action_names = $container->get( 'uninstall.ppcp-all-action-names' );
$this->handleClearDbAjaxRequest( $request_data, $clear_db, $clear_db_endpoint, $option_names, $scheduled_action_names, $action_names );
self::handleClearDbAjaxRequest( $request_data, $clear_db, $clear_db_endpoint, $option_names, $scheduled_action_names, $action_names );
}
);
return true;
}
/**
* Registers the assets for clear database functionality.
*
* @param ClearDatabaseAssets $asset_loader The clear database functionality asset loader.
*/
protected function registerClearDatabaseAssets( ClearDatabaseAssets $asset_loader ): void {
add_action( 'init', array( $asset_loader, 'register' ) );
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
}
/**
* Handles the AJAX request to clear the database.
*
@ -80,7 +76,7 @@ class UninstallModule implements ServiceModule, ExtendingModule, ExecutableModul
* @param string[] $scheduled_action_names The list of scheduled action names.
* @param string[] $action_names The list of action names.
*/
protected function handleClearDbAjaxRequest(
protected static function handleClearDbAjaxRequest(
RequestData $request_data,
ClearDatabaseInterface $clear_db,
string $nonce,

View file

@ -51,10 +51,16 @@ class VaultingModule implements ServiceModule, ExtendingModule, ExecutableModule
* @throws NotFoundException When service could not be found.
*/
public function run( ContainerInterface $container ): bool {
add_action(
'woocommerce_init',
function() use ( $container ) {
$listener = $container->get( 'vaulting.customer-approval-listener' );
assert( $listener instanceof CustomerApprovalListener );
$listener->listen();
}
);
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
add_action(

View file

@ -174,9 +174,6 @@ class SettingsPageAssets {
* @return void
*/
public function register_assets(): void {
add_action(
'admin_enqueue_scripts',
function() {
if ( ! is_admin() || wp_doing_ajax() ) {
return;
}
@ -189,9 +186,6 @@ class SettingsPageAssets {
$this->register_paypal_admin_assets();
}
}
);
}
/**
* Register assets for PayPal admin pages.

View file

@ -181,7 +181,15 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
}
);
if ( $c->has( 'wcgateway.url' ) ) {
add_action(
'admin_enqueue_scripts',
function () use ( $c ) {
if ( ! is_admin() || wp_doing_ajax() ) {
return;
}
if ( ! $c->has( 'wcgateway.url' ) ) {
return;
}
$settings_status = $c->get( 'wcgateway.settings.status' );
assert( $settings_status instanceof SettingsStatus );
@ -209,6 +217,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
);
$assets->register_assets();
}
);
add_filter(
Repository::NOTICES_FILTER,

View file

@ -56,8 +56,6 @@ class WebhookModule implements ServiceModule, FactoryModule, ExtendingModule, Ex
* {@inheritDoc}
*/
public function run( ContainerInterface $container ): bool {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
assert( $logger instanceof LoggerInterface );
add_action(
'rest_api_init',
@ -127,14 +125,17 @@ class WebhookModule implements ServiceModule, FactoryModule, ExtendingModule, Ex
}
);
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
if ( Settings::CONNECTION_TAB_ID === $page_id ) {
$asset_loader = $container->get( 'webhook.status.assets' );
assert( $asset_loader instanceof WebhooksStatusPageAssets );
add_action(
'init',
array( $asset_loader, 'register' )
);
function () use ( $container ) {
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
if ( Settings::CONNECTION_TAB_ID !== $page_id ) {
return;
}
$asset_loader = $container->get( 'webhook.status.assets' );
assert( $asset_loader instanceof WebhooksStatusPageAssets );
$asset_loader->register();
add_action(
'admin_enqueue_scripts',
array( $asset_loader, 'enqueue' )
@ -146,19 +147,13 @@ class WebhookModule implements ServiceModule, FactoryModule, ExtendingModule, Ex
if ( empty( $webhooks ) && $state->current_state() >= State::STATE_ONBOARDED ) {
$registrar = $container->get( 'webhook.registrar' );
assert( $registrar instanceof WebhookRegistrar );
// Looks like we cannot call rest_url too early.
add_action(
'init',
function () use ( $registrar ) {
$registrar->register();
}
);
}
} catch ( Exception $exception ) {
$logger->error( 'Failed to load webhooks list: ' . $exception->getMessage() );
$container->get( 'woocommerce.logger.woocommerce' )->error( 'Failed to load webhooks list: ' . $exception->getMessage() );
}
}
);
add_action(
'woocommerce_paypal_payments_gateway_migrate',

View file

@ -87,7 +87,7 @@ define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' );
}
add_action(
'init',
'plugins_loaded',
function () {
init();
@ -107,8 +107,7 @@ define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' );
}
update_option( 'woocommerce-ppcp-version', $current_plugin_version );
}
},
-1
}
);
register_activation_hook(
__FILE__,