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:
parent
3b3cd70ece
commit
93a0f30eec
Binary file not shown.
|
Before Width: | Height: | Size: 427 KiB After Width: | Height: | Size: 432 KiB |
BIN
comprobantes/Comprobante_Maria_Gricelda_López_Avalos.png
Normal file
BIN
comprobantes/Comprobante_Maria_Gricelda_López_Avalos.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 428 KiB |
1194
data/plugin.log
1194
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",
|
||||
"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/",
|
||||
"version": "2.5.1",
|
||||
"version": "2.5.3",
|
||||
"unmsVersionCompliancy": {
|
||||
"min": "2.1.0",
|
||||
"max": null
|
||||
|
||||
@ -91,7 +91,6 @@ abstract class AbstractOxxoOperationsFacade
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->logger->info("Se obtuvo el Stripe Customer ID: " . $stripeCustomerId . PHP_EOL);
|
||||
|
||||
// Obtener email del cliente
|
||||
foreach ($arrayClientCRM['contacts'] as $contact) {
|
||||
@ -99,41 +98,32 @@ abstract class AbstractOxxoOperationsFacade
|
||||
$clientEmail = $contact['email'];
|
||||
break;
|
||||
} else {
|
||||
$clientEmail = 'siip8873@gmail.com ';
|
||||
$clientEmail = 'siip8873@gmail.com';
|
||||
}
|
||||
}
|
||||
|
||||
// Validar y procesar el monto proporcionado
|
||||
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 {
|
||||
// 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']);
|
||||
|
||||
$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) {
|
||||
$this->logger->error('Error al obtener el monto pendiente del cliente: ' . $e->getMessage() . PHP_EOL);
|
||||
return 'errorobtenermontopendiente'; // Error al obtener el monto pendiente
|
||||
$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);
|
||||
}
|
||||
|
||||
// Validar que el monto sea mayor a 0 antes de proceder
|
||||
if ($amount > 10) {
|
||||
$amount = intval($amount * 100);
|
||||
try {
|
||||
|
||||
$this->logger->info("Creando referencia en Stripe por: $amount " . PHP_EOL);
|
||||
$paymentIntent = $stripe->paymentIntents->create([
|
||||
'amount' => $amount,
|
||||
'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);
|
||||
$paymentMethod = $stripe->paymentMethods->create([
|
||||
'type' => 'oxxo',
|
||||
@ -165,48 +151,40 @@ abstract class AbstractOxxoOperationsFacade
|
||||
'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->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) {
|
||||
$this->logger->error('Error al confirmar el payment intent: ' . $e->getMessage() . PHP_EOL);
|
||||
return 'errorConfirmPaymentIntent'; // Error al confirmar el payment intent
|
||||
$this->logger->error('Error al crear el payment intent: ' . $e->getMessage() . PHP_EOL);
|
||||
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 {
|
||||
$this->logger->info("Este cliente no tiene adeudos por lo tanto no se puede generar su referencia de OXXO. " . PHP_EOL);
|
||||
return 'errorsinadeudo';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * implement in subclass with the specific messaging provider
|
||||
// * @see TwilioNotifierFacade::sendWhatsApp()
|
||||
|
||||
@ -155,9 +155,27 @@ abstract class AbstractStripeOperationsFacade
|
||||
|
||||
$notification_client_data = $notificationData->clientData; //array con los datos del cliente
|
||||
|
||||
$notification_client_data_export = json_encode($notification_client_data);
|
||||
$this->logger->info("Valor de notification client data export: " . $notification_client_data_export . PHP_EOL);
|
||||
$this->createCustomerStripe($notificationData, $stripe, $baseUri, $UCRMAPIToken);
|
||||
// Asegúrate de trabajar con un objeto PHP
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ class Plugin
|
||||
// Construir la URL basada en el "client_id"
|
||||
// $url = "https://siip.mx/wp/wp-content/uploads/img/voucher.png";
|
||||
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;
|
||||
do {
|
||||
if($intentos>1){
|
||||
@ -167,7 +167,7 @@ class Plugin
|
||||
'"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);
|
||||
// if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
// $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',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '9e78efdf2f231a3ca70be5cac52428f77f1700cf',
|
||||
'reference' => '00a68dd8f1020ae4f62d6156ff093247fff6780d',
|
||||
'name' => 'ucrm-plugins/sms-twilio',
|
||||
'dev' => false,
|
||||
),
|
||||
@ -307,7 +307,7 @@
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '9e78efdf2f231a3ca70be5cac52428f77f1700cf',
|
||||
'reference' => '00a68dd8f1020ae4f62d6156ff093247fff6780d',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user