Versión 2.6.9 con modificaciones para devolver mas campos en la respuesta a una creación de referencia de OXXO, como tal son los campos de oxxo_reference, error, failDescription, clientID, clientFullName, amount

This commit is contained in:
server 2025-03-08 00:09:06 +00:00
parent 2819804ad8
commit 59aac17968
8 changed files with 2050 additions and 34 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
"displayName": "SIIP - Procesador de Pagos en línea con Stripe, Oxxo y Transferencia, Sincronizador de CallBell y Envío de Notificaciones y comprobantes vía WhatsApp",
"description": "Este plugin sincroniza los clientes del sistema UISP CRM con los contactos de WhatsApp en CallBell, además procesa pagos de Stripe como las trasferencias bancarias y genera referencias de pago vía OXXO, además envía comprobantes de pago en formato imagen PNG o texto vía Whatsapp a los clientes",
"url": "https://siip.mx/",
"version": "2.6.8",
"version": "2.6.9",
"unmsVersionCompliancy": {
"min": "2.1.0",
"max": null

View File

@ -55,11 +55,17 @@ abstract class AbstractOxxoOperationsFacade
* Creates a PaymentIntent for OXXO in Stripe for a Customer
* @param array $event_json
* @param int|null $amount
* @return string
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Stripe\Exception\ApiErrorException
* @throws Exception
*/
public function createOxxoPaymentIntent($event_json, $amount = null): string
public function createOxxoPaymentIntent($event_json, $amount = null): array
{
//declarar un array asociativo de strings pero no asignarle nada aun
$arrayOxxoPayment = array();
$this->logger->info("Creando referencia del cliente para OXXO: " . PHP_EOL);
$configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create();
$config = $configManager->loadConfig();
@ -88,13 +94,45 @@ abstract class AbstractOxxoOperationsFacade
try {
$response = $clientGuzzleHttp->request('GET', "clients/" . $clientID);
$arrayClientCRM = json_decode($response->getBody()->getContents(), true);
//$this->logger->info("Valor de arrayClientCRM: " . print_r($arrayClientCRM, true) . PHP_EOL);
$clientFullName = $arrayClientCRM['firstName'] . ' ' . $arrayClientCRM['lastName'];
} catch (RequestException $e) {
if ($e->getCode() === 404) {
$this->logger->error("Cliente no encontrado en CRM: " . $clientID . PHP_EOL);
return 'errorGetClientNotFound';
//devolver un array con los campos del codigo error, descripción de la falla, clientID, clientFullName y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorGetClientNotFound';
$arrayOxxoPayment['failDescription'] = 'Cliente no encontrado en CRM: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
//timeout
if ($e->getCode() === 408) {
$this->logger->error("Timeout al obtener el cliente en CRM: " . $clientID . PHP_EOL);
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['error'] = 'errorTimeoutGetClient';
$arrayOxxoPayment['failDescription'] = 'Timeout al obtener el cliente en CRM: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
$this->logger->error("Error al obtener el cliente en CRM (Error {$e->getCode()}): " . $e->getMessage() . PHP_EOL);
return 'errorGetClient';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['error'] = 'errorGetClient';
$arrayOxxoPayment['failDescription'] = 'Error al obtener el cliente en CRM: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
// Obtener email del cliente
@ -119,7 +157,14 @@ abstract class AbstractOxxoOperationsFacade
$this->logger->info("Stripe Customer ID obtenido: " . $stripeCustomerId . PHP_EOL);
} catch (Exception $e) {
$this->logger->error("Error al obtener el Customer ID de Stripe (Error {$e->getCode()}): " . $e->getMessage() . PHP_EOL);
return 'errorGetCustomerStripe';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['error'] = 'errorGetCustomerStripe';
$arrayOxxoPayment['failDescription'] = 'Error al obtener el Customer ID de Stripe: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
if ($amount === null) {
@ -164,13 +209,40 @@ abstract class AbstractOxxoOperationsFacade
} catch (\Stripe\Exception\ApiConnectionException $e) {
$this->logger->error("Error de conexión con Stripe (Error {$e->getCode()}): " . $e->getMessage() . PHP_EOL);
return 'errorTimeoutCreatePaymentIntent';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorConnectionStripe';
$arrayOxxoPayment['failDescription'] = 'Error de conexión con Stripe: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
} catch (\Stripe\Exception\ApiErrorException $e) {
$this->logger->error("Error de la API de Stripe: " . $e->getMessage() . PHP_EOL);
return 'errorCreatePaymentIntent';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorApiStripe';
$arrayOxxoPayment['failDescription'] = 'Error de la API de Stripe: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
} catch (Exception $e) {
$this->logger->error("Error inesperado al crear PaymentIntent (Error {$e->getCode()}): " . $e->getMessage() . PHP_EOL);
return 'errorCreatePaymentIntent';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorCreatePaymentIntent';
$arrayOxxoPayment['failDescription'] = 'Error inesperado al crear PaymentIntent: ' . $clientID;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['amount'] = $amount;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
return $arrayOxxoPayment;
}
try {
@ -178,8 +250,17 @@ abstract class AbstractOxxoOperationsFacade
$lastName = isset($arrayClientCRM['lastName']) ? trim($arrayClientCRM['lastName']) : '';
if (strlen($firstName) < 2 || strlen($lastName) < 2) {
$this->logger->error("Nombre/apellido inválido: $firstName $lastName" . PHP_EOL);
return 'errorNombreApellidoInvalido';
$this->logger->error("Nombre/apellido inválido: ' . $firstName . ' ' . $lastName" . PHP_EOL);
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorNombreApellidoInvalido';
$arrayOxxoPayment['failDescription'] = "Nombre/apellido inválido: ' . $firstName . ' ' . $lastName";
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
$responsePaymentMethod = $guzzleClient->post('https://api.stripe.com/v1/payment_methods', [
@ -206,7 +287,15 @@ abstract class AbstractOxxoOperationsFacade
} catch (Exception $e) {
$this->logger->error("Error al confirmar PaymentIntent: " . $e->getMessage() . PHP_EOL);
return 'errorConfirmPaymentIntent';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorConfirmPaymentIntent';
$arrayOxxoPayment['failDescription'] = 'Error al confirmar PaymentIntent: ' . $e->getMessage();
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
if (!empty($paymentIntentConfirm['next_action']) && isset($paymentIntentConfirm['next_action']['oxxo_display_details'])) {
@ -216,16 +305,41 @@ abstract class AbstractOxxoOperationsFacade
$this->logger->info("Referencia OXXO: " . $oxxo_reference . PHP_EOL);
$this->logger->info("URL del recibo: " . $oxxo_receipt_url . PHP_EOL);
return $oxxo_receipt_url;
//devolver un array con los campos de url de oxxo, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = $oxxo_reference;
$arrayOxxoPayment['url'] = $oxxo_receipt_url;
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
$arrayOxxoPayment['failDescription'] = '';
$arrayOxxoPayment['error'] = '';
$this->logger->info("Referencia OXXO creada correctamente." . PHP_EOL);
return $arrayOxxoPayment;
} else {
$this->logger->info("El PaymentIntent no tiene detalles de OXXO disponibles. Estado: " . $paymentIntentConfirm['status'] . PHP_EOL);
return 'errorPaymentIntentWithoutOxxoDetails';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorPaymentIntentWithoutOxxoDetails';
$arrayOxxoPayment['failDescription'] = 'El PaymentIntent no tiene detalles de OXXO disponibles. Estado: ' . $paymentIntentConfirm['status'];
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
} else {
$this->logger->info("Este cliente no tiene adeudos." . PHP_EOL);
return 'noAdeudo';
//devolver un array con los campos del codigo error, descripción de la falla, clientID y amount
$arrayOxxoPayment['oxxo_reference'] = '';
$arrayOxxoPayment['url'] = '';
$arrayOxxoPayment['error'] = 'errorsinadeudo';
$arrayOxxoPayment['failDescription'] = 'Este cliente no tiene adeudos.';
$arrayOxxoPayment['clientID'] = $clientID;
$arrayOxxoPayment['clientFullName'] = $clientFullName;
$arrayOxxoPayment['amount'] = $amount;
return $arrayOxxoPayment;
}
}

View File

@ -921,8 +921,17 @@ class ClientCallBellAPI
'Authorization: Bearer ' . $this->CallBellAPIToken,
'Content-Type: application/json',
]);
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch2, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->CallBellAPIToken,
'Content-Type: application/json',
]);
$UrlChatCallBell = 'https://api.callbell.eu/v1/contacts/' . $uuid;
curl_setopt($ch, CURLOPT_URL, $UrlChatCallBell);
curl_setopt($ch2, CURLOPT_URL, $UrlChatCallBell);
$nombre_cliente = sprintf("%s %s", $notificationData->clientData['firstName'], $notificationData->clientData['lastName']);
$log->appendLog("Nombre del cliente que se va a actualizar: " . $nombre_cliente . PHP_EOL);
$log->appendLog("UUID: " . $uuid . PHP_EOL);
@ -1010,8 +1019,8 @@ class ClientCallBellAPI
$resumenClienteJSON = '{' .
'"Cliente": "' . $notificationData->clientData['id'] . '",' .
'"Domicilio": "' .
(($notificationData->clientData['fullAddress'] == null) ? 'Sin domicilio' : '' . $notificationData->clientData['fullAddress']) . '",' .
'"Nombre": "' . sprintf("%s %s", $notificationData->clientData['firstName'], $notificationData->clientData['lastName']) . '",' .
//(($notificationData->clientData['fullAddress'] == null) ? 'Sin domicilio' : '' . $notificationData->clientData['fullAddress']) . '",' .
'"Nombre": "' . sprintf("%s %s", $notificationData->clientData['firstName'], $notificationData->clientData['lastName']) . '",' .
'"URL": "https://sistema.siip.mx/crm/client/' . $notificationData->clientId . '",' .
'"Saldo Actual": "' . $saldoTexto . '",' .
'"Monto Ultimo Pago": "$ ' . $payments[0]['amount'] . '",' .
@ -1048,7 +1057,18 @@ class ClientCallBellAPI
"Antena/Sectorial" => $antenaSectorial
)
);
$log->appendLog("JSON con los datos a actualizar: " . json_encode($data_CRM) . PHP_EOL);
$data_CRM2 = array(
"custom_fields" => array(
"Resumen" => $resumenClienteJSON,
)
);
$log->appendLog("JSON con los datos a actualizar del resumen: " . $resumenClienteJSON . PHP_EOL);
if (
$response_getContactCallBell['custom_fields']['Cliente'] != $data_CRM['custom_fields']['Cliente']
|| $response_getContactCallBell['custom_fields']['Domicilio'] != $data_CRM['custom_fields']['Domicilio']
@ -1062,10 +1082,14 @@ class ClientCallBellAPI
) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_CRM));
curl_setopt($ch2, CURLOPT_POSTFIELDS, json_encode($data_CRM2));
$response = curl_exec($ch);
$log->appendLog("Response Patch CallBell: " . $response . PHP_EOL);
$response2 = curl_exec($ch2);
$log->appendLog("Response 2 Patch CallBell: " . $response2 . PHP_EOL);
curl_close($ch);
curl_close($ch2);
// if($fileNameComprobante != null){
// sleep(3);
// $this->deleteFileWordPressAndLocal($fileNameComprobante);

View File

@ -156,8 +156,10 @@ class Plugin
// sleep(2);
// }
$responseOxxo = $this->pluginOxxoNotifierFacade->createOxxoPaymentIntent($jsonData, $jsonData['amount']);
$this->logger->info('Referencia personalizada, Valor de la respuesta: ' . json_encode($responseOxxo) . PHP_EOL);
//El array asociativo $responseOxxo es un array asosiativo con los siguientes campos: oxxo_reference, error, failDescription, clientID, amount
$intentos++;
} while (strpos($responseOxxo, 'https') !== 0 && $intentos < 3); //Mientras la url no contenga https y el número de intentos sea menor a 3
} while (strpos($responseOxxo['url'], 'https') !== 0 && $intentos < 3); //Mientras la url no contenga https y el número de intentos sea menor a 3
} else {
$intentos = 0;
do {
@ -165,28 +167,39 @@ class Plugin
// sleep(2);
// }
$responseOxxo = $this->pluginOxxoNotifierFacade->createOxxoPaymentIntent($jsonData);
//El array asociativo $responseOxxo es un array asosiativo con los siguientes campos: oxxo_reference, error, failDescription, clientID, amount
$intentos++;
} while (strpos($responseOxxo, 'https') !== 0 && $intentos < 3); //Mientras la url no contenga https y el número de intentos sea menor a 3
} while (strpos($responseOxxo['url'], 'https') !== 0 && $intentos < 3); //Mientras la url no contenga https y el número de intentos sea menor a 3
}
//El array asociativo $responseOxxo es un array asosiativo con los siguientes campos: oxxo_reference, error, failDescription, clientID, amount
//Si la respuesta no contiene https, se genera un error
if (strpos($responseOxxo, 'https') !== 0) {
$this->logger->error('Error al crear la referencia de OXXO: ' . $responseOxxo);
//crear una variable $response con un json con el error y otra clave con la url vacia por ejemplo {"error":"Error al crear la referencia de OXXO","url":""}
if (strpos($responseOxxo['url'], 'https') !== 0) {
//this->logger->error('Error al crear la referencia de OXXO: ' . $responseOxxo);
//crear un json con variable $response que contenga las claves y valores del array $responseOxxo los cuales son: oxxo_reference, error, failDescription, clientID, clientFullName amount
$response = '{' .
'"error": "' . $responseOxxo . '",' .
'"url": ""' .
'"url":' . $responseOxxo['url'] . ',' .
'"error": "' . $responseOxxo['error'] . '",' .
'"failDescription": "' . $responseOxxo['failDescription'] . '",' .
'"clientID": "' . $responseOxxo['clientID'] . '",' .
'"clientFullName": "' . $responseOxxo['clientFullName'] . '",' .
'"amount": "' . $responseOxxo['amount'] . '",' .
'}';
header('Content-Type: application/json');
echo $response;
break;
} else {
//crear una variable $response con un json con el error en blanco y otra clave url con el dato {"error":"","url":"https://stripe.voucher.com/voucher/1234567890"}
//crear un json con variable $response que contenga las claves y valores del array $responseOxxo los cuales son: oxxo_reference, error, failDescription, clientID, clientFullName, amount
$response = '{' .
'"error": "",' .
'"url": "' . $responseOxxo . '"' .
'"url": "' . $responseOxxo['url'] . '",' .
'"oxxo_reference": "' . $responseOxxo['oxxo_reference'] . '",' .
'"error": "' . $responseOxxo['error'] . '",' .
'"failDescription": "' . $responseOxxo['failDescription'] . '",' .
'"clientID": "' . $responseOxxo['clientID'] . '",' .
'"clientFullName": "' . $responseOxxo['clientFullName'] . '",' .
'"amount": "' . $responseOxxo['amount'] . '"' .
'}';
$this->logger->debug('Reponse que se envía a CallBell: ' . $response);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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