almost finish bank card export part and pec gatepay

This commit is contained in:
Hesabix 2025-02-08 21:49:28 +00:00
parent af3d3a9c06
commit 779e422909
8 changed files with 392 additions and 205 deletions

View file

@ -93,6 +93,7 @@ class ArchiveController extends AbstractController
$result = $payMGR->createRequest($order->getPrice(), $this->generateUrl('api_archive_buy_verify', ["id"=>$order->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'خرید فضای ابری');
if ($result['Success']) {
$order->setGatePay($result['gate']);
$order->setVerifyCode($result['authkey']);
$entityManager->persist($order);
$entityManager->flush();
$log->insert('سرویس فضای ابری', 'صدور فاکتور سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month'] . ' ماه ', $this->getUser(), $acc['bid']);
@ -107,7 +108,7 @@ class ArchiveController extends AbstractController
if (!$req)
throw $this->createNotFoundException('');
$res = $payMGR->verify($req->getPrice(), $id, $request);
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
if ($res['Success'] == false) {
$log->insert('سرویس فضای ابری', 'پرداخت ناموفق سرویس فضای ابری', $this->getUser(), $req->getBid());
return $this->render('buy/fail.html.twig', ['results' => $res]);

View file

@ -13,7 +13,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Writer\Exception;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class BankController extends AbstractController
{
#[Route('/api/bank/list', name: 'app_bank_list')]
@ -141,4 +146,123 @@ class BankController extends AbstractController
$log->insert('بانکداری', ' حساب بانکی با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
return $this->json(['result' => 1]);
}
/**
* @throws Exception
*/
#[Route('/api/bank/card/list/excel', name: 'app_bank_card_list_excel')]
public function app_bank_card_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
{
$acc = $access->hasRole('banks');
if (!$acc)
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if (!array_key_exists('code', $params))
throw $this->createNotFoundException();
$bank = $entityManager->getRepository(BankAccount::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]);
if (!$bank)
throw $this->createNotFoundException();
if (!array_key_exists('items', $params)) {
$transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([
'bid' => $acc['bid'],
'bank' => $bank,
'year'=>$acc['year']
]);
} else {
$transactions = [];
foreach ($params['items'] as $param) {
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
'id' => $param['id'],
'bid' => $acc['bid'],
'bank' => $bank,
'year' => $acc['year']
]);
if ($prs) {
$transactions[] = $prs;
}
}
}
$spreadsheet = new Spreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();
$arrayEntity = [
[
'شماره تراکنش',
'تاریخ',
'توضیحات',
'تفضیل',
'بستانکار',
'بدهکار',
'سال مالی',
]
];
foreach ($transactions as $transaction) {
$arrayEntity[] = [
$transaction->getId(),
$transaction->getDoc()->getDate(),
$transaction->getDes(),
$transaction->getRef()->getName(),
$transaction->getBs(),
$transaction->getBd(),
$transaction->getYear()->getlabel()
];
}
$activeWorksheet->fromArray($arrayEntity, null, 'A1');
$activeWorksheet->setRightToLeft(true);
$writer = new Xlsx($spreadsheet);
$filePath = __DIR__ . '/../../var/' . $provider->RandomString(12) . '.xlsx';
$writer->save($filePath);
return new BinaryFileResponse($filePath);
}
#[Route('/api/bank/card/list/print', name: 'app_bank_card_list_print')]
public function app_bank_card_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('banks');
if (!$acc)
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if (!array_key_exists('code', $params))
throw $this->createNotFoundException();
$bank = $entityManager->getRepository(BankAccount::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]);
if (!$bank)
throw $this->createNotFoundException();
if (!array_key_exists('items', $params)) {
$transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([
'bid' => $acc['bid'],
'bank' => $bank,
'year'=>$acc['year']
]);
} else {
$transactions = [];
foreach ($params['items'] as $param) {
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
'id' => $param['id'],
'bid' => $acc['bid'],
'bank' => $bank,
'year'=>$acc['year']
]);
if ($prs) {
$transactions[] = $prs;
}
}
}
$pid = $provider->createPrint(
$acc['bid'],
$this->getUser(),
$this->renderView('pdf/bank_card.html.twig', [
'page_title' => 'کارت حساب' . ' ' . $bank->getName(),
'bid' => $acc['bid'],
'items' => $transactions,
'bank' => $bank
])
);
return $this->json(['id' => $pid]);
}
}

View file

@ -13,7 +13,9 @@ use App\Entity\Year;
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;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -24,7 +26,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class PayController extends AbstractController
{
#[Route('/pay/sell/{id}', name: 'pay_sell')]
public function pay_sell(String $id,EntityManagerInterface $entityManager,Log $log): Response
public function pay_sell(string $id, PayMGR $payMGR, twigFunctions $twigFunctions, EntityManagerInterface $entityManager, Log $log): Response
{
$doc = $entityManager->getRepository(HesabdariDoc::class)->find($id);
if (!$doc)
@ -38,33 +40,6 @@ class PayController extends AbstractController
$totalPays += $relatedDoc->getAmount();
$amountPay = $doc->getAmount() - $totalPays;
//get system settings
$settings = $entityManager->getRepository(Settings::class)->findAll()[0];
$data = array("merchant_id" => $settings->getZarinpalMerchant(),
"amount" => $amountPay,
"callback_url" => $this->generateUrl('pay_sell_verify',['id'=>$doc->getId()],UrlGeneratorInterface::ABSOLUTE_URL),
"description" => 'پرداخت فاکتور شماره ' . $doc->getCode() . ' کسب و کار ' .$doc->getBid()->getLegalName(),
);
$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) {
$tempPay = new PayInfoTemp();
$tempPay->setBid($doc->getBid());
$tempPay->setDateSubmit(time());
@ -72,14 +47,16 @@ class PayController extends AbstractController
$tempPay->setPrice($amountPay);
$tempPay->setStatus(0);
$tempPay->setDoc($doc);
$tempPay->setVerifyCode($result['data']['authority']);
$tempPay->setGatePay('zarinpal');
$entityManager->persist($tempPay);
$entityManager->flush();
$result = $payMGR->createRequest($amountPay, $this->generateUrl('pay_sell_verify', ["id" => $doc->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'پرداخت فاکتور شماره ' . $doc->getCode() . ' کسب و کار ' . $doc->getBid()->getLegalName());
if ($result['Success']) {
$tempPay->setGatePay($result['gate']);
$tempPay->setVerifyCode($result['authkey']);
$entityManager->persist($tempPay);
$entityManager->flush();
$log->insert('کیف پول', 'ایجاد تراکنش پرداخت برای فاکتور فروش ' . $doc->getCode(), $this->getUser(), $doc->getBid());
return $this->redirect('https://www.zarinpal.com/pg/StartPay/' . $result['data']["authority"]);
}
}
return $this->redirect($result['targetURL']);
}
return $this->render('pay/fail.html.twig', [
'type' => 'sell',
@ -88,48 +65,26 @@ class PayController extends AbstractController
}
#[Route('pay/sell/verify/{id}', name: 'pay_sell_verify')]
public function pay_sell_verify(String $id, Notification $notification,Provider $provider,Jdate $jdate,Request $request,EntityManagerInterface $entityManager,Log $log): Response
public function pay_sell_verify(string $id, PayMGR $payMGR, Notification $notification, Provider $provider, Jdate $jdate, Request $request, EntityManagerInterface $entityManager, Log $log): Response
{
$doc = $entityManager->getRepository(HesabdariDoc::class)->find($id);
$req = $entityManager->getRepository(PayInfoTemp::class)->find($id);
if (!$req)
throw $this->createNotFoundException('');
$doc = $req->getDoc();
if (!$doc)
throw $this->createNotFoundException();
$Authority = $request->get('Authority');
$status = $request->get('Status');
$req = $entityManager->getRepository(PayInfoTemp::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);
//-----------------------------------
$originalDoc = $req->getDoc();
//-----------------------------------
if ($err) {
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
if ($res['Success'] == false) {
$log->insert('کیف پول', 'خطا در پرداخت فاکتور فروش ' . $doc->getCode(), $this->getUser(), $doc->getBid());
return $this->redirectToRoute('shortlinks_show',['type'=>'sell','bid'=>$originalDoc->getBid()->getId(),'link'=>$originalDoc->getId(),'msg'=>'fail']);
return $this->redirectToRoute('shortlinks_show', ['type' => 'sell', 'bid' => $doc->getBid()->getId(), 'link' => $doc->getId(), 'msg' => 'fail']);
} 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->setRefID($res['refID']);
$req->setCardPan($res['card_pan']);
$entityManager->persist($req);
$entityManager->flush();
$originalDoc = $req->getDoc();
//create wallet transaction
$wt = new WalletTransaction();
@ -229,8 +184,4 @@ class PayController extends AbstractController
return $this->redirectToRoute('shortlinks_show', ['type' => 'sell', 'bid' => $originalDoc->getBid()->getId(), 'link' => $originalDoc->getId(), 'msg' => 'success']);
}
}
$log->insert('کیف پول','خطا در پرداخت فاکتور فروش ' . $originalDoc->getCode() ,$this->getUser(),$doc->getBid());
return $this->redirectToRoute('shortlinks_show',['type'=>'sell','bid'=>$originalDoc->getBid()->getId(),'link'=>$originalDoc->getId(),'msg'=>'fail']);
}
}
}

View file

@ -72,7 +72,9 @@ class PluginController extends AbstractController
public function api_plugin_buy_verify(string $id, twigFunctions $twigFunctions, PayMGR $payMGR, Request $request, EntityManagerInterface $entityManager, Log $log): Response
{
$req = $entityManager->getRepository(Plugin::class)->find($id);
$res = $payMGR->verify($req->getPrice(), $id, $request);
if (!$req)
throw $this->createNotFoundException('');
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
if ($res['Success'] == false) {
$log->insert(
'بازار افزونه‌ها' . $req->getName(),

View file

@ -143,7 +143,10 @@ class SMSController extends AbstractController
public function api_sms_buy_verify(string $id, PayMGR $payMGR, twigFunctions $twigFunctions, Notification $notification, Request $request, EntityManagerInterface $entityManager, Log $log): Response
{
$req = $entityManager->getRepository(SMSPays::class)->find($id);
$res = $payMGR->verify($req->getPrice(), $id, $request);
if (!$req)
throw $this->createNotFoundException('');
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
if ($res['Success'] == false) {
$log->insert('سرویس پیامک', 'پرداخت ناموفق شارژ سرویس پیامک', $this->getUser(), $req->getBid());
return $this->render('buy/fail.html.twig', ['results' => $res]);

View file

@ -32,7 +32,7 @@ class PayInfoTemp
#[ORM\Column(length: 255, nullable: true)]
private ?string $verifyCode = null;
#[ORM\Column(length: 255)]
#[ORM\Column(length: 255, nullable: true)]
private ?string $gatePay = null;
#[ORM\ManyToOne]

View file

@ -18,9 +18,6 @@ class Settings
#[ORM\Column(nullable: true)]
private ?bool $activeSendSms = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $zarinpalMerchant = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $appSite = null;
@ -62,18 +59,6 @@ class Settings
return $this;
}
public function getZarinpalMerchant(): ?string
{
return $this->zarinpalMerchant;
}
public function setZarinpalMerchant(?string $zarinpalMerchant): static
{
$this->zarinpalMerchant = $zarinpalMerchant;
return $this;
}
public function getAppSite(): ?string
{
return $this->appSite;

View file

@ -0,0 +1,121 @@
{% extends "pdf/base.html.twig" %}
{% block body %}
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">کارت حساب بانکی</b>
</div>
<table style="width:100%;">
<tbody>
<tr style="text-align:center;">
<td class="">
<p>
<b>نام:
</b>
{{ bank.name }}
</p>
</td>
<td class="center">
<p>
<b>
شماره حساب:
</b>
{{ bank.accountNum }}
</p>
</td>
<td class="center">
<p>
<b>شماره شبا:
</b>
{{ bank.shaba }}
</p>
</td>
<td class="center">
<p>
<b>شماره کارت:
</b>
{{ bank.cardNum }}
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%;margin-top:5px;text-align:center;">
<table style="width:100%;">
<tbody>
<tr style="text-align: center; background-color: grey; text-color: white">
<td style="width: 35px;">ردیف</td>
<td class="center item">فاکتور/سند</td>
<td class="center item">تاریخ</td>
<td class="center item">توضیحات</td>
<td class="center item">تفضیل</td>
<td class="center item">بدهکار</td>
<td class="center item">بستانکار</td>
<td class="center item">سال مالی</td>
</tr>
{% set sumBs = 0 %}
{% set sumBd = 0 %}
{% for item in items %}
{% set sumBs = sumBs + item.bs %}
{% set sumBd = sumBd + item.bd %}
<tr class="stimol">
<td class="center item">{{ loop.index }}</td>
<td class="center item">{{ item.doc.code }}</td>
<td class="center item">{{ item.doc.date }}</td>
<td class="center item">{{ item.des }}</td>
<td class="center item">{{ item.ref.name }}</td>
<td class="center item">{{ item.bd | number_format }}</td>
<td class="center item">{{ item.bs | number_format }}</td>
<td class="center item">{{ item.year.label }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">وضعیت حساب</b>
</div>
<table style="width:100%;">
<tbody>
<tr style="text-align:center;">
<td class="center">
<p>
<b>جمع بستانکار:
</b>
{{ sumBs | number_format }}
</p>
</td>
<td class="center">
<p>
<b>جمع بدهکار:
</b>
{{ sumBd | number_format }}
</p>
</td>
<td class="center">
<p>
<b>تراز حساب:
</b>
<span>{{ (sumBs - sumBd) | abs |number_format }}</span>
</p>
</td>
<td class="center">
<p>
<b> وضعیت:
</b>
{% if sumBs > sumBd%}
بستانکار
{% elseif sumBs == sumBd %}
تسویه شده
{% else %}
بدهکار
{% endif %}
</p>
</td>
</tr>
</tbody>
</table>
</div>
{% endblock %}