From 31659829670aa72ddbb4fdd0fb2dbd216cf7d836 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Thu, 9 Jul 2026 14:26:46 +0200 Subject: [PATCH] fix: update checkout entity relation to gateway IDs --- migrations/Version20260709122602.php | 30 +++++++++++++++++++++++++ src/Benzina/InvestsPump.php | 16 ++++++------- src/Entity/Gateway/Checkout.php | 14 ++++++------ src/Filter/GatewayFilter.php | 10 ++++----- src/Gateway/GatewayLocator.php | 2 +- src/Service/Gateway/CheckoutService.php | 2 +- 6 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 migrations/Version20260709122602.php diff --git a/migrations/Version20260709122602.php b/migrations/Version20260709122602.php new file mode 100644 index 0000000..d260368 --- /dev/null +++ b/migrations/Version20260709122602.php @@ -0,0 +1,30 @@ +addSql('DROP INDEX IDX_AF382D4E3D4E91C8BF396750 ON checkout'); + $this->addSql('ALTER TABLE checkout CHANGE gateway_name gateway_id VARCHAR(255) NOT NULL'); + $this->addSql('CREATE INDEX IDX_AF382D4EBF396750 ON checkout (id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX IDX_AF382D4EBF396750 ON checkout'); + $this->addSql('ALTER TABLE checkout CHANGE gateway_id gateway_name VARCHAR(255) NOT NULL'); + $this->addSql('CREATE INDEX IDX_AF382D4E3D4E91C8BF396750 ON checkout (gateway_name, id)'); + } +} diff --git a/src/Benzina/InvestsPump.php b/src/Benzina/InvestsPump.php index a730e85..f3e01fd 100644 --- a/src/Benzina/InvestsPump.php +++ b/src/Benzina/InvestsPump.php @@ -117,7 +117,7 @@ class InvestsPump implements PumpInterface $checkout->setOrigin($user->getAccounting()); $checkout->setStatus($this->getCheckoutStatus($record)); - $checkout->setGatewayName($this->getCheckoutGateway($record)); + $checkout->setGatewayId($this->getCheckoutGatewayId($record)); $checkout->setReturnUrl(self::PLATFORM_RETURN_URL); foreach ($this->getCheckoutTrackings($record) as $tracking) { @@ -396,21 +396,21 @@ class InvestsPump implements PumpInterface } } - private function getCheckoutGateway(array $record): string + private function getCheckoutGatewayId(array $record): string { switch ($record['method']) { case 'tpv': - return CecaGateway::getName(); + return CecaGateway::getId(); case 'paypal': - return PaypalGateway::getName(); + return PaypalGateway::getId(); case 'pool': - return WalletGateway::getName(); + return WalletGateway::getId(); case 'cash': - return CashGateway::getName(); + return CashGateway::getId(); case 'drop': - return DropGateway::getName(); + return DropGateway::getId(); case 'stripe_subscription': - return StripeGateway::getName(); + return StripeGateway::getId(); default: return ''; } diff --git a/src/Entity/Gateway/Checkout.php b/src/Entity/Gateway/Checkout.php index 7f059ab..c3d7813 100644 --- a/src/Entity/Gateway/Checkout.php +++ b/src/Entity/Gateway/Checkout.php @@ -29,7 +29,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[MapProvider(EntityMapProvider::class)] #[Gedmo\Loggable()] #[ORM\Index(fields: ['migratedId'])] -#[ORM\Index(fields: ['gatewayName', 'id'])] +#[ORM\Index(fields: ['gateway', 'id'])] #[ORM\Entity(repositoryClass: CheckoutRepository::class)] class Checkout { @@ -43,11 +43,11 @@ class Checkout private ?int $id = null; /** - * The name of the Gateway implementation to checkout with. + * The ID of the Gateway implementation to checkout with. */ #[Assert\NotBlank()] #[ORM\Column(length: 255)] - private ?string $gatewayName = null; + private ?string $gatewayId = null; /** * The Accounting that will issue the Transactions of the GatewayCharges after a successful checkout. @@ -114,14 +114,14 @@ class Checkout return $this->id; } - public function getGatewayName(): ?string + public function getGatewayId(): ?string { - return $this->gatewayName; + return $this->gatewayId; } - public function setGatewayName(string $gatewayName): static + public function setGatewayId(string $id): static { - $this->gatewayName = $gatewayName; + $this->gatewayId = $id; return $this; } diff --git a/src/Filter/GatewayFilter.php b/src/Filter/GatewayFilter.php index b3861cc..038c86b 100644 --- a/src/Filter/GatewayFilter.php +++ b/src/Filter/GatewayFilter.php @@ -50,29 +50,29 @@ final class GatewayFilter extends AbstractFilter [$alias] = $this->addJoinsForNestedProperty($property, $rootAlias, $queryBuilder, $queryNameGenerator, $resourceClass, Join::LEFT_JOIN); } - $aliasedField = \sprintf('%s.gatewayName', $alias); + $aliasedField = \sprintf('%s.gatewayId', $alias); if (\count($values) > 1) { $queryBuilder ->andWhere($queryBuilder->expr()->in($aliasedField, $parameterName)) - ->setParameter($parameterName, array_map(fn($v) => $this->getGatewayName($v), $values)); + ->setParameter($parameterName, array_map(fn($v) => $this->getGatewayId($v), $values)); return; } $queryBuilder ->andWhere($queryBuilder->expr()->eq($aliasedField, $parameterName)) - ->setParameter($parameterName, $this->getGatewayName($values[0])); + ->setParameter($parameterName, $this->getGatewayId($values[0])); } - private function getGatewayName(mixed $value): string + private function getGatewayId(mixed $value): string { $value = \array_slice(\explode('/', $value), -1)[0]; try { $gateway = $this->gatewayLocator->get($value); - return $gateway::getName(); + return $gateway::getId(); } catch (MissingGatewayException $e) { throw new NotFoundHttpException($e->getMessage()); } diff --git a/src/Gateway/GatewayLocator.php b/src/Gateway/GatewayLocator.php index bcf3c95..be43cec 100644 --- a/src/Gateway/GatewayLocator.php +++ b/src/Gateway/GatewayLocator.php @@ -54,7 +54,7 @@ class GatewayLocator */ public function getForCheckout(Checkout $checkout): GatewayInterface { - return $this->get($checkout->getGatewayName()); + return $this->get($checkout->getGatewayId()); } /** diff --git a/src/Service/Gateway/CheckoutService.php b/src/Service/Gateway/CheckoutService.php index 5148798..e96a6c0 100644 --- a/src/Service/Gateway/CheckoutService.php +++ b/src/Service/Gateway/CheckoutService.php @@ -34,7 +34,7 @@ class CheckoutService GatewaysController::REDIRECT, [ 'type' => $type, - 'gateway' => $checkout->getGatewayName(), + 'gateway' => $checkout->getGatewayId(), 'checkoutId' => $checkout->getId(), ...$parameters, ],