Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace HiEvents\Services\Application\Handlers\Order;
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\Exceptions\RefundNotPossibleException;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Services\Application\Handlers\Order\DTO\RefundOrderDTO;
use HiEvents\Services\Application\Handlers\Order\Payment\Offline\RefundOfflineOrderHandler;
use HiEvents\Services\Application\Handlers\Order\Payment\Stripe\RefundOrderHandler as RefundStripeOrderHandler;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Throwable;
class RefundOrderHandler
{
public function __construct(
private readonly OrderRepositoryInterface $orderRepository,
private readonly RefundStripeOrderHandler $refundStripeOrderHandler,
private readonly RefundOfflineOrderHandler $refundOfflineOrderHandler,
) {}
/**
* @throws RefundNotPossibleException
* @throws Throwable
*/
public function handle(RefundOrderDTO $refundOrderDTO): OrderDomainObject
{
$order = $this->orderRepository->findFirstWhere([
OrderDomainObjectAbstract::EVENT_ID => $refundOrderDTO->event_id,
OrderDomainObjectAbstract::ID => $refundOrderDTO->order_id,
]);
if (! $order) {
throw new ResourceNotFoundException(__('Order :id not found for event :eventId', [
'id' => $refundOrderDTO->order_id,
'eventId' => $refundOrderDTO->event_id,
]));
}
if ($order->isPaidOutsidePlatform()) {
return $this->refundOfflineOrderHandler->handle($refundOrderDTO);
}
return $this->refundStripeOrderHandler->handle($refundOrderDTO);
}
}