feat(sms): simplify SMS settings to use only KAVENEGAR_API_KEY from env, remove other SMS-related fields from config
This commit is contained in:
@@ -35,13 +35,6 @@ class SiteConfigController extends BaseController
|
||||
'mellat_username',
|
||||
'mellat_password',
|
||||
'sep_terminal_id',
|
||||
// sms provider
|
||||
'sms_provider',
|
||||
'kavenegar_api_key',
|
||||
'kavenegar_sender',
|
||||
'rangineh_api_key',
|
||||
'rangineh_sender',
|
||||
'sms_price_rials',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
@@ -53,7 +46,10 @@ class SiteConfigController extends BaseController
|
||||
#[Route('/api/v1/admin/settings', methods: ['GET'])]
|
||||
public function get(): JsonResponse
|
||||
{
|
||||
return $this->success($this->configRepo->getAll());
|
||||
$config = $this->configRepo->getAll();
|
||||
// کلید API پیامک فقط از env؛ فقط وضعیت تنظیمبودن برگردانده میشود نه مقدار.
|
||||
$config['sms_api_key_configured'] = ($_ENV['KAVENEGAR_API_KEY'] ?? '') !== '';
|
||||
return $this->success($config);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/admin/settings', methods: ['PATCH'])]
|
||||
|
||||
@@ -28,13 +28,6 @@ class SiteConfigRepository extends ServiceEntityRepository
|
||||
'mellat_username' => '',
|
||||
'mellat_password' => '',
|
||||
'sep_terminal_id' => '',
|
||||
// sms provider
|
||||
'sms_provider' => 'kavenegar',
|
||||
'kavenegar_api_key' => '',
|
||||
'kavenegar_sender' => '',
|
||||
'rangineh_api_key' => '',
|
||||
'rangineh_sender' => '',
|
||||
'sms_price_rials' => '500',
|
||||
];
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
|
||||
@@ -29,6 +29,8 @@ use OpenApi\Attributes as OA;
|
||||
#[IsGranted('IS_AUTHENTICATED_FULLY')]
|
||||
class SmsWalletController extends BaseController
|
||||
{
|
||||
private const SMS_PRICE_RIALS = 500;
|
||||
|
||||
public function __construct(
|
||||
private readonly SmsWalletService $walletService,
|
||||
private readonly SmsWalletRepository $walletRepo,
|
||||
@@ -53,7 +55,7 @@ class SmsWalletController extends BaseController
|
||||
}
|
||||
|
||||
$balanceRials = $this->walletService->getBalance($entityType, $entityId);
|
||||
$smsPriceRials = (int) ($this->configRepo->get('sms_price_rials') ?? 500);
|
||||
$smsPriceRials = self::SMS_PRICE_RIALS;
|
||||
$estimatedSms = $smsPriceRials > 0 ? (int) floor($balanceRials / $smsPriceRials) : 0;
|
||||
|
||||
return $this->success([
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Sms\Provider;
|
||||
|
||||
use App\Config\Repository\SiteConfigRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
@@ -12,16 +11,14 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient,
|
||||
private readonly SiteConfigRepository $configRepo,
|
||||
private readonly LoggerInterface $logger,
|
||||
// Nullable: env `%env(default::KAVENEGAR_API_KEY)%` resolves to null when unset
|
||||
// (the real key normally comes from DB site config below, not env).
|
||||
// API key comes only from env `%env(default::KAVENEGAR_API_KEY)%`; null when unset.
|
||||
private readonly ?string $apiKey = null,
|
||||
private readonly ?string $sender = null,
|
||||
) {}
|
||||
|
||||
private function key(): string { return $this->configRepo->get('kavenegar_api_key') ?: ($this->apiKey ?? ''); }
|
||||
private function sender(): string { return $this->configRepo->get('kavenegar_sender') ?: ($this->sender ?? ''); }
|
||||
private function key(): string { return $this->apiKey ?? ''; }
|
||||
private function sender(): string { return $this->sender ?? ''; }
|
||||
|
||||
public function getName(): string { return 'kavenegar'; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user