diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index d293009c..dace21ab 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -74,6 +74,23 @@ public function run(ContainerInterface $container): bool [$this, 'maybeDisableBankTransferGateway'], 20 ); + // Add subscription filters after payment gateways are loaded + add_filter( + 'woocommerce_payment_gateways', + static function ($gateways) use ($container) { + $deprecatedGatewayHelpers = $container->get('__deprecated.gateway_helpers'); + + foreach ($gateways as $gateway) { + $isMolliegateway = strpos($gateway, 'mollie_wc_gateway_') !== false; + $isSubscriptiongateway = $gateway->supports('subscriptions'); + if ($isMolliegateway && $isSubscriptiongateway) { + $deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway); + } + } + return $gateways; + }, + 30 + ); // Disable SEPA as payment option in WooCommerce checkout add_filter( 'woocommerce_available_payment_gateways', diff --git a/src/Subscription/MollieSubscriptionGatewayHandler.php b/src/Subscription/MollieSubscriptionGatewayHandler.php index 20fc6849..5b2dfe71 100644 --- a/src/Subscription/MollieSubscriptionGatewayHandler.php +++ b/src/Subscription/MollieSubscriptionGatewayHandler.php @@ -90,16 +90,17 @@ public function __construct( $logger, $paymentMethod, ); + } + public function addSubscriptionFiters($gateway) { if (class_exists('WC_Subscriptions_Order')) { - //TODO add to the dynamic services and point to the helper method - add_action('woocommerce_scheduled_subscription_payment_' . $this->id, [ $this, 'scheduled_subscription_payment' ], 10, 2); + add_action('woocommerce_scheduled_subscription_payment_' . $gteway->id, [ $this, 'scheduled_subscription_payment' ], 10, 2); // A resubscribe order to record a customer resubscribing to an expired or cancelled subscription. add_action('wcs_resubscribe_order_created', [ $this, 'delete_resubscribe_meta' ], 10); // After creating a renewal order to record a scheduled subscription payment with the same post meta, order items etc. - add_action('wcs_renewal_order_created', [ $this, 'delete_renewal_meta' ], 10); + add_action('wcs_renewal_order_created', [ $this, 'delete_renewal_meta' ], 10); add_action('woocommerce_subscription_failing_payment_method_updated_mollie', [ $this, 'update_failing_payment_method' ], 10, 2);