diff --git a/shalom_api.php b/shalom_api.php index e1c6170..bead474 100644 --- a/shalom_api.php +++ b/shalom_api.php @@ -13,14 +13,23 @@ if (!$orderNumber || !$orderCode) { // 2. Configurar la llamada a la API de Shalom $apiKey = 'sk_mlq1j3na_4a676ewvaop'; -// La URL del endpoint de tracking según la documentación inferida. -$url = "https://shalom-api.lat/api/tracking/$orderNumber/$orderCode"; +$url = "https://shalom-api.lat/api/track"; // Endpoint correcto para POST + +// Datos para el cuerpo de la solicitud POST +$postData = [ + 'orderNumber' => $orderNumber, + 'orderCode' => $orderCode +]; +$jsonData = json_encode($postData); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_POST, true); // Especificar que es una solicitud POST +curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); // Enviar los datos en formato JSON curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', 'Accept: application/json', "Authorization: Bearer {$apiKey}" ]); diff --git a/test_pedidos.php b/test_pedidos.php index 4907ade..04c6dc7 100644 --- a/test_pedidos.php +++ b/test_pedidos.php @@ -195,7 +195,58 @@ include 'layout_header.php'; - + + $nombre_cliente, + '{PRODUCTO}' => $producto, + '{SEDE_ENVIO}' => $sede_envio, + '{MONTO_TOTAL}' => number_format($monto_total, 2), + '{ADELANTO}' => number_format($adelanto, 2), + '{SALDO_PENDIENTE}' => number_format($monto_debe, 2) + ]; + + $whatsappMessage = str_replace(array_keys($replacements), array_values($replacements), $template); + $whatsappMessage = urlencode($whatsappMessage); + + $celular = preg_replace('/[^0-9]/', '', $pedido['celular']); + if (strlen($celular) == 9) { + $celular = '51' . $celular; + } + + $whatsappUrl = "https://api.whatsapp.com/send?phone={$celular}&text={$whatsappMessage}"; + ?> +
+ + 💬 +
+ @@ -303,9 +354,81 @@ document.addEventListener('DOMContentLoaded', function() { // 4. Display the result if (data.error) { modalStatusDiv.innerHTML = `

Error: ${data.error}

`; + } else if (data.search && data.search.success) { + const searchData = data.search.data; + const statusData = data.statuses.data; + const statusMessage = data.statuses.message || 'No disponible'; + + let html = ` +
+
Estado: ${statusMessage}
+
+ +
+
+
+
Origen
+
+

${searchData.origen.nombre}

+

${searchData.origen.direccion}

+
+
+
+
+
+
Destino
+
+

${searchData.destino.nombre}

+

${searchData.destino.direccion}

+
+
+
+
+ +
+
Detalles del Envío
+ +
+ +
+
Historial de Estados
+
+ `; + + const timeline = [ + { name: 'Registrado', data: statusData.registrado }, + { name: 'En Origen', data: statusData.origen }, + { name: 'En Tránsito', data: statusData.transito }, + { name: 'En Destino', data: statusData.destino }, + { name: 'En Reparto', data: statusData.reparto }, + { name: 'Entregado', data: statusData.entregado } + ]; + + timeline.forEach(item => { + if (item.data && item.data.fecha) { + html += `

${item.name}: ${new Date(item.data.fecha).toLocaleString('es-PE', { timeZone: 'America/Lima' })}

`; + } else { + html += `

${item.name}: Pendiente

`; + } + }); + + html += ` +
+
+ `; + + + + + modalStatusDiv.innerHTML = html; } else { - // Assuming the response is a JSON object, pretty-print it - modalStatusDiv.innerHTML = `
${JSON.stringify(data, null, 2)}
`; + modalStatusDiv.innerHTML = `

No se pudo encontrar la guía o la respuesta no es válida.

${JSON.stringify(data, null, 2)}
`; } }) .catch(error => {