Fix wallet: bake composer vendor into Docker image

This commit is contained in:
Hamza-Ayed
2026-08-01 03:19:55 +03:00
parent 414965de45
commit 508a6ce1d0
4 changed files with 47 additions and 35 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ try {
$firstName_encrypted = $encryptionHelper->encryptData($firstName);
$lastName_encrypted = $encryptionHelper->encryptData($lastName);
$email_encrypted = $encryptionHelper->encryptData($email);
$uniqueId = substr(md5($phoneNumber), 0, 20);
$uniqueId = substr(md5($phoneNumber), 0, 16);
$password_hashed = password_hash($email . $uniqueId, PASSWORD_DEFAULT);
$unknown_encrypted = $encryptionHelper->encryptData("unknown yet");
+2 -2
View File
@@ -30,8 +30,8 @@ services:
# التقسيم لأبعد من هذا لا يضيف أداءً — نفس الصورة، نفس النواة.
php:
build:
context: ./php
dockerfile: Dockerfile.fpm
context: ..
dockerfile: docker/php/Dockerfile.fpm
args:
PHP_VERSION: "${PHP_VERSION:-8.2}"
volumes:
+5
View File
@@ -6,4 +6,9 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions mysqli pdo_mysql redis opcache gd zip @composer
# تثبيت مكتبات سيرفر المدفوعات (firebase/php-jwt وغيره)
# هذا يخبز vendor/ داخل الصورة مباشرة حتى لا يعتمد على مجلد خارجي
COPY payment_server/v2/composer.json payment_server/v2/composer.lock /var/www/v2/
RUN cd /var/www/v2 && composer install --no-dev --no-interaction --optimize-autoloader
WORKDIR /var/www
+37 -30
View File
@@ -1,54 +1,61 @@
<?php
// Load environment variables from .env file
require_once realpath(__DIR__ . '/../vendor/autoload.php');
require_once 'load_env.php';
$envFile = '/home/intaleq-walletintaleq/env/.env';
if (!file_exists($envFile)) {
$envFile = __DIR__ . '/../.env';
// connect.php — نسخة الدوكر
// ─────────────────────────────────────────────────────────────
// • vendor/ مخبوز داخل الصورة في /var/www/v2/vendor (Dockerfile يشغّل composer install)
// • متغيّرات البيئة تصل عبر env_file في docker-compose → getenv() يعمل مباشرةً
// ─────────────────────────────────────────────────────────────
// 1. Autoload — vendor مخبوز داخل الصورة
$autoload = __DIR__ . '/../vendor/autoload.php';
if (file_exists($autoload)) {
require_once $autoload;
}
loadEnvironment($envFile);
// Get environment variables (You don't need user/pass for JWT auth itself)
$secretKey = getenv('SECRET_KEY'); // Only need the secret key now
// 2. لا حاجة لتحميل .env يدوياً: Docker يحقن المتغيّرات عبر env_file
// نحتفظ بـ load_env.php فقط لبيئة التطوير خارج الدوكر
if (!getenv('DB_PAYMENT_HOST')) {
// نحن خارج بيئة الدوكر — جرّب تحميل .env يدوياً
if (file_exists(__DIR__ . '/load_env.php')) {
require_once 'load_env.php';
$envFile = __DIR__ . '/../.env';
if (file_exists($envFile)) loadEnvironment($envFile);
}
}
// --- CORS Headers ---
header("Access-Control-Allow-Origin: https://wallet.siromove.com");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); // Adjust as needed
// 3. CORS Headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header('Content-Type: application/json'); // Set content type to JSON
header('Content-Type: application/json');
// Handle preflight requests (OPTIONS)
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
// --- Database Connection (Still needed for your application logic) ---
// 4. Database Connection
try {
$dbname = getenv('DB_PAYMENT_NAME') ?: (getenv('dbname') ?: 'payment');
$dbHost = getenv('DB_PAYMENT_HOST') ?: (getenv('DB_HOST') ?: 'mysql');
$dsn = "mysql:host=$dbHost;dbname=$dbname;charset=utf8mb4";
$dbname = getenv('DB_PAYMENT_NAME') ?: 'paymentDB';
$dbHost = getenv('DB_PAYMENT_HOST') ?: 'mysql';
$user = getenv('DB_PAYMENT_USER') ?: 'root';
$pass = getenv('DB_PAYMENT_PASS') ?: getenv('MYSQL_ROOT_PASSWORD') ?: '';
$dsn = "mysql:host=$dbHost;dbname=$dbname;charset=utf8mb4";
$options = [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8",
];
$user = getenv('DB_PAYMENT_USER') ?: (getenv('USER') ?: 'root');
$pass = getenv('DB_PAYMENT_PASS') ?: (getenv('PASS') ?: getenv('MYSQL_ROOT_PASSWORD'));
$con = new PDO($dsn, $user, $pass, $options);
// echo $con;
// --- JWT Authentication ---
include __DIR__ . "/functions.php"; // Include the functions file
$decodedToken = authenticateJWT(); // Call the authentication function
// 5. JWT Authentication
include __DIR__ . "/functions.php";
$decodedToken = authenticateJWT();
} catch (PDOException $e) {
error_log($e->getMessage());
http_response_code(500); // Internal Server Error
error_log('[WALLET] DB Error: ' . $e->getMessage());
http_response_code(500);
echo json_encode(['error' => 'A database error occurred.']);
exit;
}