mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
only change Modules in run that are to early for translations and use plugins_loaded again
This commit is contained in:
parent
622913f384
commit
4dcabc5e67
16 changed files with 353 additions and 290 deletions
|
@ -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' )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue