fix: update checkout entity relation to gateway IDs
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260709122602 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Change gateway_name to gateway_id';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->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)');
|
||||
}
|
||||
}
|
||||
@@ -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 '';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class GatewayLocator
|
||||
*/
|
||||
public function getForCheckout(Checkout $checkout): GatewayInterface
|
||||
{
|
||||
return $this->get($checkout->getGatewayName());
|
||||
return $this->get($checkout->getGatewayId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class CheckoutService
|
||||
GatewaysController::REDIRECT,
|
||||
[
|
||||
'type' => $type,
|
||||
'gateway' => $checkout->getGatewayName(),
|
||||
'gateway' => $checkout->getGatewayId(),
|
||||
'checkoutId' => $checkout->getId(),
|
||||
...$parameters,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user