'error', 'message' => 'Authentication failed. Invalid or missing token.']); exit; } try { // يفترض أن MTN سترسل رقم هاتف المستخدم للاستعلام عنه //$mtnPhone = filterRequest("mtn_phone"); $mtnPhone = $_GET['phone_number'] ?? null; if (empty($mtnPhone)) { echo json_encode(["status" => "error", "message" => "Phone number is required."]); http_response_code(400); exit; } // البحث عن فاتورة معلقة لهذا الرقم $stmt = $con->prepare( "SELECT invoice_number, amount, user_id, user_type FROM `mtn_invoices` WHERE `mtn_phone` = :mtn_phone AND `status` = 'pending' ORDER BY `created_at` DESC LIMIT 1" ); $stmt->execute([':mtn_phone' => $mtnPhone]); $invoice = $stmt->fetch(PDO::FETCH_ASSOC); if ($invoice) { // تم العثور على فاتورة، يتم إرجاع تفاصيلها لنظام MTN echo json_encode([ "status" => "success", "statusInvoice" => "pending", "invoice_number" => $invoice['invoice_number'], "amount" => (float) $invoice['amount'], "description" => "شحن نقاط في تطبيق انطلق", // وصف يظهر للمستخدم في تطبيق MTN "biller_name" => "Intaleq App" ]); } else { // لا توجد فاتورة معلقة echo json_encode(["status" => "error", "message" => "No pending invoice found for this number."]); http_response_code(404); } } catch (Exception $e) { error_log("Error in query_mtn_invoice.php: " . $e->getMessage()); echo json_encode(["status" => "error", "message" => "Internal server error."]); http_response_code(500); } ?>