From 9b21855852ed656d0a9c9e00f5e7a224966f66a9 Mon Sep 17 00:00:00 2001 From: Jacob Tobiasz Date: Tue, 10 Sep 2024 19:45:03 +0200 Subject: [PATCH] Fix CI --- config/services/payum/action.php | 2 -- src/Form/Extension/CompleteTypeExtension.php | 2 +- src/Form/Type/TpayCardType.php | 30 ++++++++++++------- .../Type/TpayGatewayConfigurationType.php | 4 +-- src/Form/Type/TpayPaymentDetailsType.php | 5 ++-- .../Api/AbstractCreateTransactionAction.php | 9 +----- .../Api/CreateCardTransactionAction.php | 8 ++--- .../CreateRedirectBasedTransactionAction.php | 8 ++--- src/Payum/Action/CaptureAction.php | 8 +++-- .../Factory/Token/NotifyTokenFactory.php | 2 +- .../CreateCardPaymentPayloadFactory.php | 3 +- ...eateRedirectBasedPaymentPayloadFactory.php | 2 +- .../Api/CreateCardTransactionActionTest.php | 5 ---- ...eateRedirectBasedTransactionActionTest.php | 5 ---- 14 files changed, 43 insertions(+), 50 deletions(-) diff --git a/config/services/payum/action.php b/config/services/payum/action.php index 49e433d6..6e7a7d5a 100644 --- a/config/services/payum/action.php +++ b/config/services/payum/action.php @@ -28,7 +28,6 @@ $services->set(CreateCardTransactionAction::class) ->args([ - service('router'), service('commerce_weavers_tpay.tpay.factory.create_card_payment_payload'), service('commerce_weavers_tpay.payum.factory.token.notify'), ]) @@ -37,7 +36,6 @@ $services->set(CreateRedirectBasedTransactionAction::class) ->args([ - service('router'), service('commerce_weavers_tpay.tpay.factory.create_redirect_based_payment_payload'), service('commerce_weavers_tpay.payum.factory.token.notify'), ]) diff --git a/src/Form/Extension/CompleteTypeExtension.php b/src/Form/Extension/CompleteTypeExtension.php index a27801aa..1a465e41 100644 --- a/src/Form/Extension/CompleteTypeExtension.php +++ b/src/Form/Extension/CompleteTypeExtension.php @@ -18,7 +18,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'tpay', TpayPaymentDetailsType::class, [ - 'property_path' => 'last_payment.details[tpay]' + 'property_path' => 'last_payment.details[tpay]', ], ) ; diff --git a/src/Form/Type/TpayCardType.php b/src/Form/Type/TpayCardType.php index dbae94c7..702a8e8d 100644 --- a/src/Form/Type/TpayCardType.php +++ b/src/Form/Type/TpayCardType.php @@ -24,24 +24,27 @@ public function buildForm(FormBuilderInterface $builder, array $options): void TextType::class, [ 'mapped' => false, - 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.holder_name' + 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.holder_name', ], ) - ->add('number', + ->add( + 'number', TextType::class, [ 'mapped' => false, - 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.number' + 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.number', ], ) - ->add('cvv', + ->add( + 'cvv', TextType::class, [ 'mapped' => false, - 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.cvv' + 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.cvv', ], ) - ->add('expiration_date_month', + ->add( + 'expiration_date_month', ChoiceType::class, [ 'mapped' => false, @@ -59,7 +62,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'commerce_weavers_sylius_tpay.shop.order_summary.card.expiration_date.month.october' => '10', 'commerce_weavers_sylius_tpay.shop.order_summary.card.expiration_date.month.november' => '11', 'commerce_weavers_sylius_tpay.shop.order_summary.card.expiration_date.month.december' => '12', - ] + ], ], ) ->add( @@ -68,19 +71,26 @@ public function buildForm(FormBuilderInterface $builder, array $options): void [ 'mapped' => false, 'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.card.expiration_date.year', - ] + ], ) ->add('card', HiddenType::class) ; - $builder->addModelTransformer(new class implements DataTransformerInterface { + $builder->addModelTransformer(new class() implements DataTransformerInterface { public function transform($value): ?array { return null; } - public function reverseTransform($value): string + /** + * @param mixed|array{card: string} $value + */ + public function reverseTransform(mixed $value): string { + if (!is_array($value)) { + return ''; + } + return $value['card']; } }); diff --git a/src/Form/Type/TpayGatewayConfigurationType.php b/src/Form/Type/TpayGatewayConfigurationType.php index bd68c359..bcf85c80 100644 --- a/src/Form/Type/TpayGatewayConfigurationType.php +++ b/src/Form/Type/TpayGatewayConfigurationType.php @@ -45,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void TextType::class, [ 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.cards_api', - ] + ], ) ->add( 'type', @@ -56,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'commerce_weavers_sylius_tpay.admin.gateway_configuration.type.redirect' => 'redirect', 'commerce_weavers_sylius_tpay.admin.gateway_configuration.type.card' => 'card', ], - ] + ], ) ->add( 'production_mode', diff --git a/src/Form/Type/TpayPaymentDetailsType.php b/src/Form/Type/TpayPaymentDetailsType.php index ff57ca1a..7bd4ae22 100644 --- a/src/Form/Type/TpayPaymentDetailsType.php +++ b/src/Form/Type/TpayPaymentDetailsType.php @@ -20,11 +20,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'card', TpayCardType::class, [ - 'property_path' => '[card]' - ] + 'property_path' => '[card]', + ], ); $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + /** @var array{card?: string} $data */ $data = $event->getData() ?? []; $form = $event->getForm(); diff --git a/src/Payum/Action/Api/AbstractCreateTransactionAction.php b/src/Payum/Action/Api/AbstractCreateTransactionAction.php index 87b3c19a..e149a89b 100644 --- a/src/Payum/Action/Api/AbstractCreateTransactionAction.php +++ b/src/Payum/Action/Api/AbstractCreateTransactionAction.php @@ -8,7 +8,6 @@ use Payum\Core\Security\GenericTokenFactoryAwareInterface; use Payum\Core\Security\GenericTokenFactoryAwareTrait; use Sylius\Component\Core\Model\PaymentInterface; -use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; abstract class AbstractCreateTransactionAction extends BaseApiAwareAction implements GenericTokenFactoryAwareInterface @@ -16,12 +15,6 @@ abstract class AbstractCreateTransactionAction extends BaseApiAwareAction implem use GenericTokenFactoryAwareTrait; use GatewayAwareTrait; - public function __construct( - private RouterInterface $router, - ) { - parent::__construct(); - } - protected function createTransaction(PaymentInterface $payment, array $payload): void { $details = $payment->getDetails(); @@ -41,6 +34,6 @@ protected function createTransaction(PaymentInterface $payment, array $payload): protected function getLocaleCodeFrom(PaymentInterface $payment): string { - return $payment->getOrder()->getLocaleCode() ?? throw new \InvalidArgumentException('Cannot determine locale code for a given payment'); + return $payment->getOrder()?->getLocaleCode() ?? throw new \InvalidArgumentException('Cannot determine locale code for a given payment'); } } diff --git a/src/Payum/Action/Api/CreateCardTransactionAction.php b/src/Payum/Action/Api/CreateCardTransactionAction.php index f65e2984..d42e8537 100644 --- a/src/Payum/Action/Api/CreateCardTransactionAction.php +++ b/src/Payum/Action/Api/CreateCardTransactionAction.php @@ -12,7 +12,6 @@ use Payum\Core\GatewayAwareTrait; use Payum\Core\Security\GenericTokenFactoryAwareTrait; use Sylius\Component\Core\Model\PaymentInterface; -use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; final class CreateCardTransactionAction extends AbstractCreateTransactionAction implements GatewayAwareInterface @@ -21,11 +20,10 @@ final class CreateCardTransactionAction extends AbstractCreateTransactionAction use GatewayAwareTrait; public function __construct( - private RouterInterface $router, private CreateCardPaymentPayloadFactoryInterface $createCardPaymentPayloadFactory, private NotifyTokenFactoryInterface $notifyTokenFactory, ) { - parent::__construct($router); + parent::__construct(); } /** @@ -51,12 +49,12 @@ public function execute($request): void public function supports($request): bool { - $model = $request->getModel(); - if (!$request instanceof CreateTransaction) { return false; } + $model = $request->getModel(); + if (!$model instanceof PaymentInterface) { return false; } diff --git a/src/Payum/Action/Api/CreateRedirectBasedTransactionAction.php b/src/Payum/Action/Api/CreateRedirectBasedTransactionAction.php index af05afc9..cde8e4cc 100644 --- a/src/Payum/Action/Api/CreateRedirectBasedTransactionAction.php +++ b/src/Payum/Action/Api/CreateRedirectBasedTransactionAction.php @@ -10,7 +10,6 @@ use Payum\Core\Reply\HttpRedirect; use Payum\Core\Security\GenericTokenFactoryAwareTrait; use Sylius\Component\Core\Model\PaymentInterface; -use Symfony\Component\Routing\RouterInterface; use Webmozart\Assert\Assert; class CreateRedirectBasedTransactionAction extends AbstractCreateTransactionAction @@ -18,11 +17,10 @@ class CreateRedirectBasedTransactionAction extends AbstractCreateTransactionActi use GenericTokenFactoryAwareTrait; public function __construct( - private RouterInterface $router, private CreateRedirectBasedPaymentPayloadFactoryInterface $createRedirectBasedPaymentPayloadFactory, private NotifyTokenFactoryInterface $notifyTokenFactory, ) { - parent::__construct($router); + parent::__construct(); } /** @@ -50,12 +48,12 @@ public function execute($request): void public function supports($request): bool { - $model = $request->getModel(); - if (!$request instanceof CreateTransaction) { return false; } + $model = $request->getModel(); + if (!$model instanceof PaymentInterface) { return false; } diff --git a/src/Payum/Action/CaptureAction.php b/src/Payum/Action/CaptureAction.php index 5de2227b..54030b34 100644 --- a/src/Payum/Action/CaptureAction.php +++ b/src/Payum/Action/CaptureAction.php @@ -11,6 +11,7 @@ use Payum\Core\Reply\HttpRedirect; use Payum\Core\Request\Capture; use Sylius\Component\Core\Model\PaymentInterface; +use Webmozart\Assert\Assert; final class CaptureAction implements ActionInterface, GatewayAwareInterface { @@ -26,11 +27,14 @@ public function __construct( */ public function execute($request): void { + $token = $request->getToken(); + Assert::notNull($token); + $this->gateway->execute( - $this->createTransactionFactory->createNewWithModel($request->getToken()), + $this->createTransactionFactory->createNewWithModel($token), ); - throw new HttpRedirect($request->getToken()->getAfterUrl()); + throw new HttpRedirect($token->getAfterUrl()); } public function supports($request): bool diff --git a/src/Payum/Factory/Token/NotifyTokenFactory.php b/src/Payum/Factory/Token/NotifyTokenFactory.php index ba8b67db..e4a542ae 100644 --- a/src/Payum/Factory/Token/NotifyTokenFactory.php +++ b/src/Payum/Factory/Token/NotifyTokenFactory.php @@ -12,7 +12,7 @@ final class NotifyTokenFactory implements NotifyTokenFactoryInterface { - public function __construct ( + public function __construct( private Payum $payum, private RouterInterface $router, private string $notifyRouteName, diff --git a/src/Tpay/Factory/CreateCardPaymentPayloadFactory.php b/src/Tpay/Factory/CreateCardPaymentPayloadFactory.php index 61e58489..871e75cb 100644 --- a/src/Tpay/Factory/CreateCardPaymentPayloadFactory.php +++ b/src/Tpay/Factory/CreateCardPaymentPayloadFactory.php @@ -8,7 +8,7 @@ final class CreateCardPaymentPayloadFactory implements CreateCardPaymentPayloadFactoryInterface { - public function __construct ( + public function __construct( private CreateRedirectBasedPaymentPayloadFactoryInterface $createRedirectBasedPaymentPayloadFactory, ) { } @@ -18,6 +18,7 @@ public function __construct ( */ public function createFrom(PaymentInterface $payment, string $notifyUrl, string $localeCode): array { + /** @var array{pay: array} $payload */ $payload = $this->createRedirectBasedPaymentPayloadFactory->createFrom($payment, $notifyUrl, $localeCode); $payload['pay']['groupId'] = 103; diff --git a/src/Tpay/Factory/CreateRedirectBasedPaymentPayloadFactory.php b/src/Tpay/Factory/CreateRedirectBasedPaymentPayloadFactory.php index 92396ca4..2547bf75 100644 --- a/src/Tpay/Factory/CreateRedirectBasedPaymentPayloadFactory.php +++ b/src/Tpay/Factory/CreateRedirectBasedPaymentPayloadFactory.php @@ -11,7 +11,7 @@ final class CreateRedirectBasedPaymentPayloadFactory implements CreateRedirectBasedPaymentPayloadFactoryInterface { - public function __construct ( + public function __construct( private RouterInterface $router, private string $successRoute, private string $errorRoute, diff --git a/tests/Unit/Payum/Action/Api/CreateCardTransactionActionTest.php b/tests/Unit/Payum/Action/Api/CreateCardTransactionActionTest.php index 84f1de8a..b13e7688 100644 --- a/tests/Unit/Payum/Action/Api/CreateCardTransactionActionTest.php +++ b/tests/Unit/Payum/Action/Api/CreateCardTransactionActionTest.php @@ -19,7 +19,6 @@ use Prophecy\Prophecy\ObjectProphecy; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; -use Symfony\Component\Routing\RouterInterface; use Tpay\OpenApi\Api\TpayApi; use Tpay\OpenApi\Api\Transactions\TransactionsApi; use Webmozart\Assert\InvalidArgumentException; @@ -30,8 +29,6 @@ final class CreateCardTransactionActionTest extends TestCase private TpayApi|ObjectProphecy $api; - private RouterInterface|ObjectProphecy $router; - private CreateCardPaymentPayloadFactoryInterface|ObjectProphecy $createCardPaymentPayloadFactory; private GenericTokenFactoryInterface|ObjectProphecy $tokenFactory; @@ -43,7 +40,6 @@ final class CreateCardTransactionActionTest extends TestCase protected function setUp(): void { $this->api = $this->prophesize(TpayApi::class); - $this->router = $this->prophesize(RouterInterface::class); $this->createCardPaymentPayloadFactory = $this->prophesize(CreateCardPaymentPayloadFactoryInterface::class); $this->tokenFactory = $this->prophesize(GenericTokenFactoryInterface::class); $this->notifyTokenFactory = $this->prophesize(NotifyTokenFactoryInterface::class); @@ -164,7 +160,6 @@ public function test_it_throws_an_exception_if_a_token_is_null(): void private function createTestSubject(): CreateCardTransactionAction { $action = new CreateCardTransactionAction( - $this->router->reveal(), $this->createCardPaymentPayloadFactory->reveal(), $this->notifyTokenFactory->reveal(), ); diff --git a/tests/Unit/Payum/Action/Api/CreateRedirectBasedTransactionActionTest.php b/tests/Unit/Payum/Action/Api/CreateRedirectBasedTransactionActionTest.php index 21035d1e..bb1ed6e6 100644 --- a/tests/Unit/Payum/Action/Api/CreateRedirectBasedTransactionActionTest.php +++ b/tests/Unit/Payum/Action/Api/CreateRedirectBasedTransactionActionTest.php @@ -17,7 +17,6 @@ use Prophecy\Prophecy\ObjectProphecy; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentInterface; -use Symfony\Component\Routing\RouterInterface; use Tpay\OpenApi\Api\TpayApi; use Tpay\OpenApi\Api\Transactions\TransactionsApi; use Webmozart\Assert\InvalidArgumentException; @@ -28,8 +27,6 @@ final class CreateRedirectBasedTransactionActionTest extends TestCase private TpayApi|ObjectProphecy $api; - private RouterInterface|ObjectProphecy $router; - private CreateRedirectBasedPaymentPayloadFactoryInterface|ObjectProphecy $createRedirectBasedPaymentPayloadFactory; private GenericTokenFactoryInterface|ObjectProphecy $tokenFactory; @@ -39,7 +36,6 @@ final class CreateRedirectBasedTransactionActionTest extends TestCase protected function setUp(): void { $this->api = $this->prophesize(TpayApi::class); - $this->router = $this->prophesize(RouterInterface::class); $this->createRedirectBasedPaymentPayloadFactory = $this->prophesize(CreateRedirectBasedPaymentPayloadFactoryInterface::class); $this->tokenFactory = $this->prophesize(GenericTokenFactoryInterface::class); $this->notifyTokenFactory = $this->prophesize(NotifyTokenFactoryInterface::class); @@ -178,7 +174,6 @@ public function test_it_throws_an_exception_if_a_token_is_null(): void private function createTestSubject(): CreateRedirectBasedTransactionAction { $action = new CreateRedirectBasedTransactionAction( - $this->router->reveal(), $this->createRedirectBasedPaymentPayloadFactory->reveal(), $this->notifyTokenFactory->reveal(), );