الانتقال إلى المحتوى الرئيسي

Documentation Index

Fetch the complete documentation index at: https://docs.oneclickdz.com/llms.txt

Use this file to discover all available pages before exploring further.

نظرة عامة

تحقق من أرقام الهاتف قبل إرسال شحنات الإنترنت لتقليل فشل الطلبات وتحسين تجربة العملاء. endpoint التحقق يتحقق من صحة التنسيق ومن ارتباط الرقم بالخدمة المطلوبة.
يُعدّ التحقق خطوة إلزامية قبل إرسال أي طلب شحن لتجنب رسوم الطلبات الفاشلة.

مرجع API

POST /v3/internet/check-number

التوثيق الكامل للـ endpoint

أنماط صياغة الأرقام

ADSL

أرقام ADSL هي أرقام هاتف أرضي جزائرية بالتنسيق: 0XX XXX XXXX
036362608  → صحيح (ولاية برج بوعريريج)
031562900  → صحيح (ولاية عنابة)
029000000  → صحيح (ولاية ورقلة)

4G

أرقام 4G هي أرقام هواتف محمولة جزائرية: 06X XXX XXXX أو 07X XXX XXXX
0661234567 → صحيح (Djezzy)
0771234567 → صحيح (Mobilis)
0551234567 → صحيح (Ooredoo)

التحقق الأساسي

async function validateInternetNumber(type, number) {
  const response = await fetch(
    "https://api.oneclickdz.com/v3/internet/check-number",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Access-Token": process.env.API_KEY,
      },
      body: JSON.stringify({ type, number }),
    }
  );

  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.error?.message || `Validation failed: ${response.status}`);
  }

  const result = await response.json();
  return result.data;
}

// Usage
try {
  const validation = await validateInternetNumber('ADSL', '036362608');
  console.log('Number is valid:', validation);
} catch (error) {
  console.error('Validation failed:', error.message);
}

مثال على الاستجابة

رقم صحيح

{
  "success": true,
  "data": {
    "valid": true,
    "type": "ADSL",
    "number": "036362608"
  }
}

رقم غير صحيح

{
  "success": false,
  "error": {
    "code": "err_phone",
    "message": "Invalid phone number for ADSL service"
  }
}

التحقق المسبق من التنسيق

تحقق من التنسيق محلياً قبل استدعاء API:
function prevalidateNumber(type, number) {
  const cleaned = number.replace(/\s+/g, '');

  if (type === 'ADSL') {
    // Algerian landline: 0XX XXXXXXX
    const adslPattern = /^0[2-9]\d{7,8}$/;
    if (!adslPattern.test(cleaned)) {
      return {
        valid: false,
        error: 'ADSL numbers must be Algerian landline numbers (e.g., 036362608)'
      };
    }
  } else if (type === '4G') {
    // Algerian mobile: 06X or 07X followed by 8 digits
    const mobilePattern = /^0[67]\d{8}$/;
    if (!mobilePattern.test(cleaned)) {
      return {
        valid: false,
        error: '4G numbers must be Algerian mobile numbers (e.g., 0661234567)'
      };
    }
  }

  return { valid: true, cleaned };
}

التحقق الكامل من الإدخال

async function validateCompleteFlow(type, number) {
  // Step 1: Validate service type
  if (!['ADSL', '4G'].includes(type)) {
    return {
      valid: false,
      error: 'INVALID_TYPE',
      message: 'Service type must be ADSL or 4G'
    };
  }

  // Step 2: Client-side format check
  if (!validateFormat(type, number)) {
    return {
      valid: false,
      error: 'INVALID_FORMAT',
      message: type === 'ADSL' 
        ? 'ADSL numbers must be 9 digits starting with 0 (e.g., 036362608)'
        : '4G numbers must be 12 digits starting with 213 (e.g., 213665983439)'
    };
  }

  // Step 3: API validation
  try {
    await validateInternetNumber(type, number);
    return { valid: true, type, number };
  } catch (error) {
    return {
      valid: false,
      error: 'API_VALIDATION_FAILED',
      message: error.message
    };
  }
}

// Usage
const result = await validateCompleteFlow('ADSL', '036362608');

if (!result.valid) {
  console.error(`Validation failed: ${result.message}`);
} else {
  console.log('✅ Ready to place order');
}

تخزين نتائج التحقق مؤقتاً

class ValidationCache {
  constructor(ttlMs = 5 * 60 * 1000) { // 5 minutes
    this.cache = new Map();
    this.ttlMs = ttlMs;
  }

  getKey(type, number) {
    return `${type}:${number}`;
  }

  get(type, number) {
    const key = this.getKey(type, number);
    const entry = this.cache.get(key);

    if (!entry) return null;
    if (Date.now() - entry.timestamp > this.ttlMs) {
      this.cache.delete(key);
      return null;
    }

    return entry.result;
  }

  set(type, number, result) {
    const key = this.getKey(type, number);
    this.cache.set(key, { result, timestamp: Date.now() });
  }
}

const validationCache = new ValidationCache();

async function validateWithCache(type, number) {
  const cached = validationCache.get(type, number);
  if (cached) return cached;

  const result = await validateInternetNumber(type, number);
  validationCache.set(type, number, result);
  return result;
}

أفضل الممارسات

التحقق المبكر

تحقق من التنسيق من جهة العميل قبل استدعاء API

رسائل واضحة

قدّم رسائل خطأ محددة ومفيدة

التخزين المؤقت للنتائج

خزّن الأرقام الصحيحة مؤقتاً لمدة 5 دقائق

ملاحظات مرئية

أظهر حالة التحقق في الوقت الفعلي أثناء الكتابة

رسائل خطأ واضحة للمستخدم

قدّم ملاحظات واضحة بناءً على نوع الخطأ:
function getValidationErrorMessage(type, error) {
  const messages = {
    INVALID_TYPE: 'Please select either ADSL or 4G service type.',
    
    INVALID_FORMAT: {
      ADSL: 'Please enter a valid ADSL number (9 digits starting with 0).\nExample: 036362608',
      '4G': 'Please enter a valid 4G number (12 digits starting with 213).\nExample: 213665983439'
    },
    
    API_VALIDATION_FAILED: {
      default: 'This number is not valid for the selected service type.',
      'ERR_PHONE': 'This number cannot be used for internet recharge.'
    }
  };
  
  if (error === 'INVALID_FORMAT') {
    return messages.INVALID_FORMAT[type];
  }
  
  if (error === 'API_VALIDATION_FAILED') {
    return messages.API_VALIDATION_FAILED.default;
  }
  
  return messages[error] || 'Unable to validate number. Please try again.';
}

اختبار التحقق

async function testValidation() {
  const testCases = [
    // ADSL tests
    { type: 'ADSL', number: '036362608', expected: true },
    { type: 'ADSL', number: '031417237', expected: true },
    { type: 'ADSL', number: '36362608', expected: false },  // Missing 0
    { type: 'ADSL', number: '0363626081', expected: false }, // Too long
    
    // 4G tests
    { type: '4G', number: '213665983439', expected: true },
    { type: '4G', number: '213472731602', expected: true },
    { type: '4G', number: '0665983439', expected: false },   // Wrong format
    { type: '4G', number: '+213665983439', expected: false }, // Has +
  ];

  console.log('🧪 Testing validation...\n');

  for (const test of testCases) {
    const result = await validateCompleteFlow(test.type, test.number);
    const passed = result.valid === test.expected;
    
    console.log(
      `${passed ? '✅' : '❌'} ${test.type} ${test.number}: ${result.valid ? 'VALID' : 'INVALID'}`
    );
    
    if (!passed) {
      console.log(`  Expected: ${test.expected}, Got: ${result.valid}`);
    }
  }
}

الخطوات التالية

إرسال الشحنات

تقديم طلبات الشحن المُتحقق منها

تحميل المنتجات

جلب البطاقات المتاحة

مرجع API

التوثيق الكامل للـ endpoint

نظرة عامة

العودة إلى نظرة عامة على التكامل

تتبع الحالة

متابعة تنفيذ الطلبات

تسليم البطاقات

تسليم رموز البطاقات بأمان