Add charge status
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Gateway;
|
||||
|
||||
enum ChargeStatus: string
|
||||
{
|
||||
case Pending = 'pending';
|
||||
|
||||
case Charged = 'charged';
|
||||
|
||||
case ToRefund = 'to_refund';
|
||||
|
||||
case Refunded = 'refunded';
|
||||
}
|
||||
@@ -7,8 +7,4 @@ enum CheckoutStatus: string
|
||||
case Pending = 'pending';
|
||||
|
||||
case Charged = 'charged';
|
||||
|
||||
case ToRefund = 'to_refund';
|
||||
|
||||
case Refunded = 'refunded';
|
||||
}
|
||||
|
||||
@@ -234,7 +234,5 @@ class StripeGateway extends AbstractGateway
|
||||
'payment_intent' => $paymentIntent->id,
|
||||
'amount' => $charge->getMoney()->amount,
|
||||
]);
|
||||
|
||||
$charge->setStatus(CheckoutStatus::Refunded);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user