HotFix para manejo de excepciones de timeout para referencias de oxxo y otros errores versión 2 con ajuste de codigos

This commit is contained in:
server 2025-03-04 10:04:00 +00:00
parent cd74cafeda
commit 4276097212
3 changed files with 133 additions and 36 deletions

View File

@ -11095,3 +11095,100 @@ Response Patch CallBell: {"error":{"custom_fields":["Fecha Ulti-mo Pago do not e
[2025-03-04 9:22:57.823735] [debug] Valor de JSON: {"uuid":"52f3cd87-3914-459d-9d0b-05220ec8594d","changeType":"edit","entity":"payment","entityId":"594","eventName":"payment.edit","extraData":{"entity":{"id":594,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:22:52-0600","amount":100,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":100,"userId":null,"attributes":[]},"entityBeforeEdit":{"id":594,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:22:52-0600","amount":100,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":100,"userId":null,"attributes":[]}}}
[2025-03-04 9:52:26.765544] [notice] Logging level set to:debug
[2025-03-04 9:52:26.765964] [info] No UUID found in the webhook data
[2025-03-04 9:52:26.766105] [info] Evento de referencia de oxxo recibido
[2025-03-04 9:52:26.766210] [info] Referencia persnoalizada, Valor del monto: 40
[2025-03-04 9:52:26.766310] [info] Creando referencia del cliente para OXXO:
[2025-03-04 9:52:26.900403] [info] Se obtuvo el Stripe Customer ID del cliente: cus_PetN1dhr4rx0kX
[2025-03-04 9:52:26.900537] [info] Monto proporcionado directamente: 40
[2025-03-04 9:52:26.900580] [info] Creando referencia en Stripe por: 4000 para el cliente cus_PetN1dhr4rx0kX
[2025-03-04 9:52:27.472719] [info] El nombre del cliente es: Daniel Humberto Soto Villegas el boy
[2025-03-04 9:52:27.473026] [info] Creando payment methods del voucher
[2025-03-04 9:52:27.719233] [info] Confirmando el paymentIntent
[2025-03-04 9:52:28.376204] [info] Se terminó de confirmar el paymentIntent
[2025-03-04 9:52:28.376465] [info] Referencia OXXO: 12345678901234657890123456789012
[2025-03-04 9:52:28.376524] [info] URL del recibo: https://payments.stripe.com/oxxo/voucher/test_YWNjdF8xT2tHMFJFRlkxV0VVdGdSLF9Sc2RRcUJJOXVZVDlmUExMT05kZTdtc3h2bEdySjRu0100Cla9wpeO
[2025-03-04 9:52:28.377145] [debug] Reponse que se envía a CallBell: {"url": "https://payments.stripe.com/oxxo/voucher/test_YWNjdF8xT2tHMFJFRlkxV0VVdGdSLF9Sc2RRcUJJOXVZVDlmUExMT05kZTdtc3h2bEdySjRu0100Cla9wpeO"}
[2025-03-04 9:55:31.162261] [notice] Logging level set to:debug
[2025-03-04 9:55:31.276391] [debug] valor el evento recibido por webhook: payment.add
[2025-03-04 9:55:31.276521] [debug] Valor de JSON: {"uuid":"0eaaad7a-2668-4155-af6b-6cfe192ab618","changeType":"insert","entity":"payment","entityId":"595","eventName":"payment.add","extraData":{"entity":{"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]},"entityBeforeEdit":null}}
[2025-03-04 9:55:31.276778] [debug] Notification encodificado en JSON:{"uuid":"0eaaad7a-2668-4155-af6b-6cfe192ab618","changeType":"insert","entity":"payment","entityId":595,"message":null,"clientId":2,"eventName":"payment.add","clientData":{"id":2,"userIdent":null,"previousIsp":null,"isLead":false,"clientType":1,"companyName":null,"companyRegistrationNumber":null,"companyTaxId":null,"companyWebsite":null,"street1":"31 Chiapas","street2":null,"city":"Dolores Hidalgo Cuna de la Independencia Nacional","countryId":173,"stateId":null,"zipCode":"37800","fullAddress":"Chiapas 31, Centro, Dolores Hidalgo Cuna de la Independencia Nacional, Gto., M\u00e9xico","invoiceStreet1":null,"invoiceStreet2":null,"invoiceCity":null,"invoiceStateId":null,"invoiceCountryId":null,"invoiceZipCode":null,"invoiceAddressSameAsContact":true,"note":"Cliente espacial, el m\u00e1s chido","sendInvoiceByPost":null,"invoiceMaturityDays":null,"stopServiceDue":null,"stopServiceDueDays":null,"organizationId":1,"tax1Id":null,"tax2Id":null,"tax3Id":null,"registrationDate":"2024-01-25T00:00:00-0600","leadConvertedAt":null,"companyContactFirstName":null,"companyContactLastName":null,"isActive":true,"firstName":"Daniel Humberto","lastName":"Soto Villegas el boy","username":"danydhsv","contacts":[{"id":2,"clientId":2,"email":"dhsv.141089@gmail.com","phone":"5214181878106","name":"Personal","isBilling":false,"isContact":false,"types":[{"id":1000,"name":"WhatsApp"}]},{"id":170,"clientId":2,"email":null,"phone":"5214181817609","name":"Bussiness","isBilling":false,"isContact":false,"types":[]}],"attributes":[{"id":112,"clientId":2,"customAttributeId":10,"name":"Stripe Customer ID","key":"stripeCustomerId","value":"cus_PetN1dhr4rx0kX","clientZoneVisible":true},{"id":113,"clientId":2,"customAttributeId":11,"name":"Clabe Interbancaria","key":"clabeInterbancaria","value":"0021804341999569810","clientZoneVisible":true}],"accountBalance":333.33,"accountCredit":333.33,"accountOutstanding":0,"currencyCode":"MXN","organizationName":"SIIP Pruebas","bankAccounts":[],"tags":[{"id":2,"name":"NS EXENTO","colorBackground":"#42a3df","colorText":"#fff"}],"invitationEmailSentDate":null,"avatarColor":"#f1df43","addressGpsLat":21.1564209,"addressGpsLon":-100.9384185,"isArchived":false,"generateProformaInvoices":null,"usesProforma":false,"hasOverdueInvoice":false,"hasOutage":true,"hasSuspendedService":false,"hasServiceWithoutDevices":false,"referral":null,"hasPaymentSubscription":false,"hasAutopayCreditCard":false},"serviceData":null,"invoiceData":null,"paymentData":{"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]}}
[2025-03-04 9:55:31.276845] [debug] valor del payment data: {"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]}
[2025-03-04 9:55:31.276938] [info] {"WhatsApp":["5214181878106"]}
[2025-03-04 9:55:31.276978] [info] Procesando tipo de contacto original: 'WhatsApp'
[2025-03-04 9:55:31.277013] [info] Tipo de contacto normalizado: 'whatsapp'
[2025-03-04 9:55:31.277049] [debug] ***Se notifica y actualiza al cliente sobre su pago***
Eviando comprobante de pago al cliente: 2 con número: 5214181878106
El archivo PDF se ha descargado y guardado correctamente en: /data/ucrm/data/plugins/siip-whatsapp-notifications/src/Facade/../../comprobantes/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.pdf
El archivo PDF es válido y tiene contenido: /data/ucrm/data/plugins/siip-whatsapp-notifications/src/Facade/../../comprobantes/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.pdf
El archivo PNG se ha generado correctamente en: /data/ucrm/data/plugins/siip-whatsapp-notifications/src/Facade/../../comprobantes/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.png
Subiendo comprobante a worpdpress
file_to_upload: /data/ucrm/data/plugins/siip-whatsapp-notifications/src/Facade/../../comprobantes/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.png
Conexión FTP exitosa
El archivo ha sido cargado exitosamente.
La URL es: https://siip.mx/wp/wp-content/uploads/img/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.png
No se pudo obtener la lista de archivos de la carpeta FTP
Se terminó de subir comprobante a wordpress
La cadena CURL que se envia es: {
"to": "5214181878106",
"from": "whatsapp",
"type": "document",
"content": {
"text": "S/M",
"url": "https://siip.mx/wp/wp-content/uploads/img/Comprobante_Daniel_Humberto_Soto_Villegas_el_boy.png"
},
"template_values": ["Daniel Humberto Soto Villegas el boy", "$40", "$333.33 a favor"],
"template_uuid": "57ead79cebd14902921477922403093b",
"optin_contact": true
}
Response del CallBell: {"message":{"uuid":"d513e5ce662a40b8af0a80146b57e931","status":"enqueued"}}
Hay menos de 100 archivos en el directorio. No se eliminarán archivos.
La notificación fue enviada correctamente con estado: enqueued
Dentro del proceso del patch:
Datos traidos con payment api: [{"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]}]
Nombre del cliente que se va a actualizar: Daniel Humberto Soto Villegas el boy
UUID: 74cc2bb45eb8409f92cd5dba99200d26
JSON con los datos a actualizar: {"name":"Daniel Humberto Soto Villegas el boy","custom_fields":{"Cliente":2,"Domicilio":"\ud83d\udccd Chiapas 31, Centro, Dolores Hidalgo Cuna de la Independencia Nacional, Gto., M\u00e9xico","Nombre":"\ud83d\udc64 Daniel Humberto Soto Villegas el boy","URL":"\ud83c\udf10 https:\/\/sistema.siip.mx\/crm\/client\/2","Saldo Actual":"\ud83d\udcb2333.33 a favor","Monto Ultimo Pago":"\ud83d\udcb2 40","Estado":"\ud83d\udfe2 Activo ","Resumen":"{\"Cliente\": \"2\",\"Domicilio\": \"\ud83d\udccd Chiapas 31, Centro, Dolores Hidalgo Cuna de la Independencia Nacional, Gto., M\u00e9xico\",\"Nombre\": \"\ud83d\udc64 Daniel Humberto Soto Villegas el boy\",\"URL\": \"\ud83c\udf10 https:\/\/sistema.siip.mx\/crm\/client\/2\",\"Saldo Actual\": \"\ud83d\udcb2333.33 a favor\",\"Monto Ultimo Pago\": \"\ud83d\udcb2 40\",\"Estado\": \"\ud83d\udfe2 Activo\",\"Fecha Ultimo Pago\": \"\ud83d\udcc6\ud83d\udcb0 04\/03\/2025 03:55 con Tarjeta de cr\u00e9dito Stripe \ud83d\udcb3\",\"Fecha Ultima Actualizacion\": \"\ud83d\udcc6\ud83d\udd04\ufe0f 04\/03\/2025 03:55\",\"Clabe Interbancaria\": \"\"}","Fecha Ulti-mo Pago":"\ud83d\udcc6\ud83d\udcb8 04\/03\/2025 03:55 con Tarjeta de cr\u00e9dito Stripe \ud83d\udcb3","Fecha Ultima Actualizacion":"\ud83d\udcc6\ud83d\udd04\ufe0f 04\/03\/2025 03:55","Clabe Interbancaria":null}}
Response Patch CallBell: {"error":{"custom_fields":["Fecha Ulti-mo Pago do not exist or are misspelled, please check before retrying"]}}
[2025-03-04 9:55:39.636518] [notice] Logging level set to:debug
[2025-03-04 9:55:39.762156] [debug] valor el evento recibido por webhook: payment.edit
[2025-03-04 9:55:39.762307] [debug] Valor de JSON: {"uuid":"49dd7ec2-ae09-44b5-af7a-cdef739c74be","changeType":"edit","entity":"payment","entityId":"595","eventName":"payment.edit","extraData":{"entity":{"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]},"entityBeforeEdit":{"id":595,"clientId":2,"methodId":"1dd098fa-5d63-4c8d-88b7-3c27ffbbb6ae","checkNumber":null,"createdDate":"2025-03-04T03:55:30-0600","amount":40,"currencyCode":"MXN","note":null,"receiptSentDate":null,"providerName":null,"providerPaymentId":null,"providerPaymentTime":null,"paymentCovers":[],"creditAmount":40,"userId":null,"attributes":[]}}}

View File

@ -91,23 +91,7 @@ abstract class AbstractOxxoOperationsFacade
$response = $clientGuzzleHttp->request('GET', "clients/" . $clientID);
$arrayClientCRM = json_decode($response->getBody()->getContents(), true);
// Obtener stripeCustomerId
foreach ($arrayClientCRM['attributes'] as $attribute) {
if ($attribute['key'] === 'stripeCustomerId') {
$stripeCustomerId = $attribute['value'];
break;
}
}
// Obtener email del cliente
foreach ($arrayClientCRM['contacts'] as $contact) {
if (!empty($contact['email'])) {
$clientEmail = $contact['email'];
break;
} else {
$clientEmail = 'siip8873@gmail.com';
}
}
} catch (RequestException $e) {
if ($e->getCode() === 404) {
@ -120,22 +104,38 @@ abstract class AbstractOxxoOperationsFacade
}
// Obtener email del cliente
foreach ($arrayClientCRM['contacts'] as $contact) {
if (!empty($contact['email'])) {
$clientEmail = $contact['email'];
break;
} else {
$clientEmail = 'siip8873@gmail.com';
}
}
try {
// Obtener stripeCustomerId
foreach ($arrayClientCRM['attributes'] as $attribute) {
if ($attribute['key'] === 'stripeCustomerId') {
$stripeCustomerId = $attribute['value'];
break;
}
}
$this->logger->info("Se obtuvo el Stripe Customer ID del cliente: " . $stripeCustomerId . PHP_EOL);
} catch (RequestException $e) {
$this->logger->error("Error al obtener el Customer ID de Stripe" . PHP_EOL);
return 'errorGetCustomerStripe';
}
// Verificar si $amount es null para determinar si es necesario consultar la API
if ($amount === null) {
try {
// Obtener el monto pendiente del cliente en centavos
$amount = abs($arrayClientCRM['accountOutstanding']);
// Obtener el monto pendiente del cliente en centavos
$amount = abs($arrayClientCRM['accountOutstanding']);
$this->logger->info("Se obtuvieron los datos del cliente y Stripe Customer ID: " . $stripeCustomerId . PHP_EOL);
} catch (RequestException $e) {
$this->logger->error("Error al obtener atributos personalizados del cliente: " . $e->getMessage() . PHP_EOL);
return 'errorGetClientAttributes';
}
} else {
$this->logger->info("Monto proporcionado directamente: $amount " . PHP_EOL);
}
@ -166,13 +166,13 @@ abstract class AbstractOxxoOperationsFacade
]);
} catch (Exception $e) {
$this->logger->error('Error al crear el payment intent: ' . $e->getMessage() . PHP_EOL);
return 'errorCreatePaymentIntent';
}
try{
try {
// Obtener los nombres del cliente
$firstName = isset($arrayClientCRM['firstName']) ? trim($arrayClientCRM['firstName']) : '';
$lastName = isset($arrayClientCRM['lastName']) ? trim($arrayClientCRM['lastName']) : '';
@ -201,16 +201,16 @@ abstract class AbstractOxxoOperationsFacade
['payment_method' => $paymentMethod->id]
);
$this->logger->info("Se terminó de confirmar el paymentIntent" . PHP_EOL);
}catch (Exception $e) {
if($e->getCode() === 408){
} catch (Exception $e) {
if ($e->getCode() === 408) {
$this->logger->error('Error de timeout al confirmar el payment intent: ' . $e->getMessage() . PHP_EOL);
return 'errorTimeoutConfirmPaymentIntent';
}else{
} else {
$this->logger->error('Error al confirmar el payment intent: ' . $e->getMessage() . PHP_EOL);
return 'errorConfirmPaymentIntent';
}
}
if (!empty($paymentIntent->next_action) && isset($paymentIntent->next_action->oxxo_display_details)) {
@ -224,7 +224,7 @@ abstract class AbstractOxxoOperationsFacade
} else {
$this->logger->info("El PaymentIntent no tiene detalles de OXXO disponibles aún. " . PHP_EOL);
$this->logger->info("Estado actual del PaymentIntent: " . $paymentIntent->status . PHP_EOL);
return 'errorPyamentIntentWithoutOxxoDetails';
return 'errorPaymentIntentWithoutOxxoDetails';
}
} else {
$this->logger->info("Este cliente no tiene adeudos por lo tanto no se puede generar su referencia de OXXO. " . PHP_EOL);

View File

@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '398dcc462fec4278f6ce4ece52950adf089e35fe',
'reference' => 'cd74cafedaf76be5fca5f3f67b1b6c8306b1eef2',
'name' => 'ucrm-plugins/sms-twilio',
'dev' => false,
),
@ -307,7 +307,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '398dcc462fec4278f6ce4ece52950adf089e35fe',
'reference' => 'cd74cafedaf76be5fca5f3f67b1b6c8306b1eef2',
'dev_requirement' => false,
),
),