Skip to content

Commit

Permalink
PIPRES-349: Update subscription action
Browse files Browse the repository at this point in the history
  • Loading branch information
mandan2 committed Dec 5, 2023
1 parent f665063 commit f30e057
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 255 deletions.
3 changes: 1 addition & 2 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use Mollie\Subscription\Install\DatabaseTableInstaller;
use Mollie\Subscription\Install\HookInstaller;
use Mollie\Subscription\Install\Installer;
use Mollie\Subscription\Logger\NullLogger;
use Mollie\Subscription\Provider\SubscriptionProductProvider;
use Mollie\Subscription\Repository\LanguageRepository as LanguageAdapter;
use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface;
Expand Down Expand Up @@ -179,7 +178,7 @@ public function install()
$subscriptionInstaller = new Installer(
new DatabaseTableInstaller(),
new AttributeInstaller(
new NullLogger(),
$this->getService(PrestaLoggerInterface::class),
$this->getService(ConfigurationAdapter::class),
$this,
new LanguageAdapter(),
Expand Down
1 change: 1 addition & 0 deletions src/Logger/PrestaLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class PrestaLogger implements PrestaLoggerInterface
{
// TODO move this as a shared service for subscriptions and main source
// TODO refactor whole logger logic and implement leftover methods

/** @var ConfigurationAdapter */
Expand Down
3 changes: 0 additions & 3 deletions src/ServiceProvider/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@
use Mollie\Subscription\Grid\Accessibility\SubscriptionCancelAccessibility;
use Mollie\Subscription\Install\Installer;
use Mollie\Subscription\Install\InstallerInterface;
use Mollie\Subscription\Logger\Logger;
use Mollie\Subscription\Logger\LoggerInterface;
use Mollie\Subscription\Repository\CombinationRepository;
use Mollie\Subscription\Repository\CombinationRepositoryInterface;
use Mollie\Subscription\Repository\OrderDetailRepository;
Expand Down Expand Up @@ -149,7 +147,6 @@ public function __construct($extendedServices)
public function register(Container $container)
{
/* Logger */
$this->addService($container, LoggerInterface::class, $container->get(Logger::class));
$this->addService($container, PrestaLoggerInterface::class, $container->get(PrestaLogger::class));

/* Utility */
Expand Down
6 changes: 3 additions & 3 deletions subscription/Action/CreateRecurringOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace Mollie\Subscription\Action;

use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\DTO\CreateRecurringOrderData;
use Mollie\Subscription\Exception\CouldNotCreateRecurringOrder;
use Mollie\Subscription\Exception\MollieSubscriptionException;
use Mollie\Subscription\Logger\LoggerInterface;
use Mollie\Subscription\Utility\ClockInterface;

if (!defined('_PS_VERSION_')) {
Expand All @@ -24,13 +24,13 @@

class CreateRecurringOrderAction
{
/** @var LoggerInterface */
/** @var PrestaLoggerInterface */
private $logger;
/** @var ClockInterface */
private $clock;

public function __construct(
LoggerInterface $logger,
PrestaLoggerInterface $logger,
ClockInterface $clock
) {
$this->logger = $logger;
Expand Down
6 changes: 3 additions & 3 deletions subscription/Action/CreateRecurringOrdersProductAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

namespace Mollie\Subscription\Action;

use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\DTO\CreateRecurringOrdersProductData;
use Mollie\Subscription\Exception\CouldNotCreateRecurringOrdersProduct;
use Mollie\Subscription\Exception\MollieSubscriptionException;
use Mollie\Subscription\Logger\LoggerInterface;

if (!defined('_PS_VERSION_')) {
exit;
}

class CreateRecurringOrdersProductAction
{
/** @var LoggerInterface */
/** @var PrestaLoggerInterface */
private $logger;

public function __construct(
LoggerInterface $logger
PrestaLoggerInterface $logger
) {
$this->logger = $logger;
}
Expand Down
55 changes: 55 additions & 0 deletions subscription/Action/UpdateSubscriptionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Mollie https://www.mollie.nl
*
* @author Mollie B.V. <[email protected]>
* @copyright Mollie B.V.
* @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md
*
* @see https://github.com/mollie/PrestaShop
* @codingStandardsIgnoreStart
*/

namespace Mollie\Subscription\Action;

use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\Api\SubscriptionApi;
use Mollie\Subscription\DTO\UpdateSubscriptionData;
use Mollie\Subscription\Exception\CouldNotUpdateSubscription;
use Mollie\Subscription\Exception\MollieSubscriptionException;

if (!defined('_PS_VERSION_')) {
exit;
}

class UpdateSubscriptionAction
{
/** @var SubscriptionApi */
private $subscriptionApi;
/** @var PrestaLoggerInterface */
private $logger;

public function __construct(
SubscriptionApi $subscriptionApi,
PrestaLoggerInterface $logger
) {
$this->subscriptionApi = $subscriptionApi;
$this->logger = $logger;
}

/**
* @throws MollieSubscriptionException
*/
public function run(UpdateSubscriptionData $data): void
{
$this->logger->info(sprintf('%s - Function called', __METHOD__));

try {
$this->subscriptionApi->updateSubscription($data);
} catch (\Throwable $exception) {
throw CouldNotUpdateSubscription::failedToUpdateSubscription($exception, $data->getSubscriptionId());
}

$this->logger->info(sprintf('%s - Function ended', __METHOD__));
}
}
32 changes: 32 additions & 0 deletions subscription/Exception/CouldNotUpdateSubscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Mollie https://www.mollie.nl
*
* @author Mollie B.V. <[email protected]>
* @copyright Mollie B.V.
* @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md
*
* @see https://github.com/mollie/PrestaShop
* @codingStandardsIgnoreStart
*/

namespace Mollie\Subscription\Exception;

if (!defined('_PS_VERSION_')) {
exit;
}

class CouldNotUpdateSubscription extends MollieSubscriptionException
{
public static function failedToUpdateSubscription(\Throwable $exception, string $subscriptionId): self
{
return new self(
sprintf(
'Failed to update subscription. Subscription ID: (%s)',
$subscriptionId
),
ExceptionCode::ORDER_FAILED_TO_UPDATE_SUBSCRIPTION,

Check failure on line 28 in subscription/Exception/CouldNotUpdateSubscription.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Access to undefined constant Mollie\Subscription\Exception\ExceptionCode::ORDER_FAILED_TO_UPDATE_SUBSCRIPTION.

Check failure on line 28 in subscription/Exception/CouldNotUpdateSubscription.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Access to undefined constant Mollie\Subscription\Exception\ExceptionCode::ORDER_FAILED_TO_UPDATE_SUBSCRIPTION.
$exception
);
}
}
6 changes: 3 additions & 3 deletions subscription/Install/AttributeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use Mollie;
use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\ProductAttributeAdapter;
use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\Config\Config;
use Mollie\Subscription\Logger\LoggerInterface;
use Mollie\Subscription\Repository\LanguageRepository;
use PrestaShopDatabaseException;
use PrestaShopException;
Expand All @@ -43,14 +43,14 @@ class AttributeInstaller extends AbstractInstaller
/** @var LanguageRepository */
private $language;

/** @var LoggerInterface */
/** @var PrestaLoggerInterface */
private $logger;

/** @var ProductAttributeAdapter */
private $productAttributeAdapter;

public function __construct(
LoggerInterface $logger,
PrestaLoggerInterface $logger,
ConfigurationAdapter $configuration,
Mollie $module,
LanguageRepository $language,
Expand Down
6 changes: 3 additions & 3 deletions subscription/Install/AttributeUninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Mollie;
use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\ProductAttributeAdapter;
use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\Config\Config;
use Mollie\Subscription\Logger\LoggerInterface;
use PrestaShopException;
use Psr\Log\LogLevel;

Expand All @@ -36,13 +36,13 @@ class AttributeUninstaller extends AbstractUninstaller
/** @var Mollie */
private $module;

/** @var LoggerInterface */
/** @var PrestaLoggerInterface */
private $logger;
/** @var ProductAttributeAdapter */
private $productAttributeAdapter;

public function __construct(
LoggerInterface $logger,
PrestaLoggerInterface $logger,
ConfigurationAdapter $configuration,
Mollie $module,
ProductAttributeAdapter $productAttributeAdapter
Expand Down
102 changes: 0 additions & 102 deletions subscription/Logger/Logger.php

This file was deleted.

21 changes: 0 additions & 21 deletions subscription/Logger/LoggerInterface.php

This file was deleted.

Loading

0 comments on commit f30e057

Please sign in to comment.