mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Extract common logic from hook callbacks
This commit is contained in:
parent
db0d419cf5
commit
705ffbdf17
1 changed files with 4 additions and 19 deletions
|
@ -43,6 +43,10 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
public function run( ContainerInterface $c ): bool {
|
||||
// When Local APMs are disabled, none of the following hooks are needed.
|
||||
if ( ! $this->should_add_local_apm_gateways( $c ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'woocommerce_payment_gateways',
|
||||
|
@ -52,10 +56,6 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
function ( $methods ) use ( $c ) {
|
||||
if ( ! self::should_add_local_apm_gateways( $c ) ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
$is_connected = $c->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return $methods;
|
||||
|
@ -82,9 +82,6 @@ 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,9 +112,6 @@ 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' ) );
|
||||
|
@ -128,9 +122,6 @@ 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'] ?? '';
|
||||
|
@ -149,9 +140,6 @@ 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;
|
||||
|
@ -184,9 +172,6 @@ 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 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue