Skip to content

Commit

Permalink
Move subscription constructor filters
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Dec 20, 2024
1 parent 9cc28e0 commit 6e215c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 4 additions & 3 deletions src/Subscription/MollieSubscriptionGatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6e215c8

Please sign in to comment.