Autosave: 20260217-053817
This commit is contained in:
parent
47257c628c
commit
61ccd5cda6
@ -13,14 +13,23 @@ if (!$orderNumber || !$orderCode) {
|
|||||||
|
|
||||||
// 2. Configurar la llamada a la API de Shalom
|
// 2. Configurar la llamada a la API de Shalom
|
||||||
$apiKey = 'sk_mlq1j3na_4a676ewvaop';
|
$apiKey = 'sk_mlq1j3na_4a676ewvaop';
|
||||||
// La URL del endpoint de tracking según la documentación inferida.
|
$url = "https://shalom-api.lat/api/track"; // Endpoint correcto para POST
|
||||||
$url = "https://shalom-api.lat/api/tracking/$orderNumber/$orderCode";
|
|
||||||
|
// Datos para el cuerpo de la solicitud POST
|
||||||
|
$postData = [
|
||||||
|
'orderNumber' => $orderNumber,
|
||||||
|
'orderCode' => $orderCode
|
||||||
|
];
|
||||||
|
$jsonData = json_encode($postData);
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
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, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
'Accept: application/json',
|
'Accept: application/json',
|
||||||
"Authorization: Bearer {$apiKey}"
|
"Authorization: Bearer {$apiKey}"
|
||||||
]);
|
]);
|
||||||
|
|||||||
129
test_pedidos.php
129
test_pedidos.php
@ -195,7 +195,58 @@ include 'layout_header.php';
|
|||||||
<td><?php echo htmlspecialchars($pedido['id']); ?></td>
|
<td><?php echo htmlspecialchars($pedido['id']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($pedido['nombre_completo']); ?></td>
|
<td><?php echo htmlspecialchars($pedido['nombre_completo']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($pedido['dni_cliente'] ?? 'N/A'); ?></td>
|
<td><?php echo htmlspecialchars($pedido['dni_cliente'] ?? 'N/A'); ?></td>
|
||||||
<td><?php echo htmlspecialchars($pedido['celular']); ?></td>
|
<td>
|
||||||
|
<?php
|
||||||
|
echo htmlspecialchars($pedido['celular']);
|
||||||
|
|
||||||
|
// Prepare WhatsApp message
|
||||||
|
$nombre_cliente = $pedido['nombre_completo'];
|
||||||
|
$producto = $pedido['producto'];
|
||||||
|
// The user template has {CIUDAD} / {AGENCIA}, we'll use sede_envio for both.
|
||||||
|
$sede_envio = $pedido['sede_envio'] ?? 'su agencia de destino';
|
||||||
|
$monto_total = (float)($pedido['monto_total'] ?? 0);
|
||||||
|
$monto_debe = (float)($pedido['monto_debe'] ?? 0);
|
||||||
|
$adelanto = $monto_total - $monto_debe;
|
||||||
|
|
||||||
|
$template = "PLANTILLA – AVISO DE CLAVE DE RECOJO SHALOM\n\n"
|
||||||
|
. "Estimado(a) {NOMBRE_CLIENTE} 👋\n"
|
||||||
|
. "Le informamos que su pedido de {PRODUCTO} ya se encuentra disponible en su ciudad 📦\n\n"
|
||||||
|
. "📍 Lugar de recojo: Shalom – {SEDE_ENVIO}\n\n"
|
||||||
|
. "💰 Detalle de pago:\n"
|
||||||
|
. "• Monto total del pedido: S/ {MONTO_TOTAL}\n"
|
||||||
|
. "• Adelanto realizado: S/ {ADELANTO} ✅\n"
|
||||||
|
. "• Saldo pendiente: S/ {SALDO_PENDIENTE}\n\n"
|
||||||
|
. "Para continuar, le solicitamos enviar la captura de su pago restante por este medio 📄\n\n"
|
||||||
|
. "Una vez confirmado su pago ✅, le enviaremos su clave de recojo 🔐, para que pueda retirar su pedido en la agencia sin inconvenientes 📦\n\n"
|
||||||
|
. "Quedamos atentos a su confirmación.\n"
|
||||||
|
. "Muchas gracias por su confianza 🤝\n\n"
|
||||||
|
. "Floower Store 🛍️\n"
|
||||||
|
. "Área de Atención al Cliente";
|
||||||
|
|
||||||
|
$replacements = [
|
||||||
|
'{NOMBRE_CLIENTE}' => $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}";
|
||||||
|
?>
|
||||||
|
<div class="mt-1">
|
||||||
|
<button type="button" class="btn btn-sm btn-info" title="Consultar Estado" data-bs-toggle="modal" data-bs-target="#trackingModal" data-order-number="<?php echo htmlspecialchars($pedido['codigo_rastreo'] ?? 'N/A'); ?>" data-order-code="<?php echo htmlspecialchars($pedido['codigo_tracking'] ?? 'N/A'); ?>">🔍</button>
|
||||||
|
<a href="<?php echo $whatsappUrl; ?>" target="_blank" class="btn btn-sm btn-success" title="Enviar WhatsApp">💬</a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td><?php echo htmlspecialchars($pedido['producto']); ?></td>
|
<td><?php echo htmlspecialchars($pedido['producto']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td>
|
<td><?php echo htmlspecialchars($pedido['sede_envio'] ?? 'N/A'); ?></td>
|
||||||
<td><?php echo htmlspecialchars($pedido['cantidad'] ?: 1); ?></td>
|
<td><?php echo htmlspecialchars($pedido['cantidad'] ?: 1); ?></td>
|
||||||
@ -303,9 +354,81 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// 4. Display the result
|
// 4. Display the result
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
modalStatusDiv.innerHTML = `<p class="text-danger text-center"><strong>Error:</strong> ${data.error}</p>`;
|
modalStatusDiv.innerHTML = `<p class="text-danger text-center"><strong>Error:</strong> ${data.error}</p>`;
|
||||||
|
} 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 = `
|
||||||
|
<div class="alert alert-info text-center">
|
||||||
|
<h5 class="alert-heading mb-0">Estado: ${statusMessage}</h5>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header"><strong>Origen</strong></div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text mb-1">${searchData.origen.nombre}</p>
|
||||||
|
<p class="card-text mb-0"><small class="text-muted">${searchData.origen.direccion}</small></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header"><strong>Destino</strong></div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text mb-1">${searchData.destino.nombre}</p>
|
||||||
|
<p class="card-text mb-0"><small class="text-muted">${searchData.destino.direccion}</small></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header"><strong>Detalles del Envío</strong></div>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<li class="list-group-item"><strong>Remitente:</strong> ${searchData.remitente.nombre}</li>
|
||||||
|
<li class="list-group-item"><strong>Destinatario:</strong> ${searchData.destinatario.nombre}</li>
|
||||||
|
<li class="list-group-item"><strong>Fecha de Emisión:</strong> ${new Date(searchData.fecha_emision).toLocaleString('es-PE', { timeZone: 'America/Lima' })}</li>
|
||||||
|
<li class="list-group-item"><strong>Contenido:</strong> ${searchData.contenido}</li>
|
||||||
|
<li class="list-group-item"><strong>Monto a Pagar:</strong> S/ ${parseFloat(searchData.monto).toFixed(2)} (${searchData.tipo_pago})</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header"><strong>Historial de Estados</strong></div>
|
||||||
|
<div class="card-body" style="font-size: 0.9rem;">
|
||||||
|
`;
|
||||||
|
|
||||||
|
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 += `<p class="mb-1"><strong>${item.name}:</strong> <span class="text-success">${new Date(item.data.fecha).toLocaleString('es-PE', { timeZone: 'America/Lima' })}</span></p>`;
|
||||||
|
} else {
|
||||||
|
html += `<p class="mb-1"><strong>${item.name}:</strong> <span class="text-muted">Pendiente</span></p>`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
html += `
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
modalStatusDiv.innerHTML = html;
|
||||||
} else {
|
} else {
|
||||||
// Assuming the response is a JSON object, pretty-print it
|
modalStatusDiv.innerHTML = `<p class="text-warning text-center">No se pudo encontrar la guía o la respuesta no es válida.</p><pre><code>${JSON.stringify(data, null, 2)}</code></pre>`;
|
||||||
modalStatusDiv.innerHTML = `<pre><code>${JSON.stringify(data, null, 2)}</code></pre>`;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user