Skip to content

Commit

Permalink
Move to theme hook only relevant parts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 17, 2025
1 parent 96922db commit 734a1f7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ function initialize()
}
}

add_action('after_setup_theme', __NAMESPACE__ . '\\initialize');
add_action('plugins_loaded', __NAMESPACE__ . '\\initialize');
46 changes: 25 additions & 21 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,35 @@ static function () {

// Set order to paid and processed when eventually completed without Mollie
add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1);
$appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_applepay'] : false;
$notice = $container->get(AdminNotice::class);
assert($notice instanceof AdminNotice);
$logger = $container->get(Logger::class);
assert($logger instanceof Logger);
$pluginUrl = $container->get('shared.plugin_url');
$apiHelper = $container->get('SDK.api_helper');
assert($apiHelper instanceof Api);
$settingsHelper = $container->get('settings.settings_helper');
assert($settingsHelper instanceof Settings);

$surchargeService = $container->get(Surcharge::class);
assert($surchargeService instanceof Surcharge);
$this->gatewaySurchargeHandling($surchargeService);
if ($appleGateway) {
$this->mollieApplePayDirectHandling($notice, $logger, $apiHelper, $settingsHelper, $appleGateway);
}
add_action('after_setup_theme', function () use ($container) {
$notice = $container->get(AdminNotice::class);
assert($notice instanceof AdminNotice);
$logger = $container->get(Logger::class);
assert($logger instanceof Logger);
$pluginUrl = $container->get('shared.plugin_url');
$apiHelper = $container->get('SDK.api_helper');
assert($apiHelper instanceof Api);
$settingsHelper = $container->get('settings.settings_helper');
assert($settingsHelper instanceof Settings);
$appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_applepay'] : false;
if ($appleGateway) {
$this->mollieApplePayDirectHandling($notice, $logger, $apiHelper, $settingsHelper, $appleGateway);
}

$paypalGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_paypal']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_paypal'] : false;
if ($paypalGateway) {
$this->molliePayPalButtonHandling($paypalGateway, $notice, $logger, $pluginUrl);
}
});

$paypalGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_paypal']) ? $container->get(
'gateway.instances'
)['mollie_wc_gateway_paypal'] : false;
if ($paypalGateway) {
$this->molliePayPalButtonHandling($paypalGateway, $notice, $logger, $pluginUrl);
}

$maybeDisableVoucher = new MaybeDisableGateway();
$dataService = $container->get('settings.data_helper');
Expand Down
6 changes: 5 additions & 1 deletion src/Shared/GatewaySurchargeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ class GatewaySurchargeHandler
public function __construct(Surcharge $surcharge)
{
$this->surcharge = $surcharge;
$this->gatewayFeeLabel = $this->surchargeFeeOption();
add_action('after_setup_theme', [$this, 'initializeGatewayFeeLabel']);
add_action('init', [$this, 'surchargeActions']);
}
public function initializeGatewayFeeLabel()
{
$this->gatewayFeeLabel = $this->surchargeFeeOption();
}

public function surchargeActions()
{
Expand Down
8 changes: 2 additions & 6 deletions src/Shared/SharedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ public function services(): array
return plugin_basename(self::PLUGIN_ID . '/' . self::PLUGIN_ID . '.php');
},
'shared.plugin_url' => static function (ContainerInterface $container): string {
$pluginProperties = $container->get(Package::PROPERTIES);

return $pluginProperties->baseUrl();
return $container->get('properties')->baseUrl();
},
'shared.plugin_path' => static function (ContainerInterface $container): string {

$pluginProperties = $container->get(Package::PROPERTIES);

return $pluginProperties->basePath();
return $container->get('properties')->basePath();
},
'shared.status_helper' => static function (ContainerInterface $container): Status {
$pluginTitle = $container->get('shared.plugin_title');
Expand Down

0 comments on commit 734a1f7

Please sign in to comment.