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.
نظرة عامة قبل إرسال طلب الشحن، تحقق من صحة جميع المدخلات لتجنب الأخطاء وضمان تجربة مستخدم سلسة. التحقق السليم يقلل من أخطاء API ويحسن تجربة المستخدم من خلال اكتشاف الأخطاء مبكرًا.
التحقق من رقم الهاتف يجب أن تتطابق أرقام الهاتف مع هذا النمط: ^0[567][0-9]{8}$ المتطلبات:
يجب أن يبدأ بـ 0
يجب أن يكون الرقم الثاني 5 أو 6 أو 7
10 أرقام بالضبط
أرقام فقط بدون رموز أخرى
أمثلة صحيحة
أمثلة غير صحيحة
✅ "0778037340"
✅ "0665983439"
✅ "0556121212"
❌ "778037340" - الصفر الأول مفقود
❌ "+213778037340" - التنسيق الدولي
❌ "0778 037 340" - يحتوي على مسافات
function validatePhoneNumber ( phone ) {
if ( typeof phone !== 'string' ) {
return { valid: false , error: 'Phone number must be a string' };
}
phone = phone . trim ();
if ( ! / ^ 0 [ 567 ][ 0-9 ] {8} $ / . test ( phone )) {
return { valid: false , error: 'Invalid phone format. Must be 10 digits starting with 05, 06, or 07' };
}
return { valid: true , phone };
}
التحقق من الباقة تحقق من أن الباقة المختارة موجودة ومتاحة: function validatePlan ( planCode , plans ) {
const plan = plans . find ( p => p . code === planCode );
if ( ! plan ) {
return { valid: false , error: `Plan ${ planCode } not found` };
}
if ( ! plan . isEnabled ) {
return { valid: false , error: `Plan ${ plan . name } is currently unavailable` };
}
return { valid: true , plan };
}
التحقق من المبلغ تحقق من صحة المبالغ بناءً على نوع الباقة (ديناميكية أو ثابتة): function validateAmount ( amount , plan ) {
// Fixed plans use their predefined amount
if ( plan . type === 'fixed' ) {
return { valid: true , amount: plan . fixedAmount };
}
// Dynamic plans require amount within range
if ( ! amount ) {
return { valid: false , error: 'Amount is required for dynamic plans' };
}
const numAmount = Number ( amount );
if ( isNaN ( numAmount ) || ! Number . isInteger ( numAmount )) {
return { valid: false , error: 'Amount must be an integer' };
}
if ( numAmount < plan . minAmount ) {
return { valid: false , error: `Amount must be at least ${ plan . minAmount } DZD` };
}
if ( numAmount > plan . maxAmount ) {
return { valid: false , error: `Amount cannot exceed ${ plan . maxAmount } DZD` };
}
return { valid: true , amount: numAmount };
}
التحقق الكامل ادمج جميع عمليات التحقق: function validateTopUpRequest ( data , plans ) {
const errors = [];
// Validate phone
const phoneValidation = validatePhoneNumber ( data . phone );
if ( ! phoneValidation . valid ) {
errors . push ({ field: 'phone' , message: phoneValidation . error });
}
// Validate plan
const planValidation = validatePlan ( data . planCode , plans );
if ( ! planValidation . valid ) {
errors . push ({ field: 'planCode' , message: planValidation . error });
return { valid: false , errors };
}
// Validate amount
const amountValidation = validateAmount ( data . amount , planValidation . plan );
if ( ! amountValidation . valid ) {
errors . push ({ field: 'amount' , message: amountValidation . error });
}
if ( errors . length > 0 ) {
return { valid: false , errors };
}
return {
valid: true ,
data: {
phone: phoneValidation . phone ,
planCode: planValidation . plan . code ,
amount: amountValidation . amount
}
};
}
// Usage
const result = validateTopUpRequest ({
phone: '0778037340' ,
planCode: 'PREPAID_DJEZZY' ,
amount: 500
}, plans );
if ( ! result . valid ) {
console . error ( 'Validation errors:' , result . errors );
} else {
console . log ( 'Valid request:' , result . data );
}
أفضل الممارسات
تحقق من المدخلات في واجهة المستخدم قبل إجراء استدعاءات API لتحسين تجربة المستخدم.
التحقق دائمًا من جهة الخادم
لا تثق أبدًا بمدخلات العميل. تحقق دائمًا من جهة الخادم.
اعرض رسائل خطأ محددة تساعد المستخدمين على إصلاح المشكلات.
أزل المسافات وقم بتوحيد المدخلات قبل التحقق.
الخطوات التالية
الخطوة 3: إرسال الشحنات تعرف على كيفية إرسال طلبات الشحن