Update: 2026-06-18 16:46:30
This commit is contained in:
@@ -30,11 +30,6 @@ GEMINI_API_KEY=<CHANGE_ME>
|
||||
# Nabeh Integration (must match Nabeh's .env)
|
||||
NABEH_API_KEY=<CHANGE_ME_SHARED_SECRET>
|
||||
|
||||
# Siro Backend URL (for phone→driverID resolution)
|
||||
# Used by verify_payment.php to call resolve_user.php
|
||||
# Example: https://api-syria.siromove.com/siro
|
||||
SIRO_BACKEND_URL=https://api-syria.siromove.com/siro
|
||||
|
||||
# Admin login
|
||||
passwordnewpassenger=<CHANGE_ME>
|
||||
allowedWallet1=Tripz-Wallet
|
||||
|
||||
@@ -8,6 +8,7 @@ try {
|
||||
$userType = filterRequest("user_type");
|
||||
$amount = filterRequest("amount");
|
||||
$cliqPhone = filterRequest("cliq_phone");
|
||||
$phone = filterRequest("phone");
|
||||
|
||||
if (empty($userId) || empty($userType) || !is_numeric($amount) || $amount <= 0 || empty($cliqPhone)) {
|
||||
echo json_encode(["status" => "failure", "message" => "Invalid input provided."]);
|
||||
@@ -36,12 +37,14 @@ try {
|
||||
$upd = $con->prepare("
|
||||
UPDATE cliq_invoices
|
||||
SET amount = :amount,
|
||||
phone = :phone,
|
||||
cliq_phone = :cliq_phone,
|
||||
updated_at = NOW()
|
||||
WHERE id = :id
|
||||
");
|
||||
$upd->execute([
|
||||
':amount' => $amount,
|
||||
':phone' => $phone ?: null,
|
||||
':cliq_phone' => $cliqPhone,
|
||||
':id' => $existing['id'],
|
||||
]);
|
||||
@@ -59,14 +62,15 @@ try {
|
||||
|
||||
$ins = $con->prepare("
|
||||
INSERT INTO cliq_invoices
|
||||
(invoice_number, user_id, user_type, amount, cliq_phone, status, created_at, updated_at)
|
||||
(invoice_number, user_id, user_type, phone, amount, cliq_phone, status, created_at, updated_at)
|
||||
VALUES
|
||||
(:invoice_number, :user_id, :user_type, :amount, :cliq_phone, 'pending', NOW(), NOW())
|
||||
(:invoice_number, :user_id, :user_type, :phone, :amount, :cliq_phone, 'pending', NOW(), NOW())
|
||||
");
|
||||
$ins->execute([
|
||||
':invoice_number' => $invoiceNumber,
|
||||
':user_id' => $userId,
|
||||
':user_type' => $userType,
|
||||
':phone' => $phone ?: null,
|
||||
':amount' => $amount,
|
||||
':cliq_phone' => $cliqPhone
|
||||
]);
|
||||
|
||||
@@ -14,7 +14,7 @@ function finalizeClickPayment(PDO $con, int $invoiceId): array
|
||||
{
|
||||
try {
|
||||
// جلب تفاصيل الفاتورة
|
||||
$stmt = $con->prepare("SELECT * FROM `click_invoices` WHERE id = :id AND status = 'completed' LIMIT 1");
|
||||
$stmt = $con->prepare("SELECT * FROM `cliq_invoices` WHERE id = :id AND status = 'completed' LIMIT 1");
|
||||
$stmt->execute([':id' => $invoiceId]);
|
||||
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ try {
|
||||
$userType = filterRequest("user_type"); // 'driver' أو 'passenger'
|
||||
$amount = filterRequest("amount");
|
||||
$mtnPhone = filterRequest("mtn_phone");
|
||||
$phone = filterRequest("phone");
|
||||
|
||||
if (empty($userId) || empty($userType) || !is_numeric($amount) || $amount <= 0 || empty($mtnPhone)) {
|
||||
echo json_encode(["status" => "failure", "message" => "Invalid input provided."]);
|
||||
@@ -43,12 +44,14 @@ try {
|
||||
$upd = $con->prepare("
|
||||
UPDATE mtn_invoices
|
||||
SET amount = :amount,
|
||||
phone = :phone,
|
||||
mtn_phone = :mtn_phone,
|
||||
updated_at = NOW()
|
||||
WHERE id = :id
|
||||
");
|
||||
$upd->execute([
|
||||
':amount' => $amount,
|
||||
':phone' => $phone ?: null,
|
||||
':mtn_phone'=> $mtnPhone,
|
||||
':id' => $existing['id'],
|
||||
]);
|
||||
@@ -67,14 +70,15 @@ try {
|
||||
|
||||
$ins = $con->prepare("
|
||||
INSERT INTO mtn_invoices
|
||||
(invoice_number, user_id, user_type, amount, mtn_phone, status, created_at, updated_at)
|
||||
(invoice_number, user_id, user_type, phone, amount, mtn_phone, status, created_at, updated_at)
|
||||
VALUES
|
||||
(:invoice_number, :user_id, :user_type, :amount, :mtn_phone, 'pending', NOW(), NOW())
|
||||
(:invoice_number, :user_id, :user_type, :phone, :amount, :mtn_phone, 'pending', NOW(), NOW())
|
||||
");
|
||||
$ins->execute([
|
||||
':invoice_number' => $invoiceNumber,
|
||||
':user_id' => $userId,
|
||||
':user_type' => $userType,
|
||||
':phone' => $phone ?: null,
|
||||
':amount' => $amount,
|
||||
':mtn_phone' => $mtnPhone
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
-- Migration: Add phone column to all invoice tables
|
||||
-- Allows direct phone lookup instead of S2S resolve_user
|
||||
-- Run: mysql -u root WalletIntaleqDB < migration_add_phone.sql
|
||||
|
||||
ALTER TABLE invoices_shamcash
|
||||
ADD COLUMN phone VARCHAR(20) AFTER driverID,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
|
||||
ALTER TABLE invoices_shamcash_passenger
|
||||
ADD COLUMN phone VARCHAR(20) AFTER passengerID,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
|
||||
ALTER TABLE cliq_invoices
|
||||
ADD COLUMN phone VARCHAR(20) AFTER user_type,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
|
||||
ALTER TABLE invoices_sms
|
||||
ADD COLUMN phone VARCHAR(20) AFTER driverID,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
|
||||
ALTER TABLE invoices_sms_passenger
|
||||
ADD COLUMN phone VARCHAR(20) AFTER passengerID,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
|
||||
ALTER TABLE mtn_invoices
|
||||
ADD COLUMN phone VARCHAR(20) AFTER user_type,
|
||||
ADD INDEX idx_phone_status (phone, status);
|
||||
@@ -2,33 +2,25 @@
|
||||
/**
|
||||
* Nabeh Payment Verification Endpoint
|
||||
*
|
||||
* Auto-detects the user's pending invoice and uses Gemini AI to verify
|
||||
* the receipt image against the invoice. No manual invoice number needed.
|
||||
* Simplified: uses phone directly to find pending invoice (no S2S resolve_user).
|
||||
* Added Cliq AI verification with receipt image.
|
||||
*
|
||||
* ===============================
|
||||
* INPUT (JSON body)
|
||||
* ===============================
|
||||
* driver_id (optional) — from Nabeh's Siro API resolution (preferred)
|
||||
* phone (required if no driver_id) — lookup via Siro backend resolve_user
|
||||
* payment_method (required) — shamcash / cliq / mtn / sms
|
||||
* receipt_image (optional for AI verification)
|
||||
* image_mime_type (optional, default: image/jpeg)
|
||||
* phone (required) — User's phone number
|
||||
* payment_method (req) — shamcash / cliq / sms / mtn
|
||||
* receipt_image (opt) — Receipt screenshot for AI verification
|
||||
* image_mime_type (opt) — Default: image/jpeg
|
||||
*
|
||||
* ===============================
|
||||
* FLOW
|
||||
* ===============================
|
||||
* 1. Auth via jwtconnect.php (X-API-Key → NABEH_API_KEY)
|
||||
* 2. Resolve driverID:
|
||||
* a. Use driver_id directly if provided
|
||||
* b. Otherwise call Siro backend resolve_user.php (phone → driverID)
|
||||
* 3. Auto-find latest pending invoice for that driver
|
||||
* 4. If shamcash + receipt_image:
|
||||
* a. Call GeminiAi::verifyPayment(invoice_number, amount, "ShamCash", "", receipt_image)
|
||||
* b. Gemini returns {"verified": true/false, "reason": "..."}
|
||||
* c. If verified → UPDATE status='processing' → finalizeShamCashDeposit()
|
||||
* d. Return result
|
||||
* 5. If other methods or no receipt_image:
|
||||
* - Return invoice status info
|
||||
* 2. Find latest pending invoice by phone + payment_method
|
||||
* 3. If shamcash/cliq + receipt_image → Gemini AI verification
|
||||
* AI confirms → update status → finalize deposit → return success
|
||||
* 4. Otherwise return invoice status
|
||||
*
|
||||
* Auth: X-API-Key header → NABEH_API_KEY (via jwtconnect.php Path 5)
|
||||
*/
|
||||
@@ -45,110 +37,72 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true) ?: $_POST;
|
||||
|
||||
$driverId = trim($data['driver_id'] ?? '');
|
||||
$phone = trim($data['phone'] ?? '');
|
||||
$paymentMethod = strtolower(trim($data['payment_method'] ?? ''));
|
||||
$receiptImage = $data['receipt_image'] ?? '';
|
||||
$imageMimeType = $data['image_mime_type'] ?? 'image/jpeg';
|
||||
$phone = preg_replace('/\D+/', '', $data['phone'] ?? '');
|
||||
$paymentMethod = strtolower(trim($data['payment_method'] ?? ''));
|
||||
$receiptImage = $data['receipt_image'] ?? '';
|
||||
$imageMimeType = $data['image_mime_type'] ?? 'image/jpeg';
|
||||
|
||||
// ── Step 1: Resolve driverID ──────────────────────────────────
|
||||
// driver_id (from Nabeh's Siro API resolution) is preferred
|
||||
// phone fallback calls Siro backend resolve_user endpoint via S2S
|
||||
$userName = '';
|
||||
$userPhone = $phone;
|
||||
$userType = 'driver';
|
||||
|
||||
if (empty($driverId) && empty($phone)) {
|
||||
printFailure('driver_id or phone is required');
|
||||
if (empty($phone)) {
|
||||
printFailure('phone is required');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($driverId) && !empty($phone)) {
|
||||
$siroBackendUrl = rtrim(getenv('SIRO_BACKEND_URL') ?: 'https://api-syria.siromove.com/siro', '/');
|
||||
$resolveUrl = $siroBackendUrl . '/nabeh/resolve_user.php';
|
||||
|
||||
$resolvePayload = json_encode(['phone' => $phone]);
|
||||
$apiKey = getenv('NABEH_API_KEY') ?: '';
|
||||
|
||||
$ch = curl_init($resolveUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $resolvePayload,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'X-API-Key: ' . $apiKey,
|
||||
],
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
]);
|
||||
$resolveRes = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode !== 200 || empty($resolveRes)) {
|
||||
printFailure('Could not resolve user. Please ensure you are registered in Siro.');
|
||||
exit;
|
||||
}
|
||||
|
||||
$resolveData = json_decode($resolveRes, true);
|
||||
if (($resolveData['status'] ?? '') !== 'success' || empty($resolveData['data']['user_id'] ?? '')) {
|
||||
printFailure('User not found in Siro system.');
|
||||
exit;
|
||||
}
|
||||
|
||||
$driverId = $resolveData['data']['user_id'];
|
||||
$userName = $resolveData['data']['name'] ?? '';
|
||||
$userPhone = $resolveData['data']['phone'] ?? $phone;
|
||||
$userType = $resolveData['data']['type'] ?? 'driver';
|
||||
}
|
||||
|
||||
$paymentMethod = $paymentMethod ?: 'shamcash';
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// SHAMCASH — AI Verification (auto-find pending invoice)
|
||||
// HELPER: find pending invoice by phone
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
if ($paymentMethod === 'shamcash') {
|
||||
// Auto-find latest pending invoice for this driver
|
||||
function findPendingByPhone(PDO $con, string $table, string $phone, string $orderCol = 'created_at'): ?array
|
||||
{
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, invoice_number, amount, status, created_at
|
||||
FROM invoices_shamcash
|
||||
WHERE driverID = ? AND status = 'pending'
|
||||
FROM $table
|
||||
WHERE phone = ? AND status = 'pending'
|
||||
ORDER BY $orderCol DESC
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->execute([$phone]);
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
}
|
||||
|
||||
function findLastCompletedByPhone(PDO $con, string $table, string $phone): ?array
|
||||
{
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, invoice_number, amount, status, created_at
|
||||
FROM $table
|
||||
WHERE phone = ? AND status = 'completed'
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->execute([$driverId]);
|
||||
$invoice = $stmt->fetch();
|
||||
$stmt->execute([$phone]);
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// SHAMCASH — AI Verification
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
if ($paymentMethod === 'shamcash') {
|
||||
$invoice = findPendingByPhone($con, 'invoices_shamcash', $phone);
|
||||
|
||||
if (!$invoice) {
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, invoice_number, amount, status, created_at
|
||||
FROM invoices_shamcash
|
||||
WHERE driverID = ? AND status = 'completed'
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->execute([$driverId]);
|
||||
$lastCompleted = $stmt->fetch();
|
||||
|
||||
$lastCompleted = findLastCompletedByPhone($con, 'invoices_shamcash', $phone);
|
||||
if ($lastCompleted) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified'=> true,
|
||||
'message' => 'آخر فاتورة لديك مكتملة بالفعل.',
|
||||
'invoice' => $lastCompleted,
|
||||
'status' => 'success',
|
||||
'verified' => true,
|
||||
'message' => 'آخر فاتورة لديك مكتملة بالفعل.',
|
||||
'invoice' => $lastCompleted,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified'=> false,
|
||||
'message' => 'لا توجد فاتورة معلقة. يرجى إنشاء فاتورة عبر تطبيق Siro أولاً.',
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'message' => 'لا توجد فاتورة معلقة. يرجى إنشاء فاتورة عبر تطبيق Siro أولاً.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── If no receipt image, just return invoice info ─────
|
||||
if (empty($receiptImage)) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
@@ -160,7 +114,7 @@ if ($paymentMethod === 'shamcash') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── Run AI verification ─────────────────────────────────
|
||||
// ── AI verify ───────────────────────────────────────────
|
||||
$geminiKey = getenv('GEMINI_API_KEY');
|
||||
if (empty($geminiKey)) {
|
||||
printFailure('AI verification service not configured');
|
||||
@@ -178,9 +132,7 @@ if ($paymentMethod === 'shamcash') {
|
||||
);
|
||||
|
||||
if (!empty($aiResult['verified'])) {
|
||||
// ── AI confirmed → finalize ─────────────────────
|
||||
$con->beginTransaction();
|
||||
|
||||
$upd = $con->prepare("
|
||||
UPDATE invoices_shamcash
|
||||
SET status = 'processing'
|
||||
@@ -190,9 +142,7 @@ if ($paymentMethod === 'shamcash') {
|
||||
|
||||
if ($upd->rowCount() > 0) {
|
||||
require_once __DIR__ . '/../shamcash/finalize_deposit.php';
|
||||
|
||||
$finalized = finalizeShamCashDeposit($con, $invoice['id']);
|
||||
|
||||
if ($finalized) {
|
||||
$con->commit();
|
||||
echo json_encode([
|
||||
@@ -216,9 +166,9 @@ if ($paymentMethod === 'shamcash') {
|
||||
} else {
|
||||
$con->rollBack();
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified'=> false,
|
||||
'message' => 'These funds have already been credited.',
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'message' => 'These funds have already been credited.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
} else {
|
||||
@@ -238,55 +188,162 @@ if ($paymentMethod === 'shamcash') {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// OTHER METHODS — Status query (find pending invoice by phone)
|
||||
// CLIQ — AI Verification (same pattern as ShamCash)
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
$table = '';
|
||||
$columns = '';
|
||||
$conditions = '';
|
||||
if ($paymentMethod === 'cliq') {
|
||||
$invoice = findPendingByPhone($con, 'cliq_invoices', $phone);
|
||||
|
||||
switch ($paymentMethod) {
|
||||
case 'sms':
|
||||
case 'syriatel':
|
||||
$table = 'invoices_sms';
|
||||
$columns = "id, invoice_number, amount, status, NULL AS transaction_id, created_at, paid_at";
|
||||
$conditions = "driverID = ? AND status = 'pending'";
|
||||
break;
|
||||
|
||||
case 'cliq':
|
||||
$table = 'cliq_invoices';
|
||||
$columns = "id, invoice_number, amount, status, NULL AS transaction_id, created_at, updated_at AS paid_at";
|
||||
$conditions = "user_id = ? AND user_type = 'driver' AND status = 'pending'";
|
||||
break;
|
||||
|
||||
case 'mtn':
|
||||
$table = 'mtn_invoices';
|
||||
$columns = "id, invoice_number, amount, status, mtn_transaction_id AS transaction_id, created_at, updated_at AS paid_at";
|
||||
$conditions = "user_id = ? AND user_type = 'driver' AND status = 'pending'";
|
||||
break;
|
||||
|
||||
default:
|
||||
printFailure("Invalid payment method: $paymentMethod");
|
||||
if (!$invoice) {
|
||||
$lastCompleted = findLastCompletedByPhone($con, 'cliq_invoices', $phone);
|
||||
if ($lastCompleted) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => true,
|
||||
'message' => 'آخر فاتورة لديك مكتملة بالفعل.',
|
||||
'invoice' => $lastCompleted,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'message' => 'لا توجد فاتورة معلقة. يرجى إنشاء فاتورة عبر تطبيق Siro أولاً.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($receiptImage)) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'requires_image' => true,
|
||||
'message' => "تم العثور على فاتورة رقم {$invoice['invoice_number']} بمبلغ {$invoice['amount']} دينار. يرجى إرسال صورة الإيصال.",
|
||||
'invoice' => $invoice,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── AI verify ───────────────────────────────────────────
|
||||
$geminiKey = getenv('GEMINI_API_KEY');
|
||||
if (empty($geminiKey)) {
|
||||
printFailure('AI verification service not configured');
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$gemini = new GeminiAi($geminiKey);
|
||||
$aiResult = $gemini->verifyPayment(
|
||||
$invoice['invoice_number'],
|
||||
$invoice['amount'],
|
||||
'Cliq',
|
||||
'',
|
||||
$receiptImage
|
||||
);
|
||||
|
||||
if (!empty($aiResult['verified'])) {
|
||||
$con->beginTransaction();
|
||||
$upd = $con->prepare("
|
||||
UPDATE cliq_invoices
|
||||
SET status = 'completed', updated_at = NOW()
|
||||
WHERE id = ? AND status = 'pending'
|
||||
");
|
||||
$upd->execute([$invoice['id']]);
|
||||
|
||||
if ($upd->rowCount() > 0) {
|
||||
require_once __DIR__ . '/../cliq/finalize_payment.php';
|
||||
$finalized = finalizeClickPayment($con, $invoice['id']);
|
||||
if ($finalized['success']) {
|
||||
$con->commit();
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => true,
|
||||
'message' => '✅ تم التحقق من عملية الدفع بنجاح! تم تحديث رصيد حسابك.',
|
||||
'invoice' => [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'amount' => $invoice['amount'],
|
||||
'status' => 'completed',
|
||||
],
|
||||
'ai_reason' => $aiResult['reason'] ?? null,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$con->rollBack();
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Verification passed but wallet update failed. Contact support.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
} else {
|
||||
$con->rollBack();
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'message' => 'These funds have already been credited.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
} else {
|
||||
$reason = $aiResult['reason'] ?? 'لم يتم التأكيد';
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => false,
|
||||
'message' => "⚠️ $reason",
|
||||
'ai_reason' => $reason,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("[Nabeh Cliq AI] " . $e->getMessage());
|
||||
printFailure('AI verification service error');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $con->prepare("
|
||||
SELECT $columns, ? AS payment_method
|
||||
FROM $table
|
||||
WHERE $conditions
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 5
|
||||
");
|
||||
$stmt->execute([$paymentMethod, $driverId]);
|
||||
$invoices = $stmt->fetchAll();
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// SMS / SYRIATEL — Status query by phone
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
if ($paymentMethod === 'sms' || $paymentMethod === 'syriatel') {
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, invoice_number, user_phone AS method_phone, amount, status, created_at, ? AS payment_method
|
||||
FROM invoices_sms
|
||||
WHERE phone = ? AND status = 'pending'
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 5
|
||||
");
|
||||
$stmt->execute([$paymentMethod, $phone]);
|
||||
$invoices = $stmt->fetchAll();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => !empty($invoices),
|
||||
'message' => empty($invoices) ? 'لا توجد فواتير معلقة.' : null,
|
||||
'user' => [
|
||||
'id' => $driverId,
|
||||
'phone' => $userPhone,
|
||||
'name' => $userName,
|
||||
],
|
||||
'invoices' => $invoices,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => !empty($invoices),
|
||||
'message' => empty($invoices) ? 'لا توجد فواتير معلقة.' : null,
|
||||
'invoices' => $invoices,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// MTN — Status query by phone
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
if ($paymentMethod === 'mtn') {
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, invoice_number, mtn_phone AS method_phone, amount, status,
|
||||
mtn_transaction_id AS transaction_id, created_at, updated_at AS paid_at, ? AS payment_method
|
||||
FROM mtn_invoices
|
||||
WHERE phone = ? AND status = 'pending'
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 5
|
||||
");
|
||||
$stmt->execute([$paymentMethod, $phone]);
|
||||
$invoices = $stmt->fetchAll();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'verified' => !empty($invoices),
|
||||
'message' => empty($invoices) ? 'لا توجد فواتير معلقة.' : null,
|
||||
'invoices' => $invoices,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// UNKNOWN METHOD
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
printFailure("Invalid payment method: $paymentMethod");
|
||||
|
||||
@@ -7,6 +7,7 @@ include "../../jwtconnect.php";
|
||||
try {
|
||||
$driverID = filterRequest("driverID");
|
||||
$amount_raw = filterRequest("amount");
|
||||
$phone = filterRequest("phone");
|
||||
|
||||
$amount = is_numeric($amount_raw) ? (float) $amount_raw : 0.0;
|
||||
|
||||
@@ -29,8 +30,8 @@ try {
|
||||
} else {
|
||||
// إنشاء فاتورة جديدة برقم عشوائي
|
||||
$invoice_number = random_int(100000, 999999);
|
||||
$stmtIns = $con->prepare("INSERT INTO invoices_shamcash (invoice_number, driverID, amount, status, created_at) VALUES (?, ?, ?, 'pending', NOW())");
|
||||
$stmtIns->execute([$invoice_number, $driverID, $amount]);
|
||||
$stmtIns = $con->prepare("INSERT INTO invoices_shamcash (invoice_number, driverID, phone, amount, status, created_at) VALUES (?, ?, ?, ?, 'pending', NOW())");
|
||||
$stmtIns->execute([$invoice_number, $driverID, $phone ?: null, $amount]);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
|
||||
@@ -6,6 +6,7 @@ include "../../../jwtconnect.php";
|
||||
try {
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$amount_raw = filterRequest("amount");
|
||||
$phone = filterRequest("phone");
|
||||
$amount = is_numeric($amount_raw) ? (float) $amount_raw : 0.0;
|
||||
|
||||
if (empty($passengerID) || $amount <= 0) {
|
||||
@@ -25,8 +26,8 @@ try {
|
||||
$con->prepare("UPDATE invoices_shamcash_passenger SET created_at=NOW() WHERE id=?")->execute([$existing['id']]);
|
||||
} else {
|
||||
$invoice_number = random_int(100000, 999999);
|
||||
$stmtIns = $con->prepare("INSERT INTO invoices_shamcash_passenger (invoice_number, passengerID, amount, status, created_at) VALUES (?, ?, ?, 'pending', NOW())");
|
||||
$stmtIns->execute([$invoice_number, $passengerID, $amount]);
|
||||
$stmtIns = $con->prepare("INSERT INTO invoices_shamcash_passenger (invoice_number, passengerID, phone, amount, status, created_at) VALUES (?, ?, ?, ?, 'pending', NOW())");
|
||||
$stmtIns->execute([$invoice_number, $passengerID, $phone ?: null, $amount]);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
|
||||
@@ -16,6 +16,7 @@ try {
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
$user_phone = filterRequest("user_phone");
|
||||
$phone = filterRequest("phone");
|
||||
$amount_raw = filterRequest("amount");
|
||||
|
||||
// تسجيل البيانات بعد الفلترة
|
||||
@@ -46,10 +47,11 @@ try {
|
||||
// --- 4a. تحديث الفاتورة المعلقة الحالية ---
|
||||
// error_log("[CreateInvoice] Found existing pending invoice (ID: {$existing['id']}). Updating it.");
|
||||
|
||||
$sql_update = "UPDATE invoices_sms SET invoice_number = :invoice_number, amount = :amount, created_at = NOW() WHERE id = :id";
|
||||
$sql_update = "UPDATE invoices_sms SET invoice_number = :invoice_number, phone = :phone, amount = :amount, created_at = NOW() WHERE id = :id";
|
||||
$stmt_update = $con->prepare($sql_update);
|
||||
$stmt_update->execute([
|
||||
':invoice_number' => $new_invoice_number,
|
||||
':phone' => $phone ?: null,
|
||||
':amount' => $amount,
|
||||
':id' => $existing['id']
|
||||
]);
|
||||
@@ -65,11 +67,12 @@ try {
|
||||
// --- 4b. إنشاء فاتورة جديدة ---
|
||||
// error_log("[CreateInvoice] No pending invoice found. Creating a new one.");
|
||||
|
||||
$sql_insert = "INSERT INTO invoices_sms (invoice_number, driverID, user_phone, amount, status) VALUES (:invoice_number, :driverID, :user_phone, :amount, 'pending')";
|
||||
$sql_insert = "INSERT INTO invoices_sms (invoice_number, driverID, phone, user_phone, amount, status) VALUES (:invoice_number, :driverID, :phone, :user_phone, :amount, 'pending')";
|
||||
$stmt_insert = $con->prepare($sql_insert);
|
||||
$ok = $stmt_insert->execute([
|
||||
':invoice_number' => $new_invoice_number,
|
||||
':driverID' => $driverID,
|
||||
':phone' => $phone ?: null,
|
||||
':user_phone' => $user_phone,
|
||||
':amount' => $amount
|
||||
]);
|
||||
|
||||
@@ -17,6 +17,7 @@ try {
|
||||
// -------------------------------------
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$user_phone = filterRequest("user_phone");
|
||||
$phone = filterRequest("phone");
|
||||
$amount_raw = filterRequest("amount");
|
||||
error_log("[CreateInvoicePassenger] Read inputs (passengerID, user_phone, amount)");
|
||||
|
||||
@@ -65,6 +66,7 @@ try {
|
||||
$sql_update = "
|
||||
UPDATE invoices_sms_passenger
|
||||
SET invoice_number = :invoice_number,
|
||||
phone = :phone,
|
||||
amount = :amount,
|
||||
created_at = NOW()
|
||||
WHERE id = :id
|
||||
@@ -72,6 +74,7 @@ try {
|
||||
$stmt_update = $con->prepare($sql_update);
|
||||
$stmt_update->execute([
|
||||
':invoice_number' => $new_invoice_number,
|
||||
':phone' => $phone ?: null,
|
||||
':amount' => $amount,
|
||||
':id' => $existing['id']
|
||||
]);
|
||||
@@ -89,13 +92,14 @@ try {
|
||||
// -------------------------------------
|
||||
error_log("[CreateInvoicePassenger] No existing invoice. Creating new one...");
|
||||
$sql_insert = "
|
||||
INSERT INTO invoices_sms_passenger (invoice_number, passengerID, user_phone, amount, status)
|
||||
VALUES (:invoice_number, :passengerID, :user_phone, :amount, 'pending')
|
||||
INSERT INTO invoices_sms_passenger (invoice_number, passengerID, phone, user_phone, amount, status)
|
||||
VALUES (:invoice_number, :passengerID, :phone, :user_phone, :amount, 'pending')
|
||||
";
|
||||
$stmt_insert = $con->prepare($sql_insert);
|
||||
$ok = $stmt_insert->execute([
|
||||
':invoice_number' => $new_invoice_number,
|
||||
':passengerID' => $passengerID,
|
||||
':phone' => $phone ?: null,
|
||||
':user_phone' => $user_phone,
|
||||
':amount' => $amount
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user