'CMD-2026-00123', // OBLIGATOIRE — votre référence unique * 'customer_name' => 'Awa Kone', // OBLIGATOIRE * 'customer_phone' => '+2250700000000', // OBLIGATOIRE * 'customer_address' => 'Cocody, Abidjan', // optionnel * 'customer_city' => 'Abidjan', // optionnel * 'customer_country' => "Côte d'Ivoire", // optionnel * 'currency' => 'FCFA', // optionnel (défaut FCFA) * 'notes' => 'Paiement à la livraison', // optionnel * ] * @param array $items Articles (au moins un) : * [ * [ * 'name' => 'Montre LED Sport', // OBLIGATOIRE * 'quantity' => 2, // OBLIGATOIRE (entier ≥ 1) * 'unit_price' => 7500, // OBLIGATOIRE (nombre ≥ 0) * 'sku' => 'MTR-001', // recommandé : id stable du produit chez vous * 'variant' => 'Noir', // optionnel : variante lisible * ], * ] * * @return bool true si la commande a été acceptée par EcomCloser */ function ecomcloser_push(array $order, array $items): bool { try { if (ECOMCLOSER_KEY === '' || ECOMCLOSER_KEY === 'eck_collez_votre_cle_ici') { return false; // pas encore configuré — ignoré silencieusement } $payload = array_merge($order, [ 'source' => ECOMCLOSER_SOURCE_NAME, 'items' => $items, ]); $ch = curl_init('https://ecomcloser.livrezmoa.com/api/integrations/orders'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload, JSON_UNESCAPED_UNICODE), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Accept: application/json', 'X-Integration-Key: ' . ECOMCLOSER_KEY, ], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 5, ]); $body = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); if ($http >= 200 && $http < 300) { $json = json_decode((string) $body, true); ecomcloser_log('✅ Commande ' . ($order['external_order_id'] ?? '?') . ' poussée (HTTP ' . $http . ', ordre EcomCloser #' . ($json['order']['id'] ?? '?') . ')'); return true; } // 401 = clé invalide · 403 = compte inactif · 422 = payload invalide (détail dans $body) ecomcloser_log('❌ Échec push ' . ($order['external_order_id'] ?? '?') . ' (HTTP ' . $http . ($err ? ', cURL: ' . $err : '') . ') ' . substr((string) $body, 0, 300)); return false; } catch (Throwable $e) { ecomcloser_log('❌ Exception : ' . $e->getMessage()); return false; } } /** Journalise dans logs/ecomcloser.log à côté de ce fichier (silencieux si impossible). */ function ecomcloser_log(string $message): void { $dir = __DIR__ . '/logs'; if (!is_dir($dir)) { @mkdir($dir, 0755, true); } @file_put_contents($dir . '/ecomcloser.log', '[' . date('Y-m-d H:i:s') . "] $message\n", FILE_APPEND); } // ═══ EXEMPLE D'UTILISATION ═══════════════════════════════════════════════════ // // require_once __DIR__ . '/ecomcloser-push.php'; // // ecomcloser_push( // [ // 'external_order_id' => $reference, // votre référence de commande // 'customer_name' => $nomClient, // 'customer_phone' => $telephoneClient, // 'customer_address' => $adresseLivraison, // 'customer_city' => $ville, // 'notes' => 'Paiement à la livraison', // ], // array_map(fn ($ligne) => [ // 'name' => $ligne['nom_produit'], // 'sku' => 'prod-' . $ligne['produit_id'], // 'quantity' => (int) $ligne['quantite'], // 'unit_price' => (float) $ligne['prix_unitaire'], // 'variant' => $ligne['variante'] ?? null, // ], $lignesDeLaCommande) // );