Add charge status

This commit is contained in:
cmorenov1402
2025-04-15 11:35:38 +02:00
parent ecb1ee796e
commit a396fdc9b6
6 changed files with 27 additions and 15 deletions
+5 -4
View File
@@ -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;
+6 -5
View File
@@ -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);
}
}
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace App\Gateway;
enum ChargeStatus: string
{
case Pending = 'pending';
case Charged = 'charged';
case ToRefund = 'to_refund';
case Refunded = 'refunded';
}
-4
View File
@@ -7,8 +7,4 @@ enum CheckoutStatus: string
case Pending = 'pending';
case Charged = 'charged';
case ToRefund = 'to_refund';
case Refunded = 'refunded';
}
-2
View File
@@ -234,7 +234,5 @@ class StripeGateway extends AbstractGateway
'payment_intent' => $paymentIntent->id,
'amount' => $charge->getMoney()->amount,
]);
$charge->setStatus(CheckoutStatus::Refunded);
}
}
+2
View File
@@ -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;