Simplify Checkout entity
This commit is contained in:
@@ -89,7 +89,7 @@ class Checkout
|
||||
*/
|
||||
#[API\ApiProperty(writable: false)]
|
||||
#[ORM\Column]
|
||||
private array $gatewayLinks = [];
|
||||
private array $links = [];
|
||||
|
||||
/**
|
||||
* A list of tracking codes provided by the Gateway for this checkout.\
|
||||
@@ -99,7 +99,7 @@ class Checkout
|
||||
*/
|
||||
#[API\ApiProperty(writable: false)]
|
||||
#[ORM\Column]
|
||||
private array $gatewayTrackings = [];
|
||||
private array $trackings = [];
|
||||
|
||||
/**
|
||||
* GatewayCheckout was migrated from an invest record in Goteo v3 platform.
|
||||
@@ -115,12 +115,6 @@ class Checkout
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $migratedId = null;
|
||||
|
||||
/**
|
||||
* A free-form collection of additional data associated with this checkout operation.
|
||||
*/
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?array $metadata = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->status = CheckoutStatus::Pending;
|
||||
@@ -201,22 +195,22 @@ class Checkout
|
||||
/**
|
||||
* @return Link[]
|
||||
*/
|
||||
public function getGatewayLinks(): array
|
||||
public function getLinks(): array
|
||||
{
|
||||
return $this->gatewayLinks;
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
public function addGatewayLink(Link $link): static
|
||||
public function addLink(Link $link): static
|
||||
{
|
||||
$this->gatewayLinks = [...$this->gatewayLinks, $link];
|
||||
$this->links = [...$this->links, $link];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeGatewayLink(Link $link): static
|
||||
public function removeLink(Link $link): static
|
||||
{
|
||||
$this->gatewayLinks = \array_filter(
|
||||
$this->gatewayLinks,
|
||||
$this->links = \array_filter(
|
||||
$this->links,
|
||||
function (Link $existingLink) use ($link) {
|
||||
return $existingLink->href !== $link->href;
|
||||
}
|
||||
@@ -228,22 +222,22 @@ class Checkout
|
||||
/**
|
||||
* @return Tracking[]
|
||||
*/
|
||||
public function getGatewayTrackings(): array
|
||||
public function getTrackings(): array
|
||||
{
|
||||
return $this->gatewayTrackings;
|
||||
return $this->trackings;
|
||||
}
|
||||
|
||||
public function addGatewayTracking(Tracking $tracking): static
|
||||
public function addTracking(Tracking $tracking): static
|
||||
{
|
||||
$this->gatewayTrackings = [...$this->gatewayTrackings, $tracking];
|
||||
$this->trackings = [...$this->trackings, $tracking];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeGatewayTracking(Tracking $tracking): static
|
||||
public function removeTracking(Tracking $tracking): static
|
||||
{
|
||||
$this->gatewayTrackings = \array_filter(
|
||||
$this->gatewayTrackings,
|
||||
$this->trackings = \array_filter(
|
||||
$this->trackings,
|
||||
function (Tracking $existingTracking) use ($tracking) {
|
||||
return $existingTracking->title !== $tracking->title
|
||||
&& $existingTracking->value !== $tracking->value;
|
||||
@@ -276,16 +270,4 @@ class Checkout
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMetadata(): ?array
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
public function setMetadata(?array $metadata): static
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class PaypalGateway implements GatewayInterface
|
||||
$tracking->title = self::TRACKING_TITLE_ORDER;
|
||||
$tracking->value = $order['id'];
|
||||
|
||||
$checkout->addGatewayTracking($tracking);
|
||||
$checkout->addTracking($tracking);
|
||||
|
||||
foreach ($order['links'] as $linkData) {
|
||||
$linkType = \in_array($linkData['rel'], ['approve', 'payer-action'])
|
||||
@@ -88,7 +88,7 @@ class PaypalGateway implements GatewayInterface
|
||||
$link->method = $linkData['method'];
|
||||
$link->type = $linkType;
|
||||
|
||||
$checkout->addGatewayLink($link);
|
||||
$checkout->addLink($link);
|
||||
}
|
||||
|
||||
return $checkout;
|
||||
@@ -131,7 +131,7 @@ class PaypalGateway implements GatewayInterface
|
||||
$tracking->title = self::TRACKING_TITLE_TRANSACTION;
|
||||
$tracking->value = $purchaseUnit['payments']['captures'][0]['id'];
|
||||
|
||||
$checkout->addGatewayTracking($tracking);
|
||||
$checkout->addTracking($tracking);
|
||||
}
|
||||
|
||||
$checkout = $this->checkoutService->chargeCheckout($checkout);
|
||||
@@ -181,7 +181,7 @@ class PaypalGateway implements GatewayInterface
|
||||
$tracking->title = self::TRACKING_TITLE_TRANSACTION;
|
||||
$tracking->value = $purchaseUnit['payments']['captures'][0]['id'];
|
||||
|
||||
$checkout->addGatewayTracking($tracking);
|
||||
$checkout->addTracking($tracking);
|
||||
}
|
||||
|
||||
$checkout = $this->checkoutService->chargeCheckout($checkout);
|
||||
|
||||
@@ -76,13 +76,13 @@ class StripeGateway implements GatewayInterface
|
||||
$link->method = Request::METHOD_GET;
|
||||
$link->type = LinkType::Payment;
|
||||
|
||||
$checkout->addGatewayLink($link);
|
||||
$checkout->addLink($link);
|
||||
|
||||
$tracking = new Tracking();
|
||||
$tracking->title = self::TRACKING_TITLE_CHECKOUT;
|
||||
$tracking->value = $session->id;
|
||||
|
||||
$checkout->addGatewayTracking($tracking);
|
||||
$checkout->addTracking($tracking);
|
||||
|
||||
return $checkout;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use App\Gateway\CheckoutStatus;
|
||||
use App\Gateway\Gateway\CashGateway;
|
||||
use App\Gateway\Gateway\CecaGateway;
|
||||
use App\Gateway\Gateway\DropGateway;
|
||||
use App\Gateway\Gateway\PaypalGateway;
|
||||
use App\Gateway\Paypal\PaypalGateway;
|
||||
use App\Gateway\Stripe\StripeGateway;
|
||||
use App\Gateway\Tracking;
|
||||
use App\Gateway\Wallet\WalletGateway;
|
||||
@@ -120,7 +120,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
|
||||
$checkout->setGateway($this->getCheckoutGateway($record));
|
||||
|
||||
foreach ($this->getCheckoutTrackings($record) as $tracking) {
|
||||
$checkout->addGatewayTracking($tracking);
|
||||
$checkout->addTracking($tracking);
|
||||
}
|
||||
|
||||
$checkout->setMigrated(true);
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Repository\Gateway;
|
||||
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -25,17 +24,10 @@ class CheckoutRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @return Checkout|null
|
||||
*/
|
||||
public function findOneByTracking(string $title, string $value): array
|
||||
public function findOneByTracking(string $title, string $value): ?array
|
||||
{
|
||||
return $this->createQueryBuilder('g')
|
||||
->join('g.gatewayTrackings', 'gt', Join::WITH, 'gt.checkout = g.id')
|
||||
->andWhere('gt.value = :val')
|
||||
->andWhere('gt.title = :title')
|
||||
->setParameter('val', $value)
|
||||
->setParameter('title', $title)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
// TO-DO: Use a JSON lookup into the 'trackings' column to see if it contains title and value
|
||||
return null;
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
Reference in New Issue
Block a user