feat: actualizar servicio de WhatsApp para incluir el nombre de la empresa y eliminar el soporte para XML en el envío de facturas
This commit is contained in:
parent
b253e8a308
commit
232d9ccaa6
@ -60,14 +60,12 @@ public function sendInvoice(Request $request)
|
||||
'phone_number' => ['required', 'string', 'regex:/^[0-9]{10,13}$/'],
|
||||
'invoice_number' => ['required', 'string'],
|
||||
'pdf_url' => ['required', 'url'],
|
||||
'xml_url' => ['nullable', 'url'],
|
||||
'customer_name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$result = $this->whatsAppService->sendInvoice(
|
||||
phoneNumber: $validated['phone_number'],
|
||||
pdfUrl: $validated['pdf_url'],
|
||||
xmlUrl: $validated['xml_url'] ?? null,
|
||||
invoiceNumber: $validated['invoice_number'],
|
||||
customerName: $validated['customer_name']
|
||||
);
|
||||
@ -84,36 +82,4 @@ public function sendInvoice(Request $request)
|
||||
'error' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enviar ticket de venta por WhatsApp
|
||||
*/
|
||||
public function sendSaleTicket(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'phone_number' => ['required', 'string', 'regex:/^[0-9]{10,13}$/'],
|
||||
'sale_number' => ['required', 'string'],
|
||||
'ticket_url' => ['required', 'url'],
|
||||
'customer_name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$result = $this->whatsAppService->sendSaleTicket(
|
||||
phoneNumber: $validated['phone_number'],
|
||||
ticketUrl: $validated['ticket_url'],
|
||||
saleNumber: $validated['sale_number'],
|
||||
customerName: $validated['customer_name']
|
||||
);
|
||||
|
||||
if ($result['success']) {
|
||||
return ApiResponse::OK->response([
|
||||
'message' => 'Ticket enviado correctamente por WhatsApp',
|
||||
'data' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'message' => $result['message'],
|
||||
'error' => $result['error'] ?? null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ class WhatsAppService
|
||||
protected string $apiUrl;
|
||||
protected int $orgId;
|
||||
protected string $token;
|
||||
protected string $companyName;
|
||||
protected string $email = 'juan.zapata@golsystems.com.mx';
|
||||
|
||||
public function __construct()
|
||||
@ -20,6 +21,7 @@ public function __construct()
|
||||
$this->apiUrl = config('services.whatsapp.api_url', 'https://whatsapp.golsystems.mx/api/send-whatsapp');
|
||||
$this->orgId = config('services.whatsapp.org_id', 1);
|
||||
$this->token = config('services.whatsapp.token');
|
||||
$this->companyName = config('services.whatsapp.company_name', 'PDV');
|
||||
|
||||
if (!$this->token) {
|
||||
throw new \Exception('El token de WhatsApp no está configurado. Agrega WHATSAPP_TOKEN en tu archivo .env');
|
||||
@ -66,10 +68,17 @@ public function sendDocument(
|
||||
'parameters' => [
|
||||
[
|
||||
'type' => 'text',
|
||||
'parameter_name' => 'nombre_cliente',
|
||||
'text' => $customerName,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'parameter_name' => 'nombre_empresa',
|
||||
'text' => $this->companyName,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'parameter_name' => 'referencia_factura',
|
||||
'text' => $ticket,
|
||||
],
|
||||
],
|
||||
@ -147,39 +156,17 @@ public function sendDocument(
|
||||
public function sendInvoice(
|
||||
string $phoneNumber,
|
||||
string $pdfUrl,
|
||||
?string $xmlUrl,
|
||||
string $invoiceNumber,
|
||||
string $customerName
|
||||
): array {
|
||||
// Enviar PDF
|
||||
$pdfResult = $this->sendDocument(
|
||||
return $this->sendDocument(
|
||||
phoneNumber: $phoneNumber,
|
||||
documentUrl: $pdfUrl,
|
||||
filename: "Factura_{$invoiceNumber}.pdf",
|
||||
filename: "{$invoiceNumber}.pdf",
|
||||
userEmail: $this->email,
|
||||
ticket: $invoiceNumber,
|
||||
customerName: $customerName
|
||||
);
|
||||
|
||||
// Si hay XML y el PDF se envió correctamente, enviarlo también
|
||||
if ($xmlUrl && $pdfResult['success']) {
|
||||
$xmlResult = $this->sendDocument(
|
||||
phoneNumber: $phoneNumber,
|
||||
documentUrl: $xmlUrl,
|
||||
filename: "Factura_{$invoiceNumber}.xml",
|
||||
userEmail: $this->email,
|
||||
ticket: "{$invoiceNumber}_XML",
|
||||
customerName: $customerName
|
||||
);
|
||||
|
||||
return [
|
||||
'success' => $pdfResult['success'] && $xmlResult['success'],
|
||||
'pdf' => $pdfResult,
|
||||
'xml' => $xmlResult,
|
||||
];
|
||||
}
|
||||
|
||||
return $pdfResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
'api_url' => env('WHATSAPP_API_URL', 'https://whatsapp.golsystems.mx/api/send-whatsapp'),
|
||||
'org_id' => env('WHATSAPP_ORG_ID', 1),
|
||||
'token' => env('WHATSAPP_TOKEN'),
|
||||
'company_name' => env('APP_NAME', 'PDV'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user