🚀 مُصادَق: الإطلاق الأولي للنظام المتكامل
This commit is contained in:
43
app/Modules/Companies/CompanyService.php
Normal file
43
app/Modules/Companies/CompanyService.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Companies;
|
||||
|
||||
use App\Services\Security\EncryptionService;
|
||||
use App\Modules\Companies\CompanyModel;
|
||||
|
||||
final class CompanyService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CompanyModel $companyModel,
|
||||
private readonly EncryptionService $encryption
|
||||
) {}
|
||||
|
||||
public function createCompany(array $data): string
|
||||
{
|
||||
// Encrypt sensitive JoFotara credentials
|
||||
if (isset($data['jofotara_client_id'])) {
|
||||
$data['jofotara_client_id_encrypted'] = $this->encryption->encrypt($data['jofotara_client_id']);
|
||||
unset($data['jofotara_client_id']);
|
||||
}
|
||||
|
||||
if (isset($data['jofotara_secret_key'])) {
|
||||
$data['jofotara_secret_key_encrypted'] = $this->encryption->encrypt($data['jofotara_secret_key']);
|
||||
unset($data['jofotara_secret_key']);
|
||||
}
|
||||
|
||||
return (string)$this->companyModel->create($data);
|
||||
}
|
||||
|
||||
public function getJoFotaraCredentials(string $companyId): array
|
||||
{
|
||||
$company = $this->companyModel->find($companyId);
|
||||
if (!$company) return [];
|
||||
|
||||
return [
|
||||
'clientId' => $company['jofotara_client_id_encrypted'] ? $this->encryption->decrypt($company['jofotara_client_id_encrypted']) : null,
|
||||
'secretKey' => $company['jofotara_secret_key_encrypted'] ? $this->encryption->decrypt($company['jofotara_secret_key_encrypted']) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user