65 lines
2.6 KiB
PHP
Executable File
65 lines
2.6 KiB
PHP
Executable File
<?php
|
|
// --- query_mtn_invoice.php ---
|
|
// هذا السكربت هو نقطة الـ Webhook التي سيستدعيها نظام MTN
|
|
// للاستعلام عن وجود فاتورة دفع معلقة للمستخدم قبل أن يدفع
|
|
|
|
include "../../jwtconnect.php"; // تأكد من أن هذا المسار صحيح
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
// يمكن إضافة طبقة حماية هنا للتحقق من أن الطلب قادم من سيرفرات MTN
|
|
// مثلاً عبر التحقق من IP أو من وجود Secret Key في الـ Headers
|
|
// --- آلية الحماية ---
|
|
$shared_secret_key = trim(file_get_contents('/home/intaleq-wallet/.mtnKey'));
|
|
$receivedToken = $_SERVER['HTTP_X_AUTH_TOKEN'] ?? '';
|
|
|
|
if ($receivedToken !== $shared_secret_key) {
|
|
http_response_code(401); // Unauthorized
|
|
echo json_encode(['status' => '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);
|
|
}
|
|
?>
|