Files
Siro/backend/food/connect_merchant.php
T

44 lines
1.8 KiB
PHP

<?php
// ============================================================
// food/connect_merchant.php — بوابة لوحة المطعم (ويب متجاوب)
// المصادقة عبر session token (هاتف + كلمة مرور) — مستقلة عن JWT
// ============================================================
require_once __DIR__ . '/../core/bootstrap.php';
require_once __DIR__ . '/functions.php';
if (getenv('FOOD_ENABLED') === 'false') {
http_response_code(503);
echo json_encode(['status' => 'failure', 'message' => 'Food service is currently disabled']);
exit;
}
// CORS للوحة المطعم
$merchantOrigins = array_map('trim', explode(',',
getenv('FOOD_MERCHANT_ORIGINS') ?: 'https://food-merchant.siromove.com,https://admin.siromove.com'
));
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
if (in_array($origin, $merchantOrigins)) {
header("Access-Control-Allow-Origin: $origin");
header('Access-Control-Allow-Credentials: true');
}
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
$limiter = new RateLimiter($redis);
$limiter->enforce(RateLimiter::identifier(), 'api');
try {
$food_con = Database::get('food');
} catch (Exception $e) {
// السبب الحقيقي في اللوج فقط — الرد يبقى عاماً.
error_log('[FOOD] DB connection failed in ' . basename(__FILE__) . ': ' . $e->getMessage());
http_response_code(503);
echo json_encode(['status' => 'failure', 'message' => 'Food service unavailable']);
exit;
}
// التحقق من الـ session (يُعيد ['merchant_user_id'=>X, 'merchant_id'=>Y])
$food_merchant_session = foodAuthMerchant();
$food_merchant_user_id = (int)$food_merchant_session['merchant_user_id'];
$food_merchant_id = (int)$food_merchant_session['merchant_id'];