diff --git a/hesabixCore/src/Controller/AdminController.php b/hesabixCore/src/Controller/AdminController.php index 4fcb8fb..7b0d575 100644 --- a/hesabixCore/src/Controller/AdminController.php +++ b/hesabixCore/src/Controller/AdminController.php @@ -140,7 +140,7 @@ class AdminController extends AbstractController { return $this->json($entityManager->getRepository(Business::class)->countAll()); } - + #[Route('/api/admin/users/count', name: 'admin_users_count')] public function admin_users_count(Extractor $extractor, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response { @@ -148,13 +148,13 @@ class AdminController extends AbstractController } #[Route('/api/admin/business/search', name: 'admin_business_list_search')] - public function admin_business_list_search(Extractor $extractor,Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response + public function admin_business_list_search(Extractor $extractor, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response { $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - $items = $entityManager->getRepository(Business::class)->findByPage($params['options']['page'],$params['options']['rowsPerPage'],$params['search']); + $items = $entityManager->getRepository(Business::class)->findByPage($params['options']['page'], $params['options']['rowsPerPage'], $params['search']); $resp = []; foreach ($items as $item) { $temp = []; @@ -173,13 +173,13 @@ class AdminController extends AbstractController } #[Route('/api/admin/users/search', name: 'admin_users_list_search')] - public function admin_users_list_search(Extractor $extractor,Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response + public function admin_users_list_search(Extractor $extractor, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response { $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - $items = $entityManager->getRepository(User::class)->findByPage($params['options']['page'],$params['options']['rowsPerPage'],$params['search']); + $items = $entityManager->getRepository(User::class)->findByPage($params['options']['page'], $params['options']['rowsPerPage'], $params['search']); $resp = []; foreach ($items as $item) { $temp = []; @@ -340,23 +340,25 @@ class AdminController extends AbstractController } #[Route('/api/admin/settings/system/info', name: 'admin_settings_system_info')] - public function admin_settings_system_info(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response + public function admin_settings_system_info(registryMGR $registryMGR, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response { $item = $entityManager->getRepository(Settings::class)->findAll()[0]; $resp = []; $resp['keywords'] = $item->getSiteKeywords(); $resp['description'] = $item->getDiscription(); $resp['scripts'] = $item->getScripts(); - $resp['zarinpal'] = $item->getZarinpalMerchant(); + $resp['zarinpal'] = $registryMGR->get('system', key: 'zarinpalKey');; $resp['footerScripts'] = $item->getFooterScripts(); $resp['appSite'] = $item->getAppSite(); $resp['footer'] = $item->getFooter(); + $resp['activeGateway'] = $registryMGR->get('system', key: 'activeGateway'); + $resp['parsianGatewayAPI'] = $registryMGR->get('system', key: 'parsianGatewayAPI'); return $this->json($resp); } #[Route('/api/admin/settings/system/info/save', name: 'admin_settings_system_info_save')] - public function admin_settings_system_info_save(EntityManagerInterface $entityManager, Request $request): Response + public function admin_settings_system_info_save(registryMGR $registryMGR, EntityManagerInterface $entityManager, Request $request): Response { $params = []; if ($content = $request->getContent()) { @@ -367,10 +369,12 @@ class AdminController extends AbstractController $item->setSiteKeywords($params['keywords']); $item->setDiscription($params['description']); $item->setScripts($params['scripts']); - $item->setZarinpalMerchant($params['zarinpal']); + $registryMGR->update('system', 'zarinpalKey', $params['zarinpal']); $item->setFooterScripts($params['footerScripts']); $item->setAppSite($params['appSite']); $item->setFooter($params['footer']); + $registryMGR->update('system', 'activeGateway', $params['activeGateway']); + $registryMGR->update('system', 'parsianGatewayAPI', $params['parsianGatewayAPI']); $entityManager->persist($item); $entityManager->flush(); return $this->json(['result' => 1]); @@ -561,7 +565,7 @@ class AdminController extends AbstractController ]); } #[Route('/api/admin/logs/last', name: 'api_admin_logs_last')] - public function api_admin_logs_last(Extractor $extractor,Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse + public function api_admin_logs_last(Extractor $extractor, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse { $logs = $entityManager->getRepository(\App\Entity\Log::class)->findBy([], ['id' => 'DESC'], 250); $temps = []; @@ -583,16 +587,16 @@ class AdminController extends AbstractController } #[Route('/api/admin/onlineusers/list', name: 'api_admin_online_users_list')] - public function api_admin_online_users_list(Extractor $extractor,Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse + public function api_admin_online_users_list(Extractor $extractor, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse { $tokens = $entityManager->getRepository(UserToken::class)->getOnlines(120); $res = []; - foreach($tokens as $token){ + foreach ($tokens as $token) { $res[] = [ 'name' => $token->getUser()->getFullName(), - 'email'=>$token->getUser()->getEmail(), - 'mobile'=>$token->getUser()->getMobile(), - 'lastActive'=>$token->getLastActive() - time(), + 'email' => $token->getUser()->getEmail(), + 'mobile' => $token->getUser()->getMobile(), + 'lastActive' => $token->getLastActive() - time(), ]; } return $this->json($res); @@ -621,16 +625,16 @@ class AdminController extends AbstractController public function script2(EntityManagerInterface $entitymanager): JsonResponse { $banks = $entitymanager->getRepository(BankAccount::class)->findAll(); - foreach( $banks as $bank ){ - if($bank->getMoney() == null){ + foreach ($banks as $bank) { + if ($bank->getMoney() == null) { $bank->setMoney($bank->getBid()->getMoney()); $entitymanager->persist($bank); } } $items = $entitymanager->getRepository(Cashdesk::class)->findAll(); - foreach( $items as $item ){ - if($item->getMoney() == null){ + foreach ($items as $item) { + if ($item->getMoney() == null) { $item->setMoney($item->getBid()->getMoney()); $entitymanager->persist($bank); } diff --git a/hesabixCore/src/Controller/ArchiveController.php b/hesabixCore/src/Controller/ArchiveController.php index c4ec04d..6e54653 100644 --- a/hesabixCore/src/Controller/ArchiveController.php +++ b/hesabixCore/src/Controller/ArchiveController.php @@ -9,6 +9,7 @@ use App\Service\Access; use App\Service\Jdate; use App\Service\Log; use App\Service\Notification; +use App\Service\PayMGR; use App\Service\Provider; use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; @@ -25,41 +26,42 @@ use Symfony\Component\String\Slugger\SluggerInterface; class ArchiveController extends AbstractController { - private function getArchiveInfo(EntityManagerInterface $entityManager,array $acc){ + private function getArchiveInfo(EntityManagerInterface $entityManager, array $acc) + { $orders = $entityManager->getRepository(ArchiveOrders::class)->findBy([ - 'bid'=>$acc['bid'], - 'status'=>100 + 'bid' => $acc['bid'], + 'status' => 100 ]); $totalSize = 0; - foreach ($orders as $order){ - if($order->getExpireDate()>= time()) + foreach ($orders as $order) { + if ($order->getExpireDate() >= time()) $totalSize += $order->getOrderSize(); } $usedSize = 0; - $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid'=>$acc['bid']]); + $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid' => $acc['bid']]); foreach ($files as $file) $usedSize += $file->getFileSize(); return [ 'size' => $totalSize * 1024, - 'remain'=>($totalSize * 1024) - $usedSize, - 'used'=>$usedSize + 'remain' => ($totalSize * 1024) - $usedSize, + 'used' => $usedSize ]; } #[Route('/api/archive/info', name: 'app_archive_info')] - public function app_archive_info(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_info(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); - $resp = $this->getArchiveInfo($entityManager,$acc); + $resp = $this->getArchiveInfo($entityManager, $acc); return $this->json($resp); } #[Route('/api/archive/order/settings', name: 'app_archive_order_settings')] - public function app_archive_order_settings(twigFunctions $functions,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_order_settings(twigFunctions $functions, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $settings = $functions->systemSettings(); return $this->json([ @@ -68,150 +70,90 @@ class ArchiveController extends AbstractController } #[Route('/api/archive/order/submit', name: 'app_archive_order_submit')] - public function app_archive_order_submit(twigFunctions $functions,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_order_submit(PayMGR $payMGR, twigFunctions $functions, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - + $settings = $functions->systemSettings(); $order = new ArchiveOrders(); $order->setBid($acc['bid']); $order->setSubmitter($this->getUser()); $order->setDateSubmit(time()); - $order->setGatePay('zarinpal'); + $order->setPrice($params['space'] * $params['month'] * $settings->getStoragePrice()); $order->setDes('خرید سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month'] . ' ماه '); - - $settings = $functions->systemSettings(); - if(array_key_exists('space',$params) && array_key_exists('month',$params)){ - $order->setPrice($params['space'] * $params['month'] * $settings->getStoragePrice()); - $order->setOrderSize($params['space']); - $order->setMonth($params['month']); + $order->setOrderSize($params['space']); + $order->setMonth($params['month']); + $entityManager->persist($order); + $entityManager->flush(); + $result = $payMGR->createRequest($order->getPrice(), $this->generateUrl('api_archive_buy_verify', ["id"=>$order->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'خرید فضای ابری'); + if ($result['Success']) { + $order->setGatePay($result['gate']); + $entityManager->persist($order); + $entityManager->flush(); + $log->insert('سرویس فضای ابری', 'صدور فاکتور سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month'] . ' ماه ', $this->getUser(), $acc['bid']); } - else - throw $this->createAccessDeniedException(); - $data = array("merchant_id" => $settings->getZarinpalMerchant(), - "amount" => $order->getPrice(), - "callback_url" => $this->generateUrl('api_archive_buy_verify',[],UrlGeneratorInterface::ABSOLUTE_URL), - "description" => 'خرید سرویس فضای ابری', - ); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - - $result = curl_exec($ch); - $err = curl_error($ch); - $result = json_decode($result, true, JSON_PRETTY_PRINT); - curl_close($ch); - if ($err) { - throw $this->createAccessDeniedException($err); - } else { - if (empty($result['errors'])) { - if ($result['data']['code'] == 100) { - $order->setStatus(0); - $order->setVerifyCode($result['data']['authority']); - $entityManager->persist($order); - $entityManager->flush(); - $log->insert('سرویس فضای ابری','صدور فاکتور سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month']. ' ماه ' ,$this->getUser(),$acc['bid']); - return $this->json([ - 'authority' => $result['data']["authority"] - ]); - } - } - } - throw $this->createAccessDeniedException(); + return $this->json($result); } - #[Route('/api/archive/buy/verify', name: 'api_archive_buy_verify')] - public function api_archive_buy_verify(twigFunctions $functions,Notification $notification,Request $request,EntityManagerInterface $entityManager,Log $log): Response + #[Route('/api/archive/buy/verify/{id}', name: 'api_archive_buy_verify')] + public function api_archive_buy_verify(string $id, PayMGR $payMGR, twigFunctions $functions, Notification $notification, Request $request, EntityManagerInterface $entityManager, Log $log): Response { - $Authority = $request->get('Authority'); - $req = $entityManager->getRepository(ArchiveOrders::class)->findOneBy(['verifyCode'=>$Authority]); - //get system settings - $settings = $functions->systemSettings(); - $data = array("merchant_id" => $settings->getZarinpalMerchant(), "authority" => $Authority, "amount" => $req->getPrice()); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v4'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); + $req = $entityManager->getRepository(ArchiveOrders::class)->find($id); + if (!$req) + throw $this->createNotFoundException(''); - $result = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - $result = json_decode($result, true); - - //----------------------------------- - - //----------------------------------- - if ($err) { - $log->insert('سرویس فضای ابری','پرداخت ناموفق سرویس فضای ابری' ,$this->getUser(),$req->getBid()); - return $this->render('buy/fail.html.twig', ['results'=>$result]); + $res = $payMGR->verify($req->getPrice(), $id, $request); + if ($res['Success'] == false) { + $log->insert('سرویس فضای ابری', 'پرداخت ناموفق سرویس فضای ابری', $this->getUser(), $req->getBid()); + return $this->render('buy/fail.html.twig', ['results' => $res]); } else { - if(array_key_exists('code',$result['data'])){ - if ($result['data']['code'] == 100) { - $req->setStatus(100); - $req->setRefID($result['data']['ref_id']); - $req->setCardPan($result['data']['card_pan']); - $req->setExpireDate(time() + ($req->getMonth() * 30 * 24 * 60 * 60)); - $entityManager->persist($req); - $entityManager->flush(); - $log->insert( - 'سرویس فضای ابری', - 'پرداخت موفق فاکتور سرویس فضای ابری', - $req->getSubmitter(), - $req->getBid() - ); - $notification->insert(' فاکتور فضای ابری پرداخت شد.','/acc/sms/panel',$req->getBid(),$req->getSubmitter()); - return $this->render('buy/success.html.twig',['req'=>$req]); - } - } - $notification->insert('پرداخت فاکتور فضای ابری ناموفق بود','/',$req->getBid(),$req->getSubmitter()); - $log->insert('سرویس پیامک','پرداخت ناموفق فاکتور فضای ابری' ,$this->getUser(),$req->getBid()); - return $this->render('buy/fail.html.twig', ['results'=>$result]); + $req->setStatus(100); + $req->setRefID($res['refID']); + $req->setCardPan($res['card_pan']); + $req->setExpireDate(time() + ($req->getMonth() * 30 * 24 * 60 * 60)); + $entityManager->persist($req); + $entityManager->flush(); + $log->insert( + 'سرویس فضای ابری', + 'پرداخت موفق فاکتور سرویس فضای ابری', + $req->getSubmitter(), + $req->getBid() + ); + $notification->insert(' فاکتور فضای ابری پرداخت شد.', '/acc/sms/panel', $req->getBid(), $req->getSubmitter()); + return $this->render('buy/success.html.twig', ['req' => $req]); } } #[Route('/api/archive/list/{cat}', name: 'app_archive_list')] - public function app_archive_list(string $cat,Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_list(string $cat, Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('archiveUpload'); - if(!$acc) + if (!$acc) $acc = $access->hasRole('archiveMod'); - if(!$acc) + if (!$acc) $acc = $access->hasRole('archiveDelete'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); - if($cat == 'all') - $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid'=>$acc['bid']]); + if ($cat == 'all') + $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid' => $acc['bid']]); else - $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid'=>$acc['bid'],'cat'=>$cat]); + $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid' => $acc['bid'], 'cat' => $cat]); $resp = []; - foreach ($files as $file){ + foreach ($files as $file) { $temp = []; - $temp['id']=$file->getId(); - $temp['filename']=$file->getFilename(); - $temp['fileType']=$file->getFileType(); - $temp['submitter']=$file->getSubmitter()->getFullName(); - $temp['dateSubmit']=$jdate->jdate('Y/n/d H:i',$file->getDateSubmit()); - $temp['filePublicls']=$file->isPublic(); - $temp['cat']=$file->getCat(); - $temp['filesize']=$file->getFileSize(); + $temp['id'] = $file->getId(); + $temp['filename'] = $file->getFilename(); + $temp['fileType'] = $file->getFileType(); + $temp['submitter'] = $file->getSubmitter()->getFullName(); + $temp['dateSubmit'] = $jdate->jdate('Y/n/d H:i', $file->getDateSubmit()); + $temp['filePublicls'] = $file->isPublic(); + $temp['cat'] = $file->getCat(); + $temp['filesize'] = $file->getFileSize(); $resp[] = $temp; } @@ -219,41 +161,42 @@ class ArchiveController extends AbstractController } #[Route('/api/archive/orders/list', name: 'app_archive_orders_list')] - public function app_archive_orders_list(Jdate $jdate, Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_orders_list(Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('join'); if (!$acc) throw $this->createAccessDeniedException(); $orders = $entityManager->getRepository(ArchiveOrders::class)->findBy([ - 'bid'=>$acc['bid'] - ],['id'=>'DESC']); - $resp = $provider->ArrayEntity2Array($orders,0); - foreach ($resp as &$item){ - $item['dateSubmit'] = $jdate->jdate('Y/n/d H:i',$item['dateSubmit']); + 'bid' => $acc['bid'] + ], ['id' => 'DESC']); + $resp = $provider->ArrayEntity2Array($orders, 0); + foreach ($resp as &$item) { + $item['dateSubmit'] = $jdate->jdate('Y/n/d H:i', $item['dateSubmit']); } return $this->json($resp); } #[Route('/api/archive/file/upload', name: 'app_archive_file_upload')] - public function app_archive_file_upload(Jdate $jdate, Provider $provider,SluggerInterface $slugger,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_file_upload(Jdate $jdate, Provider $provider, SluggerInterface $slugger, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('archiveUpload'); if (!$acc) throw $this->createAccessDeniedException(); - $info = $this->getArchiveInfo($entityManager,$acc); + $info = $this->getArchiveInfo($entityManager, $acc); $uploadedFile = $request->files->get('image'); if ($uploadedFile) { $originalFilename = pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME); // this is needed to safely include the file name as part of the URL $safeFilename = $slugger->slug($originalFilename); - $newFilename = $safeFilename.'-'.uniqid().'.'.$uploadedFile->guessExtension(); + $newFilename = $safeFilename . '-' . uniqid() . '.' . $uploadedFile->guessExtension(); // Move the file to the directory where brochures are stored try { $uploadedFile->move( $this->getParameter('archiveTempMediaDir'), $newFilename - );} catch (FileException $e) { + ); + } catch (FileException $e) { // ... handle exception if something happens during file upload return $this->json("error"); } @@ -261,21 +204,21 @@ class ArchiveController extends AbstractController // updates the 'brochureFilename' property to store the PDF file name // instead of its contents //$product->setBrochureFilename($newFilename); - return $this->json(['name'=>$newFilename]); + return $this->json(['name' => $newFilename]); } } #[Route('/api/archive/file/save', name: 'app_archive_file_save')] - public function app_archive_file_save(Jdate $jdate, Provider $provider,SluggerInterface $slugger,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_file_save(Jdate $jdate, Provider $provider, SluggerInterface $slugger, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('archiveUpload'); if (!$acc) throw $this->createAccessDeniedException(); - foreach ($request->get('added_media') as $item){ - if (file_exists(__DIR__ . '/../../../hesabixArchive/temp/'.$item) ){ - $size = ceil(filesize(__DIR__ . '/../../../hesabixArchive/temp/'.$item)/(1024*1024)); - $info = $this->getArchiveInfo($entityManager,$acc); - if($info['size'] < ($info['used'] + $size)) - return $this->json(['result'=>'nem']); + foreach ($request->get('added_media') as $item) { + if (file_exists(__DIR__ . '/../../../hesabixArchive/temp/' . $item)) { + $size = ceil(filesize(__DIR__ . '/../../../hesabixArchive/temp/' . $item) / (1024 * 1024)); + $info = $this->getArchiveInfo($entityManager, $acc); + if ($info['size'] < ($info['used'] + $size)) + return $this->json(['result' => 'nem']); $file = new ArchiveFile(); $file->setBid($acc['bid']); $file->setDateSubmit(time()); @@ -285,89 +228,89 @@ class ArchiveController extends AbstractController $file->setDes($request->get('des')); $file->setCat($request->get('cat')); //set file type - $mimFile = mime_content_type(__DIR__ . '/../../../hesabixArchive/temp/'.$item); + $mimFile = mime_content_type(__DIR__ . '/../../../hesabixArchive/temp/' . $item); $file->setFileType($mimFile); - $file->setFileSize(ceil(filesize(__DIR__ . '/../../../hesabixArchive/temp/'.$item)/(1024*1024))); - rename(__DIR__ . '/../../../hesabixArchive/temp/'.$item,__DIR__ . '/../../../hesabixArchive/'.$item); + $file->setFileSize(ceil(filesize(__DIR__ . '/../../../hesabixArchive/temp/' . $item) / (1024 * 1024))); + rename(__DIR__ . '/../../../hesabixArchive/temp/' . $item, __DIR__ . '/../../../hesabixArchive/' . $item); $file->setRelatedDocType($request->get('doctype')); $file->setRelatedDocCode($request->get('docid')); $entityManager->persist($file); $entityManager->flush(); - $log->insert('آرشیو','فایل با نام ' . $file->getFilename() . ' افزوده شد.',$this->getUser(),$acc['bid']); + $log->insert('آرشیو', 'فایل با نام ' . $file->getFilename() . ' افزوده شد.', $this->getUser(), $acc['bid']); } } return $this->json([ - 'ok'=>'ok' + 'ok' => 'ok' ]); } #[Route('/api/archive/files/list', name: 'app_archive_file_list')] - public function app_archive_file_list(Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_archive_file_list(Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('archiveView'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } $files = $entityManager->getRepository(ArchiveFile::class)->findBy([ - 'bid'=>$acc['bid'], - 'relatedDocType'=>$params['type'], - 'relatedDocCode'=>$params['id'] + 'bid' => $acc['bid'], + 'relatedDocType' => $params['type'], + 'relatedDocCode' => $params['id'] ]); echo $request->get('type'); $resp = []; - foreach ($files as $file){ + foreach ($files as $file) { $temp = []; - $temp['id']=$file->getId(); - $temp['filename']=$file->getFilename(); - $temp['fileType']=$file->getFileType(); - $temp['submitter']=$file->getSubmitter()->getFullName(); - $temp['dateSubmit']=$jdate->jdate('Y/n/d H:i',$file->getDateSubmit()); - $temp['filePublicls']=$file->isPublic(); - $temp['cat']=$file->getCat(); - $temp['filesize']=$file->getFileSize(); + $temp['id'] = $file->getId(); + $temp['filename'] = $file->getFilename(); + $temp['fileType'] = $file->getFileType(); + $temp['submitter'] = $file->getSubmitter()->getFullName(); + $temp['dateSubmit'] = $jdate->jdate('Y/n/d H:i', $file->getDateSubmit()); + $temp['filePublicls'] = $file->isPublic(); + $temp['cat'] = $file->getCat(); + $temp['filesize'] = $file->getFileSize(); $resp[] = $temp; } return $this->json($resp); } #[Route('/api/archive/file/get/{id}', name: 'app_archive_file_get')] - public function app_archive_file_get(string $id,Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): BinaryFileResponse + public function app_archive_file_get(string $id, Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): BinaryFileResponse { $acc = $access->hasRole('archiveView'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $file = $entityManager->getRepository(ArchiveFile::class)->find($id); - if(! $file) + if (!$file) throw $this->createNotFoundException(); - if($acc['bid']->getId() != $file->getBid()->getId()) + if ($acc['bid']->getId() != $file->getBid()->getId()) throw $this->createAccessDeniedException(); - $fileAdr = __DIR__ . '/../../../hesabixArchive/'. $file->getFilename(); + $fileAdr = __DIR__ . '/../../../hesabixArchive/' . $file->getFilename(); $response = new BinaryFileResponse($fileAdr); return $response; } #[Route('/api/archive/file/remove/{id}', name: 'app_archive_file_remove')] - public function app_archive_file_remove(string $id,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_archive_file_remove(string $id, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('archiveDelete'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $file = $entityManager->getRepository(ArchiveFile::class)->find($id); - if(! $file) + if (!$file) throw $this->createNotFoundException(); - if($acc['bid']->getId() != $file->getBid()->getId()) + if ($acc['bid']->getId() != $file->getBid()->getId()) throw $this->createAccessDeniedException(); - $fileAdr = __DIR__ . '/../../../hesabixArchive/'. $file->getFilename(); + $fileAdr = __DIR__ . '/../../../hesabixArchive/' . $file->getFilename(); unlink($fileAdr); $entityManager->remove($file); $entityManager->flush(); - $log->insert('آرشیو','فایل با نام ' . $file->getFilename() . ' حذف شد.',$this->getUser(),$acc['bid']); - return $this->json(['result'=>1]); + $log->insert('آرشیو', 'فایل با نام ' . $file->getFilename() . ' حذف شد.', $this->getUser(), $acc['bid']); + return $this->json(['result' => 1]); } } diff --git a/hesabixCore/src/Controller/PluginController.php b/hesabixCore/src/Controller/PluginController.php index 6e6f945..8103adb 100644 --- a/hesabixCore/src/Controller/PluginController.php +++ b/hesabixCore/src/Controller/PluginController.php @@ -9,9 +9,12 @@ use App\Entity\Settings; use App\Service\Access; use App\Service\Jdate; use App\Service\Log; +use App\Service\PayMGR; +use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -19,164 +22,119 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class PluginController extends AbstractController { #[Route('/api/plugin/get/info/{id}', name: 'api_plugin_get_info')] - public function api_plugin_get_info(String $id,Access $access, Jdate $jdate, EntityManagerInterface $entityManager,Log $log): JsonResponse + public function api_plugin_get_info(string $id, Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $item = $entityManager->getRepository(PluginProdect::class)->findOneBy([ - 'code'=>$id + 'code' => $id ]); return $this->json($item); } #[Route('/api/plugin/insert/{id}', name: 'api_plugin_insert')] - public function api_plugin_insert(String $id,Access $access,EntityManagerInterface $entityManager): Response + public function api_plugin_insert(string $id, Log $log, twigFunctions $twigFunctions, PayMGR $payMGR, Access $access, EntityManagerInterface $entityManager): Response { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $pp = $entityManager->getRepository(PluginProdect::class)->find($id); - if(!$pp) + if (!$pp) throw $this->createNotFoundException('plugin not found'); //get system settings - $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; - $data = array("merchant_id" => $settings->getZarinpalMerchant(), - "amount" => ($pp->getPrice() * 109)/10, - "callback_url" => $this->generateUrl('api_plugin_buy_verify',[],UrlGeneratorInterface::ABSOLUTE_URL), - "description" => $pp->getName(), - ); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - - $result = curl_exec($ch); - $err = curl_error($ch); - $result = json_decode($result, true, JSON_PRETTY_PRINT); - curl_close($ch); - if ($err) { - throw $this->createAccessDeniedException($err); - } else { - if (empty($result['errors'])) { - if ($result['data']['code'] == 100) { - $plugin = new Plugin(); - $plugin->setBid($acc['bid']); - $plugin->setSubmitter($this->getUser()); - $plugin->setDateSubmit(time()); - $plugin->setGatePay('zarinpal'); - $plugin->setVerifyCode($result['data']['authority']); - $plugin->setStatus(0); - $plugin->setDes($pp->getName()); - $plugin->setName($pp->getCode()); - $plugin->setPrice(($pp->getPrice() * 109)/10); - $plugin->setDateExpire(time() + $pp->getTimestamp()); - $entityManager->persist($plugin); - $entityManager->flush(); - return $this->json([ - 'authority'=> $result['data']["authority"] - ]); - } - } else { - throw $this->createAccessDeniedException(); - } + $settings = $twigFunctions->systemSettings(); + $plugin = new Plugin(); + $plugin->setBid($acc['bid']); + $plugin->setSubmitter($this->getUser()); + $plugin->setDateSubmit(time()); + $plugin->setStatus(0); + $plugin->setDes($pp->getName()); + $plugin->setName($pp->getCode()); + $plugin->setPrice(($pp->getPrice() * 109) / 10); + $plugin->setDateExpire(time() + $pp->getTimestamp()); + $entityManager->persist($plugin); + $entityManager->flush(); + $result = $payMGR->createRequest(($pp->getPrice() * 109) / 10, $this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'خرید فضای ابری'); + if ($result['Success']) { + $plugin->setGatePay($result['gate']); + $plugin->setVerifyCode($result['authkey']); + $entityManager->persist($plugin); + $entityManager->flush(); + $entityManager->persist($plugin); + $entityManager->flush(); + $log->insert('بازار افزونه‌ها', 'صدور فاکتور افزونه ' . $pp->getName(), $this->getUser(), $acc['bid']); } + return $this->json($result); } - #[Route('/api/plugin/buy/verify', name: 'api_plugin_buy_verify')] - public function api_plugin_buy_verify(\Symfony\Component\HttpFoundation\Request $request,EntityManagerInterface $entityManager,Log $log): Response + + #[Route('/api/plugin/buy/verify/{id}', name: 'api_plugin_buy_verify')] + public function api_plugin_buy_verify(string $id, twigFunctions $twigFunctions, PayMGR $payMGR, Request $request, EntityManagerInterface $entityManager, Log $log): Response { - $Authority = $request->get('Authority'); - $status = $request->get('Status'); - $req = $entityManager->getRepository(Plugin::class)->findOneBy(['verifyCode'=>$Authority]); - //get system settings - $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; - $data = array("merchant_id" => $settings->getZarinpalMerchant(), "authority" => $Authority, "amount" => $req->getPrice()); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v4'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - - $result = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - $result = json_decode($result, true); - - //----------------------------------- - - //----------------------------------- - if ($err) { - return $this->render('buy/fail.html.twig', ['results'=>$result]); + $req = $entityManager->getRepository(Plugin::class)->find($id); + $res = $payMGR->verify($req->getPrice(), $id, $request); + if ($res['Success'] == false) { + $log->insert( + 'بازار افزونه‌ها' . $req->getName(), + 'پرداخت ناموفق صورت‌حساب خرید افزونه', + $req->getSubmitter(), + $req->getBid() + ); + return $this->render('buy/fail.html.twig', ['results' => $res]); } else { - if(array_key_exists('code',$result['data'])){ - if ($result['data']['code'] == 100) { - $req->setStatus(100); - $req->setRefID($result['data']['ref_id']); - $req->setCardPan($result['data']['card_pan']); - $entityManager->persist($req); - $entityManager->flush(); - $log->insert( - 'افزونه ' . $req->getName(), - 'افزونه جدید خریداری و فعال شد.', - $req->getSubmitter(), - $req->getBid() - ); - return $this->render('buy/success.html.twig',['req'=>$req]); - } - } - return $this->render('buy/fail.html.twig', ['results'=>$result]); + $req->setStatus(100); + $req->setRefID($res['refID']); + $req->setCardPan($res['card_pan']); + $entityManager->persist($req); + $entityManager->flush(); + $log->insert( + 'افزونه ' . $req->getName(), + 'افزونه جدید خریداری و فعال شد.', + $req->getSubmitter(), + $req->getBid() + ); + return $this->render('buy/success.html.twig', ['req' => $req]); } } #[Route('/api/plugin/get/actives', name: 'api_plugin_get_actives')] - public function api_plugin_get_actives(Access $access, Jdate $jdate, EntityManagerInterface $entityManager,Log $log): JsonResponse + public function api_plugin_get_actives(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $plugins = $entityManager->getRepository(Plugin::class)->findActivePlugins($acc['bid']); $temp = []; - foreach ($plugins as $plugin){ - $plugin->setDateExpire($jdate->jdate('Y/n/d',$plugin->getDateExpire())); + foreach ($plugins as $plugin) { + $plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire())); $temp[$plugin->getName()] = $plugin; } return $this->json($temp); } #[Route('/api/plugin/get/paids', name: 'api_plugin_get_paids')] - public function api_plugin_get_paids(Access $access, Jdate $jdate, EntityManagerInterface $entityManager,Log $log): JsonResponse + public function api_plugin_get_paids(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $plugins = $entityManager->getRepository(Plugin::class)->findBy([ - 'bid'=>$acc['bid'], + 'bid' => $acc['bid'], ]); $temp = []; - foreach ($plugins as $plugin){ - $plugin->setDateExpire($jdate->jdate('Y/n/d',$plugin->getDateExpire())); - $plugin->setDateSubmit($jdate->jdate('Y/n/d',$plugin->getDateSubmit())); + foreach ($plugins as $plugin) { + $plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire())); + $plugin->setDateSubmit($jdate->jdate('Y/n/d', $plugin->getDateSubmit())); $plugin->setPrice(number_format($plugin->getPrice())); } return $this->json($plugins); } #[Route('/api/plugin/get/all', name: 'api_plugin_get_all')] - public function api_plugin_get_all(Access $access, Jdate $jdate, EntityManagerInterface $entityManager,Log $log): JsonResponse + public function api_plugin_get_all(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse { $acc = $access->hasRole('join'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $plugins = $entityManager->getRepository(PluginProdect::class)->findAll(); return $this->json($plugins); diff --git a/hesabixCore/src/Controller/SMSController.php b/hesabixCore/src/Controller/SMSController.php index 141229f..1cb4114 100644 --- a/hesabixCore/src/Controller/SMSController.php +++ b/hesabixCore/src/Controller/SMSController.php @@ -11,10 +11,12 @@ use App\Service\Access; use App\Service\Jdate; use App\Service\Log; use App\Service\Notification; +use App\Service\PayMGR; use App\Service\PluginService; use App\Service\Provider; use App\Service\registryMGR; use App\Service\SMS; +use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -104,7 +106,7 @@ class SMSController extends AbstractController } #[Route('/api/sms/charge', name: 'api_sms_charge')] - public function api_sms_charge(Log $log, Notification $notification, Request $request, Access $access, EntityManagerInterface $entityManager): JsonResponse + public function api_sms_charge(PayMGR $payMGR, Log $log, registryMGR $registryMGR, Request $request, Access $access, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('owner'); if (!$acc) @@ -116,108 +118,50 @@ class SMSController extends AbstractController if (!array_key_exists('price', $params)) throw $this->createAccessDeniedException('price not set'); - //get system settings - $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; - $data = array( - "merchant_id" => $settings->getZarinpalMerchant(), - "amount" => $params['price'], - "callback_url" => $this->generateUrl('api_sms_buy_verify', [], UrlGeneratorInterface::ABSOLUTE_URL), - "description" => 'افزایش اعتبار سرویس پیامک', - ); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); + $smsPay = new SMSPays(); + $smsPay->setBid($acc['bid']); + $smsPay->setDateSubmit(time()); + $smsPay->setSubmitter($this->getUser()); + $smsPay->setDes('افزایش اعتبار سرویس پیامک'); + $smsPay->setPrice($params['price']); + $smsPay->setStatus(0); + $entityManager->persist($smsPay); + $entityManager->flush(); - $result = curl_exec($ch); - $err = curl_error($ch); - $result = json_decode($result, true, JSON_PRETTY_PRINT); - curl_close($ch); - if ($err) { - throw $this->createAccessDeniedException($err); - } else { - if (empty($result['errors'])) { - if ($result['data']['code'] == 100) { - $smsPay = new SMSPays(); - $smsPay->setBid($acc['bid']); - $smsPay->setDateSubmit(time()); - $smsPay->setSubmitter($this->getUser()); - $smsPay->setDes('افزایش اعتبار سرویس پیامک'); - $smsPay->setPrice($params['price']); - $smsPay->setStatus(0); - $smsPay->setVerifyCode($result['data']['authority']); - $smsPay->setGatePay('zarinpal'); - $entityManager->persist($smsPay); - $entityManager->flush(); - $log->insert('سرویس پیامک', 'صدور فاکتور شارژ سرویس پیامک', $this->getUser(), $acc['bid']); - return $this->json([ - 'authority' => $result['data']["authority"] - ]); - } - } + $result = $payMGR->createRequest($params['price'], $this->generateUrl('api_sms_buy_verify', ['id' => $smsPay->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'افزایش اعتبار سرویس پیامک'); + if ($result['Success']) { + $smsPay->setVerifyCode($result['authkey']); + $smsPay->setGatePay($result['gate']); + $entityManager->persist($smsPay); + $entityManager->flush(); + $log->insert('سرویس پیامک', 'صدور فاکتور شارژ سرویس پیامک', $this->getUser(), $acc['bid']); } - throw $this->createAccessDeniedException(); + return $this->json($result); } - #[Route('/api/sms/buy/verify', name: 'api_sms_buy_verify')] - public function api_sms_buy_verify(Notification $notification, Request $request, EntityManagerInterface $entityManager, Log $log): Response + #[Route('/api/sms/buy/verify/{id}', name: 'api_sms_buy_verify')] + public function api_sms_buy_verify(string $id, PayMGR $payMGR, twigFunctions $twigFunctions, Notification $notification, Request $request, EntityManagerInterface $entityManager, Log $log): Response { - $Authority = $request->get('Authority'); - $status = $request->get('Status'); - $req = $entityManager->getRepository(SMSPays::class)->findOneBy(['verifyCode' => $Authority]); - //get system settings - $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; - $data = array("merchant_id" => $settings->getZarinpalMerchant(), "authority" => $Authority, "amount" => $req->getPrice()); - $jsonData = json_encode($data); - $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); - curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v4'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData) - )); - - $result = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - $result = json_decode($result, true); - - //----------------------------------- - - //----------------------------------- - if ($err) { + $req = $entityManager->getRepository(SMSPays::class)->find($id); + $res = $payMGR->verify($req->getPrice(), $id, $request); + if ($res['Success'] == false) { $log->insert('سرویس پیامک', 'پرداخت ناموفق شارژ سرویس پیامک', $this->getUser(), $req->getBid()); - return $this->render('buy/fail.html.twig', ['results' => $result]); + return $this->render('buy/fail.html.twig', ['results' => $res]); } else { - if (array_key_exists('code', $result['data'])) { - if ($result['data']['code'] == 100) { - $req->setStatus(100); - $req->setRefID($result['data']['ref_id']); - $req->setCardPan($result['data']['card_pan']); - $req->getBid()->setSmsCharge($req->getBid()->getSmsCharge() + ($req->getPrice() / 1.09)); - $entityManager->persist($req); - $entityManager->flush(); - $log->insert( - 'سرویس پیامک', - 'افزایش اعتبار سرویس پیامک به مبلغ: ' . $req->getPrice() . ' ریال ', - $req->getSubmitter(), - $req->getBid() - ); - $notification->insert(' سرویس پیامک شارژ شد.', '/acc/sms/panel', $req->getBid(), $req->getSubmitter()); - return $this->render('buy/success.html.twig', ['req' => $req]); - } - } - $notification->insert('پرداخت فاکتور شارژ سرویس پیامک ناموفق بود', '/', $req->getBid(), $req->getSubmitter()); - $log->insert('سرویس پیامک', 'پرداخت ناموفق شارژ سرویس پیامک', $this->getUser(), $req->getBid()); - return $this->render('buy/fail.html.twig', ['results' => $result]); + $req->setStatus(100); + $req->setRefID($res['refID']); + $req->setCardPan($res['card_pan']); + $req->getBid()->setSmsCharge($req->getBid()->getSmsCharge() + ($req->getPrice() / 1.09)); + $entityManager->persist($req); + $entityManager->flush(); + $log->insert( + 'سرویس پیامک', + 'افزایش اعتبار سرویس پیامک به مبلغ: ' . $req->getPrice() . ' ریال ', + $req->getSubmitter(), + $req->getBid() + ); + $notification->insert(' سرویس پیامک شارژ شد.', '/acc/sms/panel', $req->getBid(), $req->getSubmitter()); + return $this->render('buy/success.html.twig', ['req' => $req]); } } @@ -238,7 +182,7 @@ class SMSController extends AbstractController 'id' => $id, 'bid' => $bid, 'type' => 'sell', - 'money'=> $acc['money'] + 'money' => $acc['money'] ]); if (!$doc) return $this->json(['result' => 3]); diff --git a/hesabixCore/src/Service/PayMGR.php b/hesabixCore/src/Service/PayMGR.php new file mode 100644 index 0000000..1cea697 --- /dev/null +++ b/hesabixCore/src/Service/PayMGR.php @@ -0,0 +1,161 @@ + false, + ]; + $activeGateway = $this->registry->get('system', 'activeGateway'); + if ($activeGateway == 'zarinpal') { + $data = array( + "merchant_id" => $this->registry->get('system', 'zarinpalKey'), + "amount" => $price, + "callback_url" => $callback_url, + "description" => $des, + ); + $jsonData = json_encode($data); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); + curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($jsonData) + )); + + $result = curl_exec($ch); + $err = curl_error($ch); + $result = json_decode($result, true, JSON_PRETTY_PRINT); + curl_close($ch); + if ($err) { + + } else { + if (empty($result['errors'])) { + if ($result['data']['code'] == 100) { + $res['code'] = 100; + $res['Success'] = true; + $res['gate'] = 'zarinpal'; + $res['message'] = $result['data']['message']; + $res['authkey'] = $result['data']['authority']; + $res['targetURL'] = 'https://www.zarinpal.com/pg/StartPay/' . $result['data']['authority']; + } + } + } + } elseif ($activeGateway == 'pec') { + ini_set("soap.wsdl_cache_enabled", "0"); + $url = "https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?WSDL"; + $params = array( + "LoginAccount" => $this->registry->get('system', 'parsianGatewayAPI'), + "Amount" => $price, + "OrderId" => $orderID, + "CallBackUrl" => $callback_url, + "AdditionalData" => '', + "Originator" => '' + ); + $client = new \SoapClient($url); + try { + $result = $client->SalePaymentRequest(array( + "requestData" => $params + )); + if ($result->SalePaymentRequestResult->Token && $result->SalePaymentRequestResult->Status === 0) { + $res['code'] = 100; + $res['Success'] = true; + $res['gate'] = 'zarinpal'; + $res['message'] = 'OK'; + $res['authkey'] = $result->SalePaymentRequestResult->Token; + $res['targetURL'] = 'https://pec.shaparak.ir/NewIPG/?Token=' . $result->SalePaymentRequestResult->Token; + } + } catch (\Exception $ex) { + + } + } + return $res; + } + + + public function verify($price,$token, Request $request): array + { + $res = [ + 'Success' => false + ]; + $activeGateway = $this->registry->get('system', 'activeGateway'); + if ($activeGateway == 'zarinpal') { + $Authority = $request->get('Authority'); + $data = array("merchant_id" => $this->registry->get('system', 'zarinpalKey'), "authority" => $Authority, "amount" => $price); + $jsonData = json_encode($data); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); + curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v4'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($jsonData) + )); + + $result = curl_exec($ch); + $err = curl_error($ch); + curl_close($ch); + $result = json_decode($result, true); + + if ($err) { + return $res; + } else { + if (array_key_exists('code', $result['data'])) { + if ($result['data']['code'] == 100) { + $res['Success'] = true; + $res['status'] = 100; + $res['refID'] = $result['data']['ref_id']; + $res['card_pan'] = $result['data']['card_pan']; + return $res; + } + } + } + } elseif ($activeGateway == 'pec') { + $confirmUrl = 'https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL'; + $params = array( + "LoginAccount" => $this->registry->get('system', 'parsianGatewayAPI'), + "Token" => $token + ); + + $client = new \SoapClient($confirmUrl); + + $result = $client->ConfirmPayment(array( + "requestData" => $params + )); + if ($result->ConfirmPaymentResult->Status == '0') { + $res['Success'] = true; + $res['status'] = 100; + $res['refID'] = $_POST ["RRN"]; + $res['card_pan'] = $result->CardNumberMasked; + } + } + return $res; + } +} \ No newline at end of file