feat: mejorar el envío de facturas por WhatsApp con autenticación y manejo de errores

This commit is contained in:
Juan Felipe Zapata Moreno 2026-02-11 16:46:50 -06:00
parent d521f0b2c2
commit 898643cdab
2 changed files with 35 additions and 14 deletions

View File

@ -161,7 +161,6 @@ const sendInvoiceByWhatsapp = async () => {
phone_number: request.client.phone,
invoice_number: request.sale?.invoice_number || `SOL-${request.id}`,
pdf_url: request.invoice_pdf_url,
xml_url: request.invoice_xml_url || null,
customer_name: request.client.name
});

View File

@ -1,4 +1,6 @@
import { api, apiURL } from '@Services/Api';
import { apiURL, token } from '@Services/Api';
import { page } from '@Services/Page';
import axios from 'axios';
/**
* Servicio para enviar mensajes por WhatsApp
@ -9,15 +11,25 @@ const whatsappService = {
* @param {Object} data - Datos de la factura
* @returns {Promise}
*/
async sendInvoice({ phone_number, invoice_number, pdf_url, xml_url, customer_name }) {
async sendInvoice({ phone_number, invoice_number, pdf_url, xml_url = null, customer_name }) {
try {
const { data } = await window.axios.post(apiURL('whatsapp/send-invoice'), {
const { data } = await axios.post(
apiURL('whatsapp/send-invoice'),
{
phone_number,
invoice_number,
pdf_url,
xml_url,
customer_name
});
},
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token.value}`
}
}
);
return data;
} catch (error) {
const errorData = error.response?.data?.data || error.response?.data;
@ -33,10 +45,20 @@ const whatsappService = {
*/
async sendMessage({ phone_number, message }) {
try {
const { data } = await window.axios.post(apiURL('whatsapp/send-message'), {
const { data } = await axios.post(
apiURL('whatsapp/send-message'),
{
phone_number,
message
});
},
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token.value}`
}
}
);
return data;
} catch (error) {
const errorData = error.response?.data?.data || error.response?.data;