Hot fix para nuevos clientes potenciales, se evitara hacer un Stripe customer ID, se ajuto el email del cliente por defecto para crear paymenIntent para pagos de Oxxo

This commit is contained in:
server 2025-01-05 20:25:12 +00:00
parent 3b3cd70ece
commit 93a0f30eec
8 changed files with 390 additions and 928 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 427 KiB

After

Width:  |  Height:  |  Size: 432 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -91,7 +91,6 @@ 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) {
@ -99,41 +98,32 @@ abstract class AbstractOxxoOperationsFacade
$clientEmail = $contact['email']; $clientEmail = $contact['email'];
break; break;
} else { } else {
$clientEmail = 'siip8873@gmail.com '; $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 +142,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,48 +151,40 @@ 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]
); );
$this->logger->info("Se terminó de confirmar el paymentIntent" . PHP_EOL);
if (!empty($paymentIntent->next_action) && isset($paymentIntent->next_action->oxxo_display_details)) {
$oxxoPayment = $paymentIntent->next_action->oxxo_display_details;
$oxxo_reference = $oxxoPayment->number;
$oxxo_receipt_url = $oxxoPayment->hosted_voucher_url;
$this->logger->info("Referencia OXXO: " . $oxxo_reference . PHP_EOL);
$this->logger->info("URL del recibo: " . $oxxo_receipt_url . PHP_EOL);
return $oxxo_receipt_url;
} 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';
}
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->error('Error al confirmar el payment intent: ' . $e->getMessage() . PHP_EOL); $this->logger->error('Error al crear el payment intent: ' . $e->getMessage() . PHP_EOL);
return 'errorConfirmPaymentIntent'; // Error al confirmar el payment intent return 'errorCreatePaymentIntent';
} }
if (!empty($paymentIntent->next_action) && isset($paymentIntent->next_action->oxxo_display_details)) {
$oxxoPayment = $paymentIntent->next_action->oxxo_display_details;
$oxxo_reference = $oxxoPayment->number;
$oxxo_receipt_url = $oxxoPayment->hosted_voucher_url;
$this->logger->info("Referencia OXXO: " . $oxxo_reference . PHP_EOL);
$this->logger->info("URL del recibo: " . $oxxo_receipt_url . PHP_EOL);
return $oxxo_receipt_url;
} 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';
}
} 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';
} }
} }
// /** // /**
// * implement in subclass with the specific messaging provider // * implement in subclass with the specific messaging provider
// * @see TwilioNotifierFacade::sendWhatsApp() // * @see TwilioNotifierFacade::sendWhatsApp()

View File

@ -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
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
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);
}
} }
@ -260,7 +278,7 @@ abstract class AbstractStripeOperationsFacade
], ],
] ]
); );
$this->logger->info("CLABE guardada en metadata: " . $customer->metadata->clabe . PHP_EOL); $this->logger->info("CLABE guardada en metadata: " . $customer->metadata->clabe . PHP_EOL);

View File

@ -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);

View File

@ -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,
), ),
), ),