Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Sep 10, 2024
1 parent ef3bfe8 commit 9b21855
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 50 deletions.
2 changes: 0 additions & 2 deletions config/services/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
])
Expand All @@ -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'),
])
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Extension/CompleteTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
],
)
;
Expand Down
30 changes: 20 additions & 10 deletions src/Form/Type/TpayCardType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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'];
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Type/TpayGatewayConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions src/Form/Type/TpayPaymentDetailsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
9 changes: 1 addition & 8 deletions src/Payum/Action/Api/AbstractCreateTransactionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
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
{
use GenericTokenFactoryAwareTrait;
use GatewayAwareTrait;

public function __construct(
private RouterInterface $router,
) {
parent::__construct();
}

protected function createTransaction(PaymentInterface $payment, array $payload): void
{
$details = $payment->getDetails();
Expand All @@ -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');
}
}
8 changes: 3 additions & 5 deletions src/Payum/Action/Api/CreateCardTransactionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

/**
Expand All @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/Payum/Action/Api/CreateRedirectBasedTransactionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
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
{
use GenericTokenFactoryAwareTrait;

public function __construct(
private RouterInterface $router,
private CreateRedirectBasedPaymentPayloadFactoryInterface $createRedirectBasedPaymentPayloadFactory,
private NotifyTokenFactoryInterface $notifyTokenFactory,
) {
parent::__construct($router);
parent::__construct();
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Payum/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Factory/Token/NotifyTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final class NotifyTokenFactory implements NotifyTokenFactoryInterface
{
public function __construct (
public function __construct(
private Payum $payum,
private RouterInterface $router,
private string $notifyRouteName,
Expand Down
3 changes: 2 additions & 1 deletion src/Tpay/Factory/CreateCardPaymentPayloadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class CreateCardPaymentPayloadFactory implements CreateCardPaymentPayloadFactoryInterface
{
public function __construct (
public function __construct(
private CreateRedirectBasedPaymentPayloadFactoryInterface $createRedirectBasedPaymentPayloadFactory,
) {
}
Expand All @@ -18,6 +18,7 @@ public function __construct (
*/
public function createFrom(PaymentInterface $payment, string $notifyUrl, string $localeCode): array
{
/** @var array{pay: array<string, mixed>} $payload */
$payload = $this->createRedirectBasedPaymentPayloadFactory->createFrom($payment, $notifyUrl, $localeCode);

$payload['pay']['groupId'] = 103;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class CreateRedirectBasedPaymentPayloadFactory implements CreateRedirectBasedPaymentPayloadFactoryInterface
{
public function __construct (
public function __construct(
private RouterInterface $router,
private string $successRoute,
private string $errorRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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(),
);
Expand Down

0 comments on commit 9b21855

Please sign in to comment.