Files
portal/app/app/Http/Controllers/Api/AdminYandex360BalanceController.php
T
Дмитрий 1fef2571e8
Accessibility (Pa11y live) / a11y (push) Waiting to run
SAST — Semgrep / Semgrep SAST scan (push) Waiting to run
feat(y360): баланс почты Яндекс 360 — ручной ввод + кнопка Пополнить
email — денежный сервис; сумма вписывается в админке «Система» (Yandex360BalanceStore),
светофор по порогам, кнопка «Открыть оплату»/«Пополнить» → admin.yandex.ru/products.
Робот-скрейпер отклонён (SPA Яндекса враждебен ботам + автопополнение защищает баланс).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 13:34:13 +03:00

43 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Services\External\Yandex360BalanceStore;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* SaaS-admin → Система: ручной ввод баланса Яндекс 360 (почта).
* Владелец периодически вписывает сумму из кабинета (у Яндекса нет API баланса).
*/
class AdminYandex360BalanceController extends Controller
{
public function __construct(private readonly Yandex360BalanceStore $store) {}
/** GET /api/admin/settings/yandex360-balance */
public function show(): JsonResponse
{
return response()->json($this->store->status());
}
/** PUT /api/admin/settings/yandex360-balance — {balance:number|null} */
public function update(Request $request): JsonResponse
{
$raw = $request->input('balance');
$balance = ($raw === null || $raw === '') ? null : (float) $raw;
if ($balance !== null && $balance < 0) {
return response()->json([
'message' => 'Баланс не может быть отрицательным.',
'errors' => ['balance' => ['Введите сумму ≥ 0 или очистите поле.']],
], 422);
}
$this->store->set($balance);
return response()->json($this->store->status());
}
}