Skip to content

Commit

Permalink
Fixes to install and run the plugin with Sylius Standard (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel authored Nov 4, 2024
2 parents 806fe0f + 58ac9c5 commit 5ed4505
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"firebase/php-jwt": "^6.10",
"payum/core": "^1.7",
"sylius/core-bundle": "^1.12",
"sylius/refund-plugin": "^1.5",
"sylius/resource-bundle": "^1.10",
"symfony/config": "5.4.* || ^6.0",
"symfony/dependency-injection": "5.4.* || ^6.0",
Expand Down Expand Up @@ -50,7 +51,6 @@
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"shipmonk/composer-dependency-analyser": "^1.7",
"sylius-labs/coding-standard": "^4.2",
"sylius/refund-plugin": "^1.5",
"sylius/sylius": "^1.12",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
Expand Down
17 changes: 17 additions & 0 deletions src/DependencyInjection/CommerceWeaversSyliusTpayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Tpay\OpenApi\Utilities\Logger;

final class CommerceWeaversSyliusTpayExtension extends AbstractResourceExtension implements PrependExtensionInterface
{
Expand Down Expand Up @@ -43,6 +44,7 @@ public function prepend(ContainerBuilder $container): void
$container,
);

$this->setUpTpayLogger($container);
$this->prependDoctrineMigrations($container);
$this->prependDoctrineMapping($container);
}
Expand Down Expand Up @@ -105,4 +107,19 @@ private function getCurrentConfiguration(ContainerBuilder $container): array

return $this->processConfiguration($configuration, $configs);
}

private function setUpTpayLogger(ContainerBuilder $container): void
{
if (!$container->hasParameter('kernel.logs_dir')) {
return;
}

$logsDir = $container->getParameter('kernel.logs_dir');

if (!is_string($logsDir)) {
return;
}

Logger::setLogPath(sprintf('%s/tpay_open_api_', $logsDir));
}
}
2 changes: 0 additions & 2 deletions src/Payum/Action/Api/BaseApiAwareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Tpay\OpenApi\Utilities\Logger;
use Tpay\OpenApi\Utilities\TpayException;

/**
Expand All @@ -21,7 +20,6 @@ abstract class BaseApiAwareAction implements ActionInterface, ApiAwareInterface
public function __construct()
{
$this->apiClass = TpayApi::class;
Logger::setLogPath(dirname(__DIR__, 4) . '/tests/Application/var/log/');
}

protected function do(callable $func, callable $onSuccess, callable $onFailure): void
Expand Down
13 changes: 0 additions & 13 deletions src/Repository/FindByChannelWithGatewayConfigTraitInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace App\Repository;
declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Repository;

use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface as BasePaymentMethodRepositoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @mixin EntityRepository
*/
trait FindByChannelWithGatewayConfigTrait
trait PaymentMethodTrait
{
public function findByChannelAndGatewayConfigNameWithGatewayConfig(ChannelInterface $channel, string $gatewayConfigName): array
{
Expand Down
6 changes: 5 additions & 1 deletion src/Tpay/Provider/ValidTpayChannelListProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@

namespace CommerceWeavers\SyliusTpayPlugin\Tpay\Provider;

use App\Repository\PaymentMethodRepositoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Exception\UnableToGetBankListException;
use CommerceWeavers\SyliusTpayPlugin\Repository\PaymentMethodRepositoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\PayGroup;
use CommerceWeavers\SyliusTpayPlugin\Tpay\PaymentType;
use Payum\Core\Security\CryptedInterface;
use Payum\Core\Security\CypherInterface;
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface as BasePaymentMethodRepositoryInterface;
use Webmozart\Assert\Assert;

final class ValidTpayChannelListProvider implements ValidTpayChannelListProviderInterface
{
/**
* @param BasePaymentMethodRepositoryInterface&PaymentMethodRepositoryInterface $paymentMethodRepository
*/
public function __construct(
private readonly AvailableTpayChannelListProviderInterface $availableTpayApiBankListProvider,
private readonly PaymentMethodRepositoryInterface $paymentMethodRepository,
Expand Down
5 changes: 3 additions & 2 deletions tests/Application/src/Repository/PaymentMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace App\Repository;

use CommerceWeavers\SyliusTpayPlugin\Repository\FindByChannelWithGatewayConfigTrait;
use CommerceWeavers\SyliusTpayPlugin\Repository\PaymentMethodTrait;
use CommerceWeavers\SyliusTpayPlugin\Repository\PaymentMethodRepositoryInterface;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository as BasePaymentMethodRepository;

final class PaymentMethodRepository extends BasePaymentMethodRepository implements PaymentMethodRepositoryInterface
{
use FindByChannelWithGatewayConfigTrait;
use PaymentMethodTrait;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Tpay\Provider;

use App\Repository\PaymentMethodRepositoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Exception\UnableToGetBankListException;
use CommerceWeavers\SyliusTpayPlugin\Repository\PaymentMethodRepositoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\AvailableTpayChannelListProviderInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProvider;
use Payum\Core\Security\CypherInterface;
Expand Down

0 comments on commit 5ed4505

Please sign in to comment.