Version 2.7.1 con la opción de generar clabes interbancarias por medio de una etiqueta con nombre 'CREARCLABESTRIPE' y además permite crear las clabes de manera automática cuando el cliente pasa de potencial a cliente regular, se corrige un error que permitía generar de manera indefinida clabes para un cliente, además también se agregó la eliminación de la etiqueta 'CREARCLABESTRIPE' de manera automática cuando termina de generar una clabe interbancaria y cliente de Sripe y también valida si ya tiene uno creado con anterioridad para descartar solicitudes hechas a clientes que ya posean dichos datos
This commit is contained in:
parent
96d7fe6b27
commit
9a3af1f3d4
1645
data/plugin.log
1645
data/plugin.log
File diff suppressed because it is too large
Load Diff
@ -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.7.0",
|
||||
"version": "2.7.1",
|
||||
"unmsVersionCompliancy": {
|
||||
"min": "2.1.0",
|
||||
"max": null
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SmsNotifier\Facade;
|
||||
|
||||
use Attribute;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use SmsNotifier\Data\NotificationData;
|
||||
@ -136,19 +137,30 @@ abstract class AbstractStripeOperationsFacade
|
||||
$UCRMAPIToken = $config['apitoken'];
|
||||
$StripeToken = $config['tokenstripe'];
|
||||
$baseUri = 'https://' . $IPServer . '/crm/api/v1.0/'; //endpoint de la API REST del CRM
|
||||
$this->ucrmApi = UcrmApi::create();
|
||||
|
||||
$stripe = new \Stripe\StripeClient($StripeToken); //Token de clave privada en modo prueba para la API de Stripe
|
||||
//$stripe = new \Stripe\StripeClient('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'); //Token de clave privada en modo prodcucción para la API de Stripe
|
||||
|
||||
//valor de $notificationData en json
|
||||
$this->logger->info("Valor de notificationData: " . json_encode($notificationData) . PHP_EOL);
|
||||
|
||||
//$this->logger->info("Ya dentro del metodo Create Stripe Client " . PHP_EOL);
|
||||
//$this->sendWhatsApp('Hola Dany');
|
||||
//ejemplo de notificationData: {"uuid":"0be6fee6-db1d-4ab5-a52c-2ee87b04315e","changeType":"edit","entity":"client","entityId":170,"message":null,"clientId":170,"eventName":"client.edit","clientData":{"id":170,"userIdent":null,"previousIsp":null,"isLead":false,"clientType":1,"companyName":null,"companyRegistrationNumber":null,"companyTaxId":null,"companyWebsite":null,"street1":"San Luis 34","street2":null,"city":"Dolores Hidalgo","countryId":173,"stateId":null,"zipCode":"37800","fullAddress":"San Luis 34, Dolores Hidalgo, 37800","invoiceStreet1":null,"invoiceStreet2":null,"invoiceCity":null,"invoiceStateId":null,"invoiceCountryId":null,"invoiceZipCode":null,"invoiceAddressSameAsContact":true,"note":null,"sendInvoiceByPost":null,"invoiceMaturityDays":null,"stopServiceDue":null,"stopServiceDueDays":null,"organizationId":1,"tax1Id":null,"tax2Id":null,"tax3Id":null,"registrationDate":"2025-03-24T00:00:00-0600","leadConvertedAt":"2025-03-24T15:01:22-0600","companyContactFirstName":null,"companyContactLastName":null,"isActive":false,"firstName":"Charicuas","lastName":"Quinero","username":null,"contacts":[{"id":176,"clientId":170,"email":null,"phone":null,"name":null,"isBilling":true,"isContact":true,"types":[{"id":1,"name":"Billing"},{"id":2,"name":"General"}]}],"attributes":[{"id":192,"clientId":170,"customAttributeId":10,"name":"Stripe Customer ID","key":"stripeCustomerId","value":"cus_S0T9BJ4dO0p0A3","clientZoneVisible":true},{"id":193,"clientId":170,"customAttributeId":11,"name":"Clabe Interbancaria","key":"clabeInterbancaria","value":"124180302040274015","clientZoneVisible":true}],"accountBalance":0,"accountCredit":0,"accountOutstanding":0,"currencyCode":"MXN","organizationName":"SIIP Pruebas","bankAccounts":[],"tags":[{"id":5,"name":"CREARCLABESTRIPE","colorBackground":"#e30000","colorText":"#fff"}],"invitationEmailSentDate":null,"avatarColor":"#ef5350","addressGpsLat":22.00854045,"addressGpsLon":-99.0272544,"isArchived":false,"generateProformaInvoices":null,"usesProforma":false,"hasOverdueInvoice":false,"hasOutage":false,"hasSuspendedService":false,"hasServiceWithoutDevices":true,"referral":null,"hasPaymentSubscription":false,"hasAutopayCreditCard":false},"serviceData":null,"invoiceData":null,"paymentData":null}
|
||||
|
||||
$this->ucrmApi = UcrmApi::create();
|
||||
if ($tagStripe) {
|
||||
$tagsIds = $this->ucrmApi->get('client-tags', ['name' => 'STRIPE']);
|
||||
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||
//obtener el id del cliente
|
||||
$clientId = $notificationData->clientData['id'];
|
||||
|
||||
//si en attributes del cliente encuentra el custom field de Stripe Customer ID entonces no se vuelve a crear el cliente en Stripe
|
||||
$attributes = $notificationData->clientData['attributes'];
|
||||
$this->logger->info("Valor de attributes: " . json_encode($attributes) . PHP_EOL);
|
||||
$stripeCustomerId = null;
|
||||
foreach ($attributes as $attribute) {
|
||||
if ($attribute['key'] === 'stripeCustomerId') {
|
||||
$stripeCustomerId = $attribute['value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$customAttributes = $this->ucrmApi->get('custom-attributes/', ['attributeType' => 'client']);//Obtener los atributos del sistema que estén vinculados a la entidad "cliente"
|
||||
//$this->logger->info("result del custom Attributes: " . json_encode($customAttributes) . PHP_EOL);
|
||||
|
||||
@ -171,6 +183,61 @@ abstract class AbstractStripeOperationsFacade
|
||||
$this->logger->info("Error al obtener los atributos personalizados." . PHP_EOL);
|
||||
}
|
||||
|
||||
if ($stripeCustomerId) {
|
||||
$this->logger->info("El cliente ya tiene un Stripe Customer ID: " . $stripeCustomerId . PHP_EOL);
|
||||
if ($tagStripe) {
|
||||
$tagsIds = $this->ucrmApi->get('client-tags', []);
|
||||
//ejemplo de respuesta $tagsIds: [{"id":4,"name":"EQUIPO A CREDITO","colorBackground":"#fed74a","colorText":"#444"},{"id":5,"name":"CREARCLABESTRIPE","colorBackground":"#e30000","colorText":"#fff"}]
|
||||
|
||||
//obtener el ID de la etiqueta o tag llamada "CREARCLABESTRIPE" y asiganarla a una variable $tagCrearClabeStripe basandose en el ejemplo de respuesta anterior
|
||||
$tagCrearClabeStripe = null;
|
||||
foreach ($tagsIds as $tag) {
|
||||
if ($tag['name'] === 'CREARCLABESTRIPE') {
|
||||
$tagCrearClabeStripe = $tag['id'];
|
||||
$this->logger->info("ID de la etiqueta 'CREARCLABESTRIPE': " . $tagCrearClabeStripe . PHP_EOL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$tagCrearClabeStripe) {
|
||||
$this->logger->info("No se encontró la etiqueta 'CREARCLABESTRIPE'." . PHP_EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ucrmApi->patch("clients/$clientId/remove-tag/" . $tagCrearClabeStripe);
|
||||
$this->logger->info("Se eliminó la etiqueta 'CREARCLABESTRIPE' del cliente." . PHP_EOL);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//$this->logger->info("Ya dentro del metodo Create Stripe Client " . PHP_EOL);
|
||||
//$this->sendWhatsApp('Hola Dany');
|
||||
|
||||
|
||||
if ($tagStripe) {
|
||||
$tagsIds = $this->ucrmApi->get('client-tags', []);
|
||||
//ejemplo de respuesta $tagsIds: [{"id":4,"name":"EQUIPO A CREDITO","colorBackground":"#fed74a","colorText":"#444"},{"id":5,"name":"CREARCLABESTRIPE","colorBackground":"#e30000","colorText":"#fff"}]
|
||||
|
||||
//obtener el ID de la etiqueta o tag llamada "CREARCLABESTRIPE" y asiganarla a una variable $tagCrearClabeStripe basandose en el ejemplo de respuesta anterior
|
||||
$tagCrearClabeStripe = null;
|
||||
foreach ($tagsIds as $tag) { //revisamos los tags del cliente y si encuentra el tag de "CREARCLABESTRIPE" entonces lo asigna a la variable $tagCrearClabeStripe el valor de id
|
||||
if ($tag['name'] === 'CREARCLABESTRIPE') {
|
||||
$tagCrearClabeStripe = $tag['id'];
|
||||
$this->logger->info("ID de la etiqueta 'CREARCLABESTRIPE': " . $tagCrearClabeStripe . PHP_EOL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$tagCrearClabeStripe) {
|
||||
$this->logger->info("No se encontró la etiqueta 'CREARCLABESTRIPE'." . PHP_EOL);
|
||||
return;
|
||||
}
|
||||
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||
$this->ucrmApi->patch("clients/$clientId/remove-tag/" . $tagCrearClabeStripe);
|
||||
$this->logger->info("Se eliminó la etiqueta 'CREARCLABESTRIPE' del cliente." . PHP_EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -189,20 +256,6 @@ abstract class AbstractStripeOperationsFacade
|
||||
}
|
||||
|
||||
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||
// Acceder a "isLead" de forma segura
|
||||
// $isLead = $dataObject->isLead ?? null;
|
||||
|
||||
// $this->logger->info("El valor de 'isLead' es: " . ($isLead ? "true" : "false") . PHP_EOL);
|
||||
|
||||
// if ($isLead === true) {
|
||||
// $this->logger->info("El cliente es un lead, no se procesará" . PHP_EOL);
|
||||
// return;
|
||||
// } else {
|
||||
// $this->logger->info("El cliente NO es un lead, se procesará" . PHP_EOL);
|
||||
// $this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -220,6 +273,7 @@ abstract class AbstractStripeOperationsFacade
|
||||
|
||||
function createCustomerStripe($notificationData, $stripe, $baseUri, $token): bool
|
||||
{
|
||||
$this->ucrmApi = UcrmApi::create();
|
||||
$this->logger->info("Creando el Customer Stripe" . PHP_EOL);
|
||||
|
||||
|
||||
@ -288,7 +342,7 @@ abstract class AbstractStripeOperationsFacade
|
||||
//validar si se creo el cliente con la API de Stripe $stripe->customers->create
|
||||
if (!isset($result['id'])) { //si no existe el ID del cliente en la respuesta de Stripe entonces se manda un mensaje de error
|
||||
$this->logger->info('Error al crear el cliente en Stripe: ' . json_encode($result) . PHP_EOL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -343,22 +397,33 @@ abstract class AbstractStripeOperationsFacade
|
||||
]
|
||||
|
||||
}'; //JSON para hacer patch de los custom fields del cliente en el UISCP CRM, Campo para el Stripe Customer ID y la Clabe interbancaria
|
||||
// $json_data_patch = '{
|
||||
// "attributes": [
|
||||
// {
|
||||
// "value": "' . $stripe_customer_id . '",
|
||||
// "customAttributeId": 29
|
||||
// },
|
||||
// {
|
||||
// "value": "' . $clabe . '",
|
||||
// "customAttributeId": 30
|
||||
// }
|
||||
// ]
|
||||
|
||||
// }'; //JSON para hacer patch de los custom fields del cliente en el UISCP CRM, Campo para el Stripe Customer ID y la Clabe interbancaria
|
||||
//valor de $json_data_patch en json
|
||||
//$this->logger->info("Valor de json_data_patch: " . $json_data_patch . PHP_EOL);
|
||||
// try{
|
||||
// $responsepatchCRM= $this->ucrmApi->patch("clients/$ucrm_client_id", [
|
||||
// "attributes" => [
|
||||
// [
|
||||
// "value" => $stripe_customer_id,
|
||||
// "customAttributeId" => $stripeID
|
||||
// ],
|
||||
// [
|
||||
// "value" => $clabeInterbancaria,
|
||||
// "customAttributeId" => $clabeInterbancariaID
|
||||
// ]
|
||||
// ]
|
||||
// ]); //aquí se contruye la petición para hacer patch hacia el cliente en sus custom fields con la API del UISP UCRM
|
||||
// $this->logger->info("Se actualizó el cliente en UCRM con el Stripe Customer ID y la Clabe Interbancaria." . PHP_EOL);
|
||||
// $this->logger->info(json_encode($responsepatchCRM) . PHP_EOL); //imprimir respuesta del patch de CRM con la clabe y Customer ID Stripe
|
||||
// }catch (GuzzleException $e) {
|
||||
// $this->logger->info("Error al hacer el patch al cliente en UCRM: " . $e->getMessage() . PHP_EOL);
|
||||
// return false; // Return false if patch fails
|
||||
// }
|
||||
|
||||
|
||||
$clientguzz = new Client(); //instancia de cliente GuzzleHttp para consumir API UISP CRM
|
||||
try {
|
||||
//aquí se contruye la petición para hacer patch hacia el cliente en sus custom fields con la API del UISP UCRM
|
||||
$responseCRM = $clientguzz->patch($baseUri . 'clients/' . $ucrm_client_id, [
|
||||
'json' => json_decode($json_data_patch, true),
|
||||
'headers' => [
|
||||
@ -366,7 +431,7 @@ abstract class AbstractStripeOperationsFacade
|
||||
'Accept' => 'application/json', // Indica que esperamos una respuesta en formato JSON
|
||||
],
|
||||
'verify' => false,
|
||||
]); //aquí se contruye la petición para hacer patch hacia el cliente en sus custom fields con la API del UISP UCRM
|
||||
]);
|
||||
|
||||
|
||||
} catch (GuzzleException $error) {
|
||||
|
||||
@ -412,11 +412,9 @@ class Plugin
|
||||
|
||||
// Comprobar si la etiqueta 'STRIPE' existe en 'tags' pero no en 'tagsBefore'
|
||||
if ($stripeTagExists && !$stripeTagExistsBefore) {
|
||||
$this->logger->debug('La etiqueta STRIPE se agregará al cliente');
|
||||
$this->logger->debug('La etiqueta CREARCLABESTRIPE se agregará al cliente');
|
||||
$this->pluginNotifierFacade->createStripeClient($notification, true);
|
||||
} else {
|
||||
$this->logger->debug('La etiqueta STRIPE no se agregó al cliente');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->logger->warning('El campo tags no existe en entity o entityBeforeEdit');
|
||||
}
|
||||
|
||||
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
@ -5,7 +5,7 @@
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '9db9febc39027c302495c041d5a28e198c035b21',
|
||||
'reference' => '96d7fe6b27798f5bb1deaa200ae416315d270a02',
|
||||
'name' => 'ucrm-plugins/sms-twilio',
|
||||
'dev' => false,
|
||||
),
|
||||
@ -307,7 +307,7 @@
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '9db9febc39027c302495c041d5a28e198c035b21',
|
||||
'reference' => '96d7fe6b27798f5bb1deaa200ae416315d270a02',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user