<?php
namespace App\Services\Transaction\Workflow\EventSubscriber\Internal\PaymentReturn;
use App\Services\Transaction\StatusManagement\ToSignTransactionComponent;
use App\Services\Transaction\FeeTransactionService;
use App\Services\Transaction\TransactionCancelService;
use App\Services\Transaction\TransactionReturnService;
use App\Entity\Transaction;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;
class OutboundTrxSubscriber implements EventSubscriberInterface
{
/**
* @var FeeTransactionService
*/
protected $feeTransactionService;
/**
* @var TransactionReturnService
*/
protected $trxReturnService;
public function __construct(
FeeTransactionService $feeTransactionService,
TransactionReturnService $trxReturnService,
TransactionCancelService $trxCancelService,
ToSignTransactionComponent $toSignTransactionComponent
) {
$this->feeTransactionService = $feeTransactionService;
$this->trxReturnService = $trxReturnService;
$this->trxCancelService = $trxCancelService;
$this->toSignTransactionComponent = $toSignTransactionComponent;
}
public static function getSubscribedEvents()
{
return [
'workflow.internal_payment_return_outbound.completed.reject' => 'cancelOutboundMainTrx',
];
}
public function cancelOutboundMainTrx(Event $event)
{
/** @var Transaction $pmtTrx */
$pmtTrx = $event->getSubject()->getEntity();
$isRejectedByBank = $event->getTransition()->getFroms()[0] == 'review';
if (
!$isRejectedByBank
&& ($pmtTrx->hasTypePayment() || $pmtTrx->hasTypePaymentReturn())
&& $pmtTrx->getOutbound() && $pmtTrx->isMoneyReleased()
) {
$this->trxReturnService->processSepaSentButRejectedTrx($pmtTrx);
}
$this->feeTransactionService->cancelFeeByMainTrx($pmtTrx);
}
}