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

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 منتجات الإنترنت جميع بطاقات الإنترنت ADSL و4G LTE المتاحة مع أسعارها وقيمها. يُنصح بالتخزين المؤقت لبيانات المنتجات لتقليل استدعاءات API.
خزّن بيانات المنتجات مؤقتاً لمدة 1-4 ساعات. الأسعار والتوفر تتغير بصورة منتظمة.

مرجع API

GET /v3/internet/products

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

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

async function loadInternetProducts(type) {
  const url = new URL('https://api.oneclickdz.com/v3/internet/products');
  if (type) url.searchParams.set('type', type);

  const response = await fetch(url.toString(), {
    headers: {
      "X-Access-Token": process.env.API_KEY,
    },
  });

  if (!response.ok) {
    throw new Error(`Failed to load products: ${response.status}`);
  }

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

// Usage
const adslProducts = await loadInternetProducts('ADSL');
const products4G = await loadInternetProducts('4G');

console.log(`ADSL products: ${adslProducts.length}`);
console.log(`4G products: ${products4G.length}`);

بنية الاستجابة

{
  "success": true,
  "data": [
    {
      "value": 500,
      "cost": 450,
      "available": true
    },
    {
      "value": 1000,
      "cost": 900,
      "available": true
    },
    {
      "value": 500,
      "cost": 470,
      "available": false
    }
  ]
}

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

class ProductCache {
  constructor(ttlMs = 2 * 60 * 60 * 1000) { // 2 hours
    this.cache = {};
    this.cachedAt = {};
    this.ttlMs = ttlMs;
  }

  isExpired(type) {
    if (!this.cachedAt[type]) return true;
    return Date.now() - this.cachedAt[type] > this.ttlMs;
  }

  async get(type) {
    if (this.isExpired(type)) {
      console.log(`Cache expired for ${type}, fetching fresh products...`);
      this.cache[type] = await loadInternetProducts(type);
      this.cachedAt[type] = Date.now();
    }
    return this.cache[type];
  }
}

const productCache = new ProductCache();

// Usage
const adslProducts = await productCache.get('ADSL');
const products4G = await productCache.get('4G');

الحصول على المنتجات المتاحة

function getAvailableProducts(products) {
  return products.filter(p => p.available);
}

// Usage
const allProducts = await cache.get('ADSL');
const available = getAvailableProducts(allProducts);

console.log(`${available.length}/${allProducts.length} products in stock`);

تطبيق هامش الربح

function applyMarkup(products, markupPercent = 5) {
  return products
    .filter(p => p.available)
    .map(p => ({
      value: p.value,
      wholesaleCost: p.cost,
      customerPrice: Math.ceil(p.cost * (1 + markupPercent / 100)),
      available: true,
    }));
}

// Usage
const products = await cache.get('ADSL');
const customerPrices = applyMarkup(products, 5); // 5% markup

customerPrices.forEach(p => {
  console.log(`${p.value} DA card: ${p.customerPrice} DA`);
});

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

التخزين المؤقت 5-10 دقائق

وازن بين التحديث وتقليل استدعاءات API

تصفية المتاح فقط

اعرض فقط المنتجات التي available: true

إخفاء أسعار الجملة

لا تعرض قيم cost الخام للعملاء

معالجة الأخطاء بلطف

استخدم البيانات المخزنة مؤقتاً إذا كان API غير متاح مؤقتاً

بناء واجهة عرض المنتجات

مثال على هيكل عرض المنتجات للعملاء:
async function buildProductOptions(type, markupPercent = 5) {
  const products = await cache.get(type);
  
  return {
    serviceType: type,
    serviceName: type === 'ADSL' ? 'ADSL Internet' : '4G LTE Internet',
    options: products
      .filter(p => p.available)
      .map(p => ({
        value: p.value,
        label: `${p.value} DA`,
        price: Math.ceil(p.cost * (1 + markupPercent / 100)),
        inStock: true,
      }))
      .sort((a, b) => a.value - b.value)
  };
}

// Usage
const adslOptions = await buildProductOptions('ADSL', 5);
const lteOptions = await buildProductOptions('4G', 5);

تحميل نوعَي الخدمة معاً

استرجع منتجات ADSL و4G بالتوازي:
async function loadAllInternetProducts() {
  const [adsl, lte] = await Promise.all([
    cache.get('ADSL'),
    cache.get('4G'),
  ]);
  
  return {
    adsl: applyMarkup(adsl, 5),
    lte: applyMarkup(lte, 5),
  };
}

// Usage
const allProducts = await loadAllInternetProducts();
console.log('ADSL:', allProducts.adsl.length, 'products');
console.log('4G:', allProducts.lte.length, 'products');

معالجة الأخطاء

async function loadProductsSafely(type) {
  try {
    return await cache.get(type);
  } catch (error) {
    console.error(`Failed to load ${type} products:`, error);
    
    // Return stale cached data if available
    const cached = cache.cache.get(type);
    if (cached) {
      console.log('Using stale cached data');
      return cached.data;
    }
    
    throw new Error(`${type} products unavailable`);
  }
}

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

التحقق من الأرقام

التحقق من أرقام الهاتف قبل الإرسال

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

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

مرجع API

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

نظرة عامة

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

تتبع الحالة

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

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

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