<?php
namespace App\Services\Transaction\Workflow\EventSubscriber\Fps\Outbound;
use App\Services\Transaction\StatusManagement\ToSignTransactionComponent;
use App\Services\Transaction\Fee\PaymentFeeService;
use App\Services\Transaction\FeeTransactionService;
use App\Services\Transaction\TransactionCancelService;
use App\Entity\Transaction;
use BrokerAction\DTO\TransactionMessage\MessageComponent\Payload;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;
class OutboundTrxSubscriber implements EventSubscriberInterface
{
/**
* @var TransactionCancelService
*/
protected $trxCancelService;
/**
* @var FeeTransactionService
*/
protected $feeTransactionService;
/**
* @var PaymentFeeService
*/
private $paymentFeeService;
public function __construct(
TransactionCancelService $trxReadyToClearComponent,
FeeTransactionService $feeTransactionService,
ToSignTransactionComponent $toSignTransactionComponent,
PaymentFeeService $paymentFeeService
) {
$this->trxCancelService = $trxReadyToClearComponent;
$this->feeTransactionService = $feeTransactionService;
$this->toSignTransactionComponent = $toSignTransactionComponent;
$this->paymentFeeService = $paymentFeeService;
}
public static function getSubscribedEvents()
{
return [
'workflow.starling_payment_outbound.completed.set_reserved' => 'makeOutboundTrx',
'workflow.starling_payment_outbound.enter.rejected' => 'cancelOutboundMainTrx',
];
}
public function makeOutboundTrx(Event $event)
{
/** @var Transaction $mainTransaction */
$mainTransaction = $event->getSubject()->getEntity();
$product = $mainTransaction->getProduct();
if ($product->debtorPaysFee() && !$mainTransaction->isDropFees()) {
$this->paymentFeeService->createOutbound(new Payload(['transaction_id' => $mainTransaction->getId()]));
}
}
public function cancelOutboundMainTrx(Event $event)
{
/** @var Transaction $pmtTrx */
$mainTransaction = $event->getSubject()->getEntity();
$this->feeTransactionService->cancelFeeByMainTrx($mainTransaction);
}
}