From a396fdc9b67af95d8ffb959eec17a03e439efc19 Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Tue, 15 Apr 2025 11:35:38 +0200 Subject: [PATCH] Add charge status --- src/Entity/Gateway/Charge.php | 9 +++++---- src/EventListener/ChargeRefundListener.php | 11 ++++++----- src/Gateway/ChargeStatus.php | 14 ++++++++++++++ src/Gateway/CheckoutStatus.php | 4 ---- src/Gateway/Stripe/StripeGateway.php | 2 -- src/Service/Gateway/CheckoutService.php | 2 ++ 6 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 src/Gateway/ChargeStatus.php diff --git a/src/Entity/Gateway/Charge.php b/src/Entity/Gateway/Charge.php index 29dd3d1..41aaa07 100644 --- a/src/Entity/Gateway/Charge.php +++ b/src/Entity/Gateway/Charge.php @@ -6,8 +6,8 @@ use App\Entity\Accounting\Accounting; use App\Entity\Accounting\Transaction; use App\Entity\Money; use App\Entity\Project\Support; +use App\Gateway\ChargeStatus; use App\Gateway\ChargeType; -use App\Gateway\CheckoutStatus; use App\Mapping\Provider\EntityMapProvider; use App\Repository\Gateway\ChargeRepository; use AutoMapper\Attribute\MapProvider; @@ -84,11 +84,12 @@ class Charge */ #[Gedmo\Versioned] #[ORM\Column()] - private ?CheckoutStatus $status = null; + private ?ChargeStatus $status = null; public function __construct() { $this->transactions = new ArrayCollection(); + $this->status = ChargeStatus::Pending; } public function getId(): ?int @@ -204,12 +205,12 @@ class Charge return $this; } - public function getStatus(): ?CheckoutStatus + public function getStatus(): ?ChargeStatus { return $this->status; } - public function setStatus(CheckoutStatus $status): static + public function setStatus(ChargeStatus $status): static { $this->status = $status; diff --git a/src/EventListener/ChargeRefundListener.php b/src/EventListener/ChargeRefundListener.php index 37f8a7b..f7baa15 100644 --- a/src/EventListener/ChargeRefundListener.php +++ b/src/EventListener/ChargeRefundListener.php @@ -3,9 +3,9 @@ namespace App\EventListener; use App\Entity\Gateway\Charge; -use App\Gateway\AbstractGateway; -use App\Gateway\CheckoutStatus; +use App\Gateway\ChargeStatus; use App\Gateway\RefundStrategy; +use App\Gateway\Stripe\StripeGateway; use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener; use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Events; @@ -18,7 +18,7 @@ use Doctrine\ORM\Events; class ChargeRefundListener { public function __construct( - private AbstractGateway $gateway, + private StripeGateway $gateway, ) {} public function preUpdate(Charge $charge, PreUpdateEventArgs $args): void @@ -31,11 +31,12 @@ class ChargeRefundListener $oldStatus = $args->getOldValue($status); $newStatus = $args->getNewValue($status); - $charged = CheckoutStatus::Charged->value; - $toRefund = CheckoutStatus::ToRefund->value; + $charged = ChargeStatus::Charged->value; + $toRefund = ChargeStatus::ToRefund->value; if ($oldStatus === $charged && $newStatus === $toRefund) { if ($charge->getCheckout()->getRefundStrategy() != RefundStrategy::ToWallet) { $this->gateway->processRefund($charge); + $charge->setStatus(ChargeStatus::Refunded); } } } diff --git a/src/Gateway/ChargeStatus.php b/src/Gateway/ChargeStatus.php new file mode 100644 index 0000000..e25cda7 --- /dev/null +++ b/src/Gateway/ChargeStatus.php @@ -0,0 +1,14 @@ + $paymentIntent->id, 'amount' => $charge->getMoney()->amount, ]); - - $charge->setStatus(CheckoutStatus::Refunded); } } diff --git a/src/Service/Gateway/CheckoutService.php b/src/Service/Gateway/CheckoutService.php index f266363..f715722 100644 --- a/src/Service/Gateway/CheckoutService.php +++ b/src/Service/Gateway/CheckoutService.php @@ -6,6 +6,7 @@ use App\Controller\GatewaysController; use App\Entity\Accounting\Transaction; use App\Entity\Gateway\Charge; use App\Entity\Gateway\Checkout; +use App\Gateway\ChargeStatus; use App\Gateway\CheckoutStatus; use Symfony\Component\Routing\RouterInterface; @@ -101,6 +102,7 @@ class CheckoutService $transaction->setTarget($charge->getTarget()); $charge->addTransaction($transaction); + $charge->setStatus(ChargeStatus::Charged); } return $checkout;