<?php
namespace EADPlataforma\Controller\Website;
use EADPlataforma\Error\ActionInvalidException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use EADPlataforma\Error\AuthInvalidException;
use EADPlataforma\Error\FieldException;
use EADPlataforma\Error\NotFoundException;
use EADPlataforma\Response\HttpOk;
use EADPlataforma\Response\HttpNoContent;
use EADPlataforma\Entity\Configuration;
use EADPlataforma\Entity\Course;
use EADPlataforma\Entity\Lesson;
use EADPlataforma\Entity\Receiver;
use EADPlataforma\Entity\Library;
use EADPlataforma\Entity\Transaction;
use EADPlataforma\Entity\UserNotify;
use EADPlataforma\Enum\ServicesEnum;
use EADPlataforma\Enum\ClientEnum;
use EADPlataforma\Enum\CourseEnum;
use EADPlataforma\Enum\ConfigurationEnum;
use EADPlataforma\Enum\ContentTypeEnum;
use EADPlataforma\Enum\LibraryEnum;
use EADPlataforma\Enum\ErrorEnum;
/**
* @Route(
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class ServiceController extends AbstractWebsiteController {
/**
* @Route(
* path = "report/csp",
* name = "reportCsp",
* methods = {"POST"}
* )
*/
public function reportCsp(Request $request): Response
{
if($request->headers->get('Content-Type') != ContentTypeEnum::CSP_REPORT){
return new Response('Invalid CSP Report', Response::HTTP_BAD_REQUEST);
}
$content = $request->getContent();
$data = json_decode($content, true);
if(isset($data['csp-report'])){
$dataStr = "**REPORT**: {$data['csp-report']['document-uri']} \n";
unset($data['csp-report']['original-policy']);
unset($data['csp-report']['document-uri']);
unset($data['csp-report']['referrer']);
foreach ($data['csp-report'] as $key => $value) {
$dataStr .= "{$key}: {$value} \n";
}
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug-csp');
$discordService->setMessage($dataStr);
$discordService->sendDiscord();
return new Response(null, Response::HTTP_NO_CONTENT);
}
return new Response('Invalid CSP Report', Response::HTTP_BAD_REQUEST);
}
/**
* @Route(
* path = "notify/auth",
* name = "registerNotifyAuth",
* methods = {"POST"}
* )
*/
public function registerNotifyAuth(Request $request): Response
{
if(!$this->user){
return new Response('User not found', Response::HTTP_BAD_REQUEST);
}
$content = $request->getContent();
$data = json_decode($content, true);
if(
isset($data['endpoint']) &&
isset($data['platform']) &&
isset($data['token']) &&
isset($data['auth'])
){
$userNotify = $this->em->getRepository(UserNotify::class)->findOneBy([
"endpoint" => $data['endpoint'],
"token" => $data['token'],
"platform" => $data['platform'],
"auth" => $data['auth'],
]);
if($userNotify){
if($userNotify->getUser()->getId() != $this->user->getId()){
$userNotify->setUser($this->user);
$this->em->flush();
}
return new Response(null, Response::HTTP_NO_CONTENT);
}
$userNotify = new UserNotify();
$userNotify->setUser($this->user);
$userNotify->setEndpoint($data['endpoint']);
$userNotify->setToken($data['token']);
$userNotify->setAuth($data['auth']);
$userNotify->setPlatform($data['platform']);
$this->em->persist($userNotify);
$this->em->flush();
return new Response(null, Response::HTTP_NO_CONTENT);
}
return new Response('Invalid notify data', Response::HTTP_BAD_REQUEST);
}
/**
* @Route(
* path = "cart/RequestEadCheckout/",
* name = "processDataEadCheckoutBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "cart/RequestEadCheckout",
* name = "processDataEadCheckout",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataEadCheckout(Request $request) {
$processEad = $this->generalService->getService('Transaction\\ProcessEad');
$pagarMe = $this->generalService->getService('PagarMe\\PagarMe');
$this->requestUtil->setRequest($request)->setData();
$postbackPayload = $request->getContent();
$data = (object)$this->requestUtil->getData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$host = $request->headers->get('host');
if(stristr($host, "doubleh")){
$debug = true;
}
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("EAD Checkout - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processEad->setDebug($debug);
if($pagarMe->isPostValid($request) && isset($data->transaction['id'])){
try{
$processEad->processTransactionEAD($data->transaction['id']);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
}else{
return $this->eadResponse([
"success" => ErrorEnum::NO
], ErrorEnum::AUTH_INVALID, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "hotmart/",
* name = "processDataHotmartBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "hotmart",
* name = "processDataHotmart",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataHotmart(Request $request) {
$processHotmart = $this->generalService->getService('Transaction\\ProcessHotmart');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$data = (object)$this->requestUtil->getData();
if($debug){
$discordService->setMessage("Hotmart - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processHotmart->setDebug($debug);
try{
$processHotmart->processTransactionHotmart($data);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "paypal/",
* name = "processDataPayPalBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "paypal",
* name = "processDataPayPal",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataPayPal(Request $request) {
$processPayPal = $this->generalService->getService('Transaction\\ProcessPayPal');
$payPal = $this->generalService->getService('PayPal\\PayPal');
$this->requestUtil->setRequest($request)->setData();
$data = $this->requestUtil->getData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Paypal - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode((object)$data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processPayPal->setDebug($debug);
try{
if($payPal->isPostValid($data)){
$processPayPal->processTransactionPayPal((object)$data);
}
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "pagseguro/",
* name = "processDataPagSeguroBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "pagseguro",
* name = "processDataPagSeguro",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataPagSeguro(Request $request) {
$processPagSeguro = $this->generalService->getService('Transaction\\ProcessPagSeguro');
$pagSeguro = $this->generalService->getService('PagSeguro\\PagSeguro');
$this->requestUtil->setRequest($request)->setData();
$data = $this->requestUtil->getData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Pagseguro - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode((object)$data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processPagSeguro->setDebug($debug);
try{
if($pagSeguro->isPostValid($data)){
$processPagSeguro->processTransactionPagSeguro((object)$data);
}
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "eduzz/",
* name = "processDataEduzzBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "eduzz",
* name = "processDataEduzz",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataEduzz(Request $request) {
$processEduzz = $this->generalService->getService('Transaction\\ProcessEduzz');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Eduzz - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processEduzz->setDebug($debug);
try{
$processEduzz->processTransactionEduzz($data);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "provi/",
* name = "processDataProviBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "provi",
* name = "processDataProvi",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataProvi(Request $request) {
$processProvi = $this->generalService->getService('Transaction\\ProcessProvi');
$this->requestUtil->setRequest($request)->setData(true);
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Provi - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processProvi->setDebug($debug);
try{
$processProvi->processTransactionProvi($data);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "braip/",
* name = "processDataBraipBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "braip",
* name = "processDataBraip",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataBraip(Request $request) {
$processBraip = $this->generalService->getService('Transaction\\ProcessBraip');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Braip - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
try{
$processBraip->processTransactionBraip($data);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "monetizze/",
* name = "processDataMonetizzeBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "monetizze",
* name = "processDataMonetizze",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataMonetizze(Request $request) {
$processMonetizze = $this->generalService->getService('Transaction\\ProcessMonetizze');
$this->requestUtil->setRequest($request)->setData();
sleep(rand(1, 5));
try{
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
if(!empty($data->json)){
$data = json_decode($data->json, true);
$data = (object)$data;
}
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Monetizze - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
$processMonetizze->setDebug($debug);
$processMonetizze->processTransactionMonetizze($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "kiwify/",
* name = "processDataKiwifyBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "kiwify",
* name = "processDataKiwify",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataKiwify(Request $request) {
$processKiwify = $this->generalService->getService('Transaction\\ProcessKiwify');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Kiwify - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processKiwify->setDebug($debug);
try{
$processKiwify->processTransactionKiwify($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "dmguru/",
* name = "processDataDigitalManagerGuruBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "dmguru",
* name = "processDataDigitalManagerGuru",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataDigitalManagerGuru(Request $request) {
$processDigitalManagerGuru = $this->generalService->getService(
'Transaction\\ProcessDigitalManagerGuru'
);
$this->requestUtil->setRequest($request)->setData(true);
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Guru - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processDigitalManagerGuru->setDebug($debug);
try{
$processDigitalManagerGuru->processTransactionDigitalManagerGuru($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "appmax/",
* name = "processDataAppMaxBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "appmax",
* name = "processDataAppMax",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataAppMax(Request $request) {
$processAppMax = $this->generalService->getService('Transaction\\ProcessAppMax');
$this->requestUtil->setRequest($request)->setData(true);
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("AppMax - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processAppMax->setDebug($debug);
try{
$processAppMax->processTransactionAppMax($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "doppus/",
* name = "processDataDoppusBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "doppus",
* name = "processDataDoppus",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataDoppus(Request $request) {
$processDoppus = $this->generalService->getService('Transaction\\ProcessDoppus');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$token = $request->headers->get('doppus-token');
$content = json_decode($request->getContent());
$data = (object)$content;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Doppus - Start");
$discordService->sendDiscord();
$discordService->setMessage("Token: $token");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
if(empty($token)){
return $this->eadResponse([ "message" => "Token empty" ], ErrorEnum::AUTH_INVALID);
}
sleep(rand(1, 5));
$processDoppus->setDebug($debug);
try{
$processDoppus->processTransactionDoppus($data, $token);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "ticto/",
* name = "processDataTictoBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "ticto",
* name = "processDataTicto",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataTicto(Request $request) {
$processTicto = $this->generalService->getService('Transaction\\ProcessTicto');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Ticto - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processTicto->setDebug($debug);
try{
$processTicto->processTransactionTicto($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "mercadopago/",
* name = "processDataMercadoPagoBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "mercadopago",
* name = "processDataMercadoPago",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataMercadoPago(Request $request) {
$processMercadoPago = $this->generalService->getService(
'Transaction\\ProcessMercadoPago'
);
$mercadoPago = $this->generalService->getService('MercadoPago\\MercadoPago');
$this->requestUtil->setRequest($request)->setData();
$data = $this->requestUtil->getData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("MercadoPago - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode((object)$data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processMercadoPago->setDebug($debug);
try{
if(!$mercadoPago->isPostValid($data)){
throw new ActionInvalidException("Only transaction requests are allowed.");
}
$processMercadoPago->processTransactionMercadoPago((object)$data);
} catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "abmex/",
* name = "processDataAbmexBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "abmex",
* name = "processDataAbmex",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataAbmex(Request $request) {
$processAbmex = $this->generalService->getService('Transaction\\ProcessAbmex');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Abmex - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processAbmex->setDebug($debug);
try{
$processAbmex->processTransactionAbmex($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "perfectpay/",
* name = "processDataPerfectPayBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "perfectpay",
* name = "processDataPerfectPay",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataPerfectPay(Request $request) {
$processPerfectPay = $this->generalService->getService(
'Transaction\\ProcessPerfectPay'
);
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("PerfectPay - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processPerfectPay->setDebug($debug);
try{
$processPerfectPay->processTransactionPerfectPay($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "evermart/",
* name = "processDataEvermartBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "evermart",
* name = "processDataEvermart",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataEvermart(Request $request) {
$processEvermart = $this->generalService->getService('Transaction\\ProcessEvermart');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Evermart - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processEvermart->setDebug($debug);
try{
$processEvermart->processTransactionEvermart($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "herospark/",
* name = "processDataHeroSparkBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "herospark",
* name = "processDataHeroSpark",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataHeroSpark(Request $request) {
$processHeroSpark = $this->generalService->getService('Transaction\\ProcessHeroSpark');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("HeroSpark - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processHeroSpark->setDebug($debug);
try{
$processHeroSpark->processTransactionHeroSpark($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "yampi/",
* name = "processDataYampi",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "yampi",
* name = "processDataYampiBar",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataYampi(Request $request) {
$processYampi = $this->generalService->getService('Transaction\\ProcessYampi');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Yampi - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processYampi->setDebug($debug);
try{
$processYampi->processTransactionYampi($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "cartpanda/",
* name = "processDataCartPanda",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "cartpanda",
* name = "processDataCartPandaBar",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataCartPanda(Request $request) {
$processCartPanda = $this->generalService->getService('Transaction\\ProcessCartPanda');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("CartPanda - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
sleep(rand(1, 5));
$processCartPanda->setDebug($debug);
try{
$processCartPanda->processTransactionCartPanda($data);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "kirvano/",
* name = "processDataKirvano",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "kirvano",
* name = "processDataKirvanoBar",
* methods = {"GET","POST","PUT"}
* )
*/
public function processDataKirvano(Request $request) {
$processKirvano = $this->generalService->getService('Transaction\\ProcessKirvano');
$this->requestUtil->setRequest($request)->setData();
$debug = (int)$request->get('debug') == ServicesEnum::YES;
$data = (object)$this->requestUtil->getData();
$token = $request->headers->get('security-token');
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("Kirvano - Start");
$discordService->sendDiscord();
$discordService->setMessage("Token: $token");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($data));
$discordService->sendDiscord();
}
if(empty($token)){
return $this->eadResponse([ "message" => "Token empty" ], ErrorEnum::AUTH_INVALID);
}
sleep(rand(1, 5));
$processKirvano->setDebug($debug);
try{
$processKirvano->processTransactionKirvano($data, $token);
}catch (\Exception $e) {
if($debug){
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
return $this->eadResponse([
"success" => ErrorEnum::NO,
"message" => $e->getMessage(),
], ErrorEnum::INTERNAL_ERROR, true, true);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "callback/rdstation/",
* name = "callbackRdStationBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "callback/rdstation",
* name = "callbackRdStation",
* methods = {"GET","POST","PUT"}
* )
*/
public function callbackRdStation(Request $request){
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$this->requestUtil->setRequest($request)->setData();
$tokenClient = $this->requestUtil->getField('token');
if (empty($tokenClient)) {
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if ($this->clientConfig->getToken() != $tokenClient) {
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$code = $this->requestUtil->getField('code');
//$debug = (int)$request->get('debug') == ServicesEnum::YES;
$debug = true;
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
if($debug){
$discordService->setMessage("RDStation - Start");
$discordService->sendDiscord();
$discordService->setMessage(json_encode($code));
$discordService->sendDiscord();
}
$rdService = $this->generalService->getService('Marketing\\RdStationService');
$rdService->setDebug($debug);
if(!empty($code)){
$this->configuration->set('rdstation_code', $code);
$this->configuration->set("app_rd_user", ConfigurationEnum::YES);
$this->configuration->set("app_rd_product", ConfigurationEnum::YES);
$this->configuration->set("app_rd_course", ConfigurationEnum::YES);
$this->configuration->set("app_rd_payment", ConfigurationEnum::YES);
$this->configuration->set("app_rd_subscription", ConfigurationEnum::YES);
$this->configuration->set("app_rd_group", ConfigurationEnum::YES);
$this->configuration->set("app_rd_enrollment", ConfigurationEnum::YES);
$rdService->getTokenAccess($code);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "callback/bling/",
* name = "callbackBlingBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "callback/bling",
* name = "callbackBling",
* methods = {"GET","POST","PUT"}
* )
*/
public function callbackBling(Request $request){
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$debug = true;
$token = $request->headers->get('X-AUTH-TOKEN');
if($debug){
$discordService->setMessage("Bling - Start");
$discordService->sendDiscord();
$discordService->setMessage("Token: " . $token);
$discordService->sendDiscord();
}
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$this->requestUtil->setRequest($request)->setData();
$tokenClient = $this->requestUtil->getField('token');
if($debug){
$discordService->setMessage("Token Client: " . $tokenClient);
$discordService->setMessage("Token Client Config: " . $this->clientConfig->getToken());
$discordService->sendDiscord();
}
if(empty($tokenClient)){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($this->clientConfig->getToken() != $tokenClient){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$code = $this->requestUtil->getField('code');
if($debug){
$discordService->setMessage("Código: " . $code);
$discordService->sendDiscord();
}
$blingAuthorization = $this->generalService->getService(
'Transaction\\Invoice\\BlingAuthorization'
);
$blingAuthorization->setDebug($debug);
if(!empty($code)){
$this->configuration->set('bling_code', $code);
$blingAuthorization->getTokenAccess($code);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "callback/dinamize/",
* name = "callbackDinamizeBar",
* methods = {"GET","POST","PUT"}
* )
* @Route(
* path = "callback/dinamize",
* name = "callbackDinamize",
* methods = {"GET","POST","PUT"}
* )
*/
public function callbackDinamize(Request $request){
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$this->requestUtil->setRequest($request)->setData();
$tokenClient = $this->requestUtil->getField('token');
if (empty($tokenClient)) {
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if ($this->clientConfig->getToken() != $tokenClient) {
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$code = $this->requestUtil->getField('code');
if(!empty($code)){
$this->configuration->set('dinamize_token', $code);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "/client/info/{clientToken}",
* name = "getClientInfo",
* methods = {"GET"}
* )
*/
public function getClientInfo(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$fileService = $this->generalService->getService('FileService');
$diskInfo = $fileService->getClientSpaceDisk();
$courseRepository = $this->em->getRepository(Course::class);
$coursesNumber = $courseRepository->countAllCourses();
$coursesNumberPublish = $courseRepository->countAllCourses(CourseEnum::PUBLISHED);
return $this->eadResponse([
"coursesNumber" => $coursesNumber,
"coursesNumberPublish" => $coursesNumberPublish,
"diskRemaining" => $diskInfo->diskRemaining,
"diskUsed" => $diskInfo->diskUsed,
"diskTotal" => $diskInfo->diskTotal,
"diskRemainingText" => $diskInfo->diskRemainingText,
"diskUsedText" => $diskInfo->diskUsedText,
"diskTotalText" => $diskInfo->diskTotalText,
"diskPercent" => $diskInfo->diskPercent,
]);
}
/**
* @Route(
* path = "/client/downgrade/free/{clientToken}",
* name = "downgradeToFree",
* methods = {"GET"}
* )
*/
public function downgradeToFree(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$fileService = $this->generalService->getService('FileService');
$diskInfo = $fileService->getClientSpaceDisk();
if($diskInfo->diskUsed >= ServicesEnum::MIN_SIZE_PLAN){
return $this->eadResponse([
"message" => "Disk Size"
], ErrorEnum::ACTION_INVALID);
}
$domain = $this->client->getDomainSecondary();
if(!empty($domain)){
$error = $this->em->getRepository(Configuration::class)->deleteClientDomain($domain);
if($error){
return $this->eadResponse([
"message" => "Custom Domain"
], ErrorEnum::ACTION_INVALID);
}
$token = $this->generalService->getTokenCron();
$linkEadmin = "https://connect.eadplataforma.com/app/park";
$params = "/{$token}/{$this->clientConfig->getToken()}/{$domain}/remove";
file_get_contents($linkEadmin . $params);
$this->client->setDomainSecondary('');
$this->clientConfig->setRedirect(ConfigurationEnum::NO);
$this->emEadmin->flush();
$this->em->flush();
}
$this->em->getRepository(Course::class)->updateCoursesToDraft();
$this->em->getRepository(Receiver::class)->resetReceiversToDefault();
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "/client/upgrade/receivers/{clientToken}",
* name = "upgradeReceivers",
* methods = {"GET"}
* )
*/
public function upgradeReceivers(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($this->configuration->isTrial()){
return $this->eadResponse(null, ErrorEnum::ACTION_INVALID);
}
$this->em->getRepository(Receiver::class)->resetReceiversToClientDefault();
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "/remove/client/domain/{clientToken}",
* name = "removeClientCustomDomain",
* methods = {"DELETE"}
* )
*/
public function removeClientCustomDomain(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$domain = $this->client->getDomainSecondary();
if(empty($domain)){
return $this->eadResponse(null, ErrorEnum::ACTION_INVALID);
}
$configurationRepository = $this->em->getRepository(Configuration::class);
$error = $configurationRepository->deleteClientDomain($domain);
if($error){
return $this->eadResponse([ "message" => $error ], ErrorEnum::ACTION_INVALID);
}
return $this->eadResponse([ "success" => ErrorEnum::YES ]);
}
/**
* @Route(
* path = "/recover/transaction/item/{clientToken}",
* name = "recoverTransactionItem",
* methods = {"GET"}
* )
*/
public function recoverTransactionItem(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$transactionRepository = $this->em->getRepository(Transaction::class);
$transactions = $transactionRepository->getTransactionWithoutItem();
foreach ($transactions as $key => $transaction) {
$transactionRepository->processTransaction($transaction, true, true, true, true);
}
return $this->eadResponse([
"success" => ErrorEnum::YES,
"count" => count($transactions),
]);
}
/**
* @Route(
* path = "/send/cron/{clientToken}",
* name = "sendCron",
* methods = {"GET"}
* )
*/
public function sendCron(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse([
"message" => "Auth Invalid"
], ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse([
"message" => "Auth Invalid"
], ErrorEnum::AUTH_INVALID);
}
$platformStatus = $this->clientConfig->getPlatformStatus();
$suspended = ClientEnum::PLATFORM_STATUS_SUSPENDED;
$canceled = ClientEnum::PLATFORM_STATUS_CANCELED;
if($platformStatus == $suspended || $platformStatus == $canceled){
return $this->eadResponse([
"message" => "Plafatorma suspensa"
], ErrorEnum::ACTION_INVALID);
}
$cronUrl = "https://{$this->eadDomain}/general/{$this->clientConfig->getToken()}";
$sqsService = $this->generalService->getService('Aws\\AwsSqs');
$info = $sqsService->sendMessageCron($cronUrl);
if($info->error){
return $this->eadResponse([
"message" => $info->message
], ErrorEnum::ACTION_INVALID);
}
return $this->eadResponse([
"success" => ErrorEnum::YES,
]);
}
/**
* @Route(
* path = "/run/updater/{clientToken}",
* name = "runUpdater",
* methods = {"GET"}
* )
*/
public function runUpdater(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
}
$databaseManagerService = $this->generalService->getService('DatabaseManagerService');
$databaseManagerService->executeMigrations(true);
return $this->eadResponse([
"success" => ErrorEnum::YES,
]);
}
/**
* @Route(
* path = "/info",
* name = "getInfo",
* methods = {"GET"}
* )
*/
public function getInfo(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
throw new AuthInvalidException('Auth Invalid');
}
$domains = [
$this->client->getDomainPrimary(),
];
if(!empty($this->client->getDomainSecondary())){
$domains[] = $this->client->getDomainSecondary();
}
$plan = $this->configuration->getPlan();
$limit = (int)$this->clientConfig->getLimitSimultaneousAccess();
if(empty($limit)){
$limit = $plan->getLimitSimultaneousAccess();
}
$data = [
"id" => $this->client->getClientId(),
"planId" => $plan->getId(),
"planTitle" => $plan->getTitle(),
"urls" => $domains,
"limit" => $limit,
];
return new HttpOk($data);
}
/**
* @Route(
* path = "/info/course/{clientToken}",
* name = "getInfoCourse",
* methods = {"GET"}
* )
*/
public function getInfoCourse(Request $request)
{
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
throw new AuthInvalidException('Auth Invalid');
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
throw new AuthInvalidException('Auth Invalid');
}
$courseRepository = $this->em->getRepository(Course::class);
$courses = $courseRepository->findBy([
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
$data = [];
foreach ($courses as $key => $course) {
$data[] = (object)[
"title" => $course->getTitle(),
];
}
return new HttpOk($data);
}
/**
* @Route(
* path = "/genereate/eadmin/sso/{clientToken}",
* name = "genereateAdminSSO",
* methods = {"POST"}
* )
*
* @throws ActionInvalidException
* @throws FieldException
*/
public function genereateAdminSSO(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
throw new AuthInvalidException('Auth Invalid');
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
throw new AuthInvalidException('Auth Invalid');
}
$userId = $this->requestUtil->getField('userId');
if(empty($userId)){
throw new FieldException("FieldException", [ "userId" => "User cannot be empty" ]);
}
$url = $this->requestUtil->getField('url');
$domain = $request->getHost();
$signDomain = $this->generalService->signDataWithExpiration(md5($domain));
$signId = $this->generalService->signDataWithExpiration(md5($userId));
$data = [
"url" => "https://{$domain}/login/eadmin/sso/{$signId}/{$signDomain}?url={$url}",
];
return new HttpOk($data);
}
/**
* @Route(
* path = "/update/live/{clientToken}/{liveId}",
* name = "updateLive",
* methods = {"PATCH"}
* )
*
* @throws AuthInvalidException
* @throws ActionInvalidException
* @throws FieldException
* @throws NotFoundException
*/
public function updateLive(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
throw new AuthInvalidException('Auth Invalid');
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
throw new AuthInvalidException('Auth Invalid');
}
$liveId = $request->get('liveId');
if(empty($liveId)){
throw new FieldException("FieldException", [ "liveId" => "Live cannot be empty" ]);
}
$libraryRepository = $this->em->getRepository(Library::class);
$library = $libraryRepository->findOneBy([
"vdocipherVideoId" => $liveId
]);
if(!$library){
throw new NotFoundException("NotFoundException");
}
$videoId = $library->getVdocipherVideoId();
if(empty($videoId)){
throw new NotFoundException("NotFoundException");
}
try{
$vdocipherService = $this->generalService->getService('VdocipherService');
$videoData = $vdocipherService->getVideo($videoId);
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$discordService->setMessage(json_encode($videoData));
$discordService->sendDiscord();
$vdocipherService->addTagInVideo($videoId, "B{$library->getId()}");
$vdocipherService->addTagInVideo($videoId, "video");
$library->setOrigin(LibraryEnum::RECORD);
$library->setType(LibraryEnum::CONTENT_VIDEO_FILE);
$library->setFileName("EADLIVE_RECORD_{$library->getLiveStart('d_m_Y')}.mp4");
$library->setFileSize($videoData->totalSizeBytes);
$library->setFileExtension('mp4');
$dateTimeUtil = $this->generalService->getUtil('DateTimeUtil');
$duration = $dateTimeUtil->secToTime($videoData->length);
$library->setDuration($duration);
$this->em->flush();
}catch (\Exception $e){
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
throw new ActionInvalidException($e->getMessage());
}
return new HttpNoContent;
}
/**
* @Route(
* path = "/meet/record/{clientToken}/{lessonId}",
* name = "meetRecordRegister",
* methods = {"POST"}
* )
*
* @throws AuthInvalidException
* @throws ActionInvalidException
* @throws FieldException
* @throws NotFoundException
*/
public function meetRecordRegister(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$token = $request->headers->get('X-AUTH-TOKEN');
if($token != $this->generalService->getTokenCron()){
throw new AuthInvalidException('Auth Invalid');
}
if($request->get('clientToken') != $this->clientConfig->getToken()){
throw new AuthInvalidException('Auth Invalid');
}
$lessonId = $request->get('lessonId');
if(empty($lessonId)){
throw new FieldException("FieldException", [ "lessonId" => "Lesson cannot be empty" ]);
}
$lessonRepository = $this->em->getRepository(Lesson::class);
$lesson = $lessonRepository->findOneBy([
"id" => $lessonId
]);
if(!$lesson){
throw new NotFoundException("NotFoundException");
}
$librarySave = $lesson->getLibrary();
if(!$librarySave){
throw new NotFoundException("NotFoundException");
}
$videoLink = $this->requestUtil->getField('videoLink');
$duration = (int)$this->requestUtil->getField('duration');
if(empty($videoLink)){
throw new FieldException("FieldException", [ "videoLink" => "VideoLink cannot be empty" ]);
}
if(empty($duration)){
throw new FieldException("FieldException", [ "duration" => "Duration cannot be empty" ]);
}
$vdocipherService = $this->generalService->getService('VdocipherService');
$videoId = $vdocipherService->getCreateVideoByUrl($videoLink);
if(empty($videoId)){
throw new ActionInvalidException("ActionInvalidException");
}
try{
$library = new Library();
$today = date('d_m_Y_H:i:s');
$libraryTitle = "EADMEET_RECORD_{$today}";
$library->setUser($librarySave->getUser());
$library->setOrigin(LibraryEnum::RECORD);
$library->setType(LibraryEnum::CONTENT_VIDEO_FILE);
$library->setStatus(LibraryEnum::PUBLISHED);
$library->setFileExtension("mp4");
$library->setTitle($libraryTitle);
$library->setLink($videoId);
$library->setVdocipherVideoId($videoId);
$library->setRecordLibrary($librarySave);
$library->setFileName("{$libraryTitle}.mp4");
$dateTimeUtil = $this->generalService->getUtil('DateTimeUtil');
$duration = $dateTimeUtil->secToTime($duration);
$library->setDuration($duration);
$this->em->persist($library);
$this->em->flush();
$data = $library->toReturn();
$this->userLogService->logInsert("library", $library->getId(), $data);
$vdocipherService->addTagInVideo($videoId, "B{$library->getId()}");
$vdocipherService->addTagInVideo($videoId, "video");
$vdocipherService->addTagInVideo($videoId, "meet");
$vdocipherService->addTagInVideo($videoId, $this->client->getClientId());
}catch (\Exception $e){
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
throw new ActionInvalidException($e->getMessage());
}
return new HttpNoContent;
}
}