<?php
namespace App\Controller\Cronjob\SubTransactions;
use App\Repository\SubTransactions\StreamMastersRepository;
use App\Service\SettingService;
use App\Service\StreamMasterApi;
use App\Service\TransactionService;
use App\Service\Util\NotificationService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class StreamMastersController extends AbstractController
{
public TransactionService $transaction;
public function __construct(TransactionService $transaction)
{
$this->transaction = $transaction;
}
#[Route('/cronjob/sub/transactions/stream-masters', name: 'app_cronjob_stream_master_cron')]
public function index(StreamMastersRepository $repository , EntityManagerInterface $managerRegistry,NotificationService $notificationService)
{
$settingObject = new SettingService($managerRegistry);
$api = new StreamMasterApi();
foreach ($repository->findBy(['isPaid' => false]) as $payment4Object) {
$res = $api->getPaymentStatus($settingObject->getSetting('streamMaster_token'),$payment4Object->getRefId());
if ($res['status'] == 'success'){
try {
$user = $payment4Object->getOwner();
$amount = $payment4Object->getPrice();
$setting = new SettingService($managerRegistry);
$payment4Object->setIsPaid(true);
$this->transaction->createTransaction($user, $amount, "افزایش اعتبار کیف پول - درگاه استریم مستر-
{$amount}
تومان
- پیگیری : "
. $payment4Object->getRefId(), 1, 0, null, 0, null, 'StreamMaster', null, null);
$managerRegistry->flush();
$managerRegistry->clear();
} catch (\Exception $exception) {
$notificationService->exception($exception);
// $this->telegram->exception($exception);
}
}
}
return $this->json(['res' => true]);
}
}