Hot fix para nuevos clientes potenciales, se evitara hacer un Stripe customer ID
This commit is contained in:
parent
3b3cd70ece
commit
ef7156fad2
Binary file not shown.
|
Before Width: | Height: | Size: 427 KiB After Width: | Height: | Size: 432 KiB |
1067
data/plugin.log
1067
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, Sincronizador de CallBell y Envío de Notificaciones y comprobantes vía WhatsApp",
|
"displayName": "SIIP - Procesador de Pagos en línea con Stripe, Sincronizador de CallBell y Envío de Notificaciones y comprobantes vía WhatsApp",
|
||||||
"description": "Este plugin sincroniza los clientes del sitema 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 vía Whatsapp a los clientes",
|
"description": "Este plugin sincroniza los clientes del sitema 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 vía Whatsapp a los clientes",
|
||||||
"url": "https://siip.mx/",
|
"url": "https://siip.mx/",
|
||||||
"version": "2.5.1",
|
"version": "2.5.3",
|
||||||
"unmsVersionCompliancy": {
|
"unmsVersionCompliancy": {
|
||||||
"min": "2.1.0",
|
"min": "2.1.0",
|
||||||
"max": null
|
"max": null
|
||||||
|
|||||||
@ -55,7 +55,7 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
* Creates a PaymentIntent for OXXO in Stripe for a Customer
|
* Creates a PaymentIntent for OXXO in Stripe for a Customer
|
||||||
*/
|
*/
|
||||||
public function createOxxoPaymentIntent($event_json, $amount = null): string
|
public function createOxxoPaymentIntent($event_json, $amount = null): string
|
||||||
{
|
{
|
||||||
$this->logger->info("Creando referencia del cliente para OXXO: " . PHP_EOL);
|
$this->logger->info("Creando referencia del cliente para OXXO: " . PHP_EOL);
|
||||||
$configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create();
|
$configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create();
|
||||||
$config = $configManager->loadConfig();
|
$config = $configManager->loadConfig();
|
||||||
@ -91,49 +91,37 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->logger->info("Se obtuvo el Stripe Customer ID: " . $stripeCustomerId . PHP_EOL);
|
|
||||||
|
|
||||||
// Obtener email del cliente
|
// Obtener email del cliente
|
||||||
foreach ($arrayClientCRM['contacts'] as $contact) {
|
foreach ($arrayClientCRM['contacts'] as $contact) {
|
||||||
if (!empty($contact['email'])) {
|
if (!empty($contact['email'])) {
|
||||||
$clientEmail = $contact['email'];
|
$clientEmail = $contact['email'];
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
$clientEmail = 'siip8873@gmail.com ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar y procesar el monto proporcionado
|
// Verificar si $amount es null para determinar si es necesario consultar la API
|
||||||
if ($amount !== null) {
|
if ($amount === null) {
|
||||||
// Extraer solo dígitos numéricos del monto
|
|
||||||
$numericAmount = preg_replace('/\D/', '', $amount);
|
|
||||||
|
|
||||||
if (empty($numericAmount)) {
|
|
||||||
$this->logger->error("Cantidad no válida proporcionada: " . $amount . PHP_EOL);
|
|
||||||
return 'cantidadnovalida'; // Retornar error si no se obtiene un valor válido
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convertir el valor limpio a entero
|
|
||||||
$amount = (int) $numericAmount;
|
|
||||||
|
|
||||||
$this->logger->info("Monto proporcionado directamente (procesado): $amount " . PHP_EOL);
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
// Obtener el monto pendiente del cliente en centavos
|
|
||||||
$amount = abs($arrayClientCRM['accountOutstanding']);
|
|
||||||
|
|
||||||
$this->logger->info("Monto pendiente del cliente (procesado): $amount " . PHP_EOL);
|
|
||||||
|
// Obtener el monto pendiente del cliente en centavos
|
||||||
|
$amount = abs($arrayClientCRM['accountOutstanding']) * 100;
|
||||||
|
|
||||||
|
$this->logger->info("Se obtuvieron los datos del cliente y Stripe Customer ID: " . $stripeCustomerId . PHP_EOL);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
$this->logger->error('Error al obtener el monto pendiente del cliente: ' . $e->getMessage() . PHP_EOL);
|
$this->logger->error("Error al obtener atributos personalizados del cliente: " . $e->getMessage() . PHP_EOL);
|
||||||
return 'errorobtenermontopendiente'; // Error al obtener el monto pendiente
|
return 'errorGetClientAttributes';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$this->logger->info("Monto proporcionado directamente: $amount " . PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar que el monto sea mayor a 0 antes de proceder
|
// Validar que el monto sea mayor a 0 antes de proceder
|
||||||
if ($amount > 10) {
|
if ($amount > 10) {
|
||||||
$amount = intval($amount * 100);
|
$amount = intval($amount * 100);
|
||||||
try {
|
try {
|
||||||
|
$this->logger->info("Creando referencia en Stripe por: $amount " . PHP_EOL);
|
||||||
$paymentIntent = $stripe->paymentIntents->create([
|
$paymentIntent = $stripe->paymentIntents->create([
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'currency' => 'mxn',
|
'currency' => 'mxn',
|
||||||
@ -152,11 +140,7 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logger->error('Error al crear el payment intent: ' . $e->getMessage() . PHP_EOL);
|
|
||||||
return 'errorCreatePaymentIntent'; // Error al crear el payment intent
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$this->logger->info("Creando payment methods del voucher" . PHP_EOL);
|
$this->logger->info("Creando payment methods del voucher" . PHP_EOL);
|
||||||
$paymentMethod = $stripe->paymentMethods->create([
|
$paymentMethod = $stripe->paymentMethods->create([
|
||||||
'type' => 'oxxo',
|
'type' => 'oxxo',
|
||||||
@ -165,25 +149,13 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
'email' => $clientEmail,
|
'email' => $clientEmail,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logger->error('Error al crear el payment method: ' . $e->getMessage() . PHP_EOL);
|
|
||||||
return 'errorCreatePaymentMethod'; // Error al crear el payment method
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
$this->logger->info("Confirmando el paymentIntent" . PHP_EOL);
|
||||||
$paymentIntent = $stripe->paymentIntents->confirm(
|
$paymentIntent = $stripe->paymentIntents->confirm(
|
||||||
$paymentIntent->id,
|
$paymentIntent->id,
|
||||||
['payment_method' => $paymentMethod->id]
|
['payment_method' => $paymentMethod->id]
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
$this->logger->info("Se terminó de confirmar el paymentIntent" . PHP_EOL);
|
||||||
$this->logger->error('Error al confirmar el payment intent: ' . $e->getMessage() . PHP_EOL);
|
|
||||||
return 'errorConfirmPaymentIntent'; // Error al confirmar el payment intent
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!empty($paymentIntent->next_action) && isset($paymentIntent->next_action->oxxo_display_details)) {
|
if (!empty($paymentIntent->next_action) && isset($paymentIntent->next_action->oxxo_display_details)) {
|
||||||
$oxxoPayment = $paymentIntent->next_action->oxxo_display_details;
|
$oxxoPayment = $paymentIntent->next_action->oxxo_display_details;
|
||||||
$oxxo_reference = $oxxoPayment->number;
|
$oxxo_reference = $oxxoPayment->number;
|
||||||
@ -197,13 +169,17 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
$this->logger->info("Estado actual del PaymentIntent: " . $paymentIntent->status . PHP_EOL);
|
$this->logger->info("Estado actual del PaymentIntent: " . $paymentIntent->status . PHP_EOL);
|
||||||
return 'errorPyamentIntentWithoutOxxoDetails';
|
return 'errorPyamentIntentWithoutOxxoDetails';
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logger->error('Error al crear el payment intent: ' . $e->getMessage() . PHP_EOL);
|
||||||
|
return 'errorCreatePaymentIntent';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->logger->info("Este cliente no tiene adeudos por lo tanto no se puede generar su referencia de OXXO. " . PHP_EOL);
|
$this->logger->info("Este cliente no tiene adeudos por lo tanto no se puede generar su referencia de OXXO. " . PHP_EOL);
|
||||||
return 'errorsinadeudo';
|
return 'errorsinadeudo';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -220,7 +196,7 @@ abstract class AbstractOxxoOperationsFacade
|
|||||||
|
|
||||||
function validarEmail($email)
|
function validarEmail($email)
|
||||||
{
|
{
|
||||||
$this->logger->info('SE VALIDA EL EMAIL!!! ' . PHP_EOL);
|
$this->logger->info('SE VALIDA EL EMAIL!!! '.PHP_EOL);
|
||||||
// Utilizar la función filter_var con el filtro FILTER_VALIDATE_EMAIL para validar el email
|
// Utilizar la función filter_var con el filtro FILTER_VALIDATE_EMAIL para validar el email
|
||||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
// Si el email es válido, devolver el email
|
// Si el email es válido, devolver el email
|
||||||
|
|||||||
@ -155,9 +155,27 @@ abstract class AbstractStripeOperationsFacade
|
|||||||
|
|
||||||
$notification_client_data = $notificationData->clientData; //array con los datos del cliente
|
$notification_client_data = $notificationData->clientData; //array con los datos del cliente
|
||||||
|
|
||||||
$notification_client_data_export = json_encode($notification_client_data);
|
// Asegúrate de trabajar con un objeto PHP
|
||||||
$this->logger->info("Valor de notification client data export: " . $notification_client_data_export . PHP_EOL);
|
$dataObject = json_decode(json_encode($notification_client_data)); // Convertir a JSON y luego decodificar como objeto
|
||||||
|
|
||||||
|
if (!is_object($dataObject)) {
|
||||||
|
$this->logger->info("Error: Los datos del cliente no pudieron ser procesados." . PHP_EOL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -136,7 +136,7 @@ class Plugin
|
|||||||
// Construir la URL basada en el "client_id"
|
// Construir la URL basada en el "client_id"
|
||||||
// $url = "https://siip.mx/wp/wp-content/uploads/img/voucher.png";
|
// $url = "https://siip.mx/wp/wp-content/uploads/img/voucher.png";
|
||||||
if (!empty($event_json->amount )) {
|
if (!empty($event_json->amount )) {
|
||||||
$this->logger->info('Valor del monto: ' . $event_json->amount . PHP_EOL);
|
$this->logger->info('Referencia persnoalizada, Valor del monto: ' . $event_json->amount . PHP_EOL);
|
||||||
$intentos = 0;
|
$intentos = 0;
|
||||||
do {
|
do {
|
||||||
if($intentos>1){
|
if($intentos>1){
|
||||||
@ -167,7 +167,7 @@ class Plugin
|
|||||||
'"url": "' . $url . '"' .
|
'"url": "' . $url . '"' .
|
||||||
'}';
|
'}';
|
||||||
|
|
||||||
$this->logger->debug('Este ese el reponse que se envía a CallBell: ' . $response);
|
$this->logger->debug('Reponse que se envía a CallBell: ' . $response);
|
||||||
// $json_codificado = json_encode($response);
|
// $json_codificado = json_encode($response);
|
||||||
// if (json_last_error() !== JSON_ERROR_NONE) {
|
// if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
// $this->logger->error('Error en la codificación JSON: ' . json_last_error_msg() . PHP_EOL);
|
// $this->logger->error('Error en la codificación JSON: ' . json_last_error_msg() . PHP_EOL);
|
||||||
|
|||||||
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
@ -5,7 +5,7 @@
|
|||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => '9e78efdf2f231a3ca70be5cac52428f77f1700cf',
|
'reference' => '00a68dd8f1020ae4f62d6156ff093247fff6780d',
|
||||||
'name' => 'ucrm-plugins/sms-twilio',
|
'name' => 'ucrm-plugins/sms-twilio',
|
||||||
'dev' => false,
|
'dev' => false,
|
||||||
),
|
),
|
||||||
@ -307,7 +307,7 @@
|
|||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => '9e78efdf2f231a3ca70be5cac52428f77f1700cf',
|
'reference' => '00a68dd8f1020ae4f62d6156ff093247fff6780d',
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user