Passer au contenu principal

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.

Vue d’ensemble

Bonnes pratiques pour interroger les endpoints API afin de suivre efficacement le statut des commandes.

Modèle de base d’interrogation

async function pollStatus(checkFunction, options = {}) {
  const {
    maxAttempts = 60,
    interval = 5000,
    finalStates = ["FULFILLED", "REFUNDED"],
  } = options;

  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    const result = await checkFunction();

    if (finalStates.includes(result.status)) {
      return result;
    }

    if (attempt < maxAttempts) {
      await new Promise((resolve) => setTimeout(resolve, interval));
    }
  }

  throw new Error("Polling timeout");
}

// Usage
const result = await pollStatus(() => checkTopupStatus(topupId), {
  maxAttempts: 60,
  interval: 5000,
});

Interrogation spécifique par service

Recharges mobiles (5 minutes max)

async function pollMobileTopup(topupId) {
  return await pollStatus(() => checkMobileStatus(topupId), {
    maxAttempts: 60,
    interval: 5000,
    finalStates: ["FULFILLED", "REFUNDED", "UNKNOWN_ERROR"],
  });
}

Recharges internet (5 minutes max)

async function pollInternetTopup(topupId) {
  return await pollStatus(() => checkInternetStatus(topupId), {
    maxAttempts: 60,
    interval: 5000,
    finalStates: ["FULFILLED", "REFUNDED", "QUEUED"],
  });
}

Cartes cadeaux (10 minutes max)

async function pollGiftCardOrder(orderId) {
  return await pollStatus(() => checkGiftCardOrder(orderId), {
    maxAttempts: 120,
    interval: 5000,
    finalStates: ["FULFILLED", "PARTIALLY_FILLED", "REFUNDED"],
  });
}

Bonnes pratiques

Définir des délais d'attente

Définissez toujours une durée d’interrogation maximale

Gérer les erreurs

Capturez et gérez les délais d’interrogation

Journaliser la progression

Suivez les tentatives d’interrogation pour le débogage

États finaux

Définissez des états terminaux clairs

Paramètres recommandés

ServiceIntervalleDurée maxÉtats finaux
Mobile5s5 minFULFILLED, REFUNDED, UNKNOWN_ERROR
Internet5s5 minFULFILLED, REFUNDED, QUEUED
Cartes cadeaux5s10 minFULFILLED, PARTIALLY_FILLED, REFUNDED

Liens utiles

Guide Recharge Mobile

Workflow d’intégration mobile complet

Gestion des erreurs

Gérer correctement les erreurs

Webhooks

Notifications de statut en temps réel

Bonnes pratiques

Bonnes pratiques de sécurité